Hi all,
I am using "S-PLUS® 6.2 for Windows STUDENT EDITION" to perform
mathematical analysis. I am a little confused with the use of the
predict command.
I have constructed a model using dataset1. Now I want to use the model
to predict a new data set - dataset2. I am not able to use the predict
command properly. Here is what I have done so far...
(1) Created the model using dataset1
Poly1_lm(formula = dataset1$Var1 ~ poly(dataset1$Var2, 40) +
poly(dataset1$Var3, 40), singular.ok = T)
(2) Now tried using Poly1 (the model) to predict values on dataset1.
This should give me the fit on the same data used for modeling
data1_predict.lm(Poly1, dataset1)
(3) Now tried using Poly1 to predict values on dataset2. This should
give me the predicted results on the new set of data.
data2_predict.lm(Poly1, dataset2)
What I find confusing is, data1 and data2 are identical. It is as if the
command did not accept the dataset parameter. I tried predict.lm(object
= Poly1, df = dataset2). Same effect. No errors. It just uses dataset1,
irrespective of whatever I do. If I give an invalid name for the second
parameter "predict.lm(Poly1, dataset3), it gives an error saying it
can't find object dataset3.
Can someone help me out?
Thanks,
SK
|