3

How can I fit a Polynomial Regression over all the dataframe's variables? It it were a linear regression, I would do:

lm.fit = lm(response~., data=dataset, subset=train)

but if I want a 2-nd (or higher) grade fit, I cannot use poly() as follows:

lm.fit = lm(reads_avg~poly(., i), data=dataset, subset=train)

In particular, poly doesn't seem to accept the point (.) as input.

Zheyuan Li
  • 71,365
  • 17
  • 180
  • 248
Paolo
  • 183
  • 1
  • 6
  • You probably want to use `optim()` to fit an polynomial equation. – Vlo Apr 14 '15 at 18:57
  • 1
    you can try something like this `lm(response~poly(x=as.matrix(dataset[, -1]), degree = 2, raw=TRUE), data=dataset)`. But be careful, `poly` adds the interactions between variables. – Mamoun Benghezal Apr 14 '15 at 19:02
  • I have been trying with your suggestion but, being dataset a data.frame, `lm(response~poly(x=dataset[, -1]), degree = 2, raw=TRUE), data=dataset)` it returns "non-numeric argument to binary operator". It works only if I select a single predictor ( e.g. `lm(response~poly(x=dataset[,2]), degree = 2, raw=TRUE), data=dataset)` – Paolo May 01 '15 at 13:46
  • have you looked at glmulti? (http://www.noamross.net/blog/2013/2/20/model-selection-drug.html) – EngrStudent Oct 15 '15 at 20:39

0 Answers0