dataset1 <- data.frame(Var1=rnorm(100), Var2=rnorm(100), Var3=rnorm(100))
## Please use " <- ", with the spaces surrounding the arrow. Please
## do not use "_". The arrow is legible, the underscore is not---and
## worse, confuses people who think the underscore is an alphabetical
## character (as it is in SAS and in R 2.x.x).
Poly1 <- lm(dataset1$Var1 ~ poly(dataset1$Var2, 40) + poly(dataset1$Var3, 40),
singular.ok = T)
formula(Poly1)
## note that you have placed dataset1 in the formula.
## therefore the prediction was based on dataset1.
## > formula(Poly1)
## dataset1$Var1 ~ poly(dataset1$Var2, 40) + poly(dataset1$Var3, 40)
## >
## We recommend that you use meaningful variable names.
names(dataset1) <- c("height","weight","diameter")
## The correct way to do this is to use the data= argument.
Poly1 <- lm(height ~ poly(weight, 40) + poly(diameter, 40),
data=dataset1,
singular.ok = T)
formula(Poly1)
## now predict works as you wish it to work.
dataset2 <- dataset1
dataset2$weight <- dataset2$weight+10
dataset2$diameter <- dataset2$diameter+10
predict(Poly1)
predict(Poly1, newdata=dataset2)
|