1
$\begingroup$

I am using an automatic model selection procedure, "step". The model of depart (the biggest possible) is a polynom, say of the 4th degree.

Depart<-lm(y~x+I(x^2)+I(x^3)+I(x^4))

Final<-step(Depart)

I need to transform the Final model to a corresponding function. How can i do this?

$\endgroup$

1 Answer 1

8
$\begingroup$

Do you mean something like this:

f<-function(newdata)predict(Final,data.frame(x=newdata))

?

$\endgroup$
4
  • $\begingroup$ No, i wish to construct a function of one variable. Something like "ff<-function(x) 3.23+2.78x-3.45x^4". $\endgroup$
    – Roah
    Commented Nov 18, 2010 at 12:49
  • 2
    $\begingroup$ @Roah Did you try the answer? Because that's exactly what it will give you (you won't see the coefficients, but why do you care about the internals of the function? $\endgroup$
    – Aniko
    Commented Nov 18, 2010 at 13:54
  • $\begingroup$ @Roah - Could you explain in what way the function I suggested does not do what you expect? It certainly accepts scalars so you can call it with a single value. Is the return value not what you are expecting? $\endgroup$
    – NPE
    Commented Nov 18, 2010 at 13:55
  • $\begingroup$ Sorry, aix! I was too bothered by the internal structure of the algorithm... And it is very simple! Thanks a lot, because i was going to parse the output... $\endgroup$
    – Roah
    Commented Nov 18, 2010 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.