[R] predict.lm() out-of-sample predictions - problem with data classes
Gero Schwenk
gero.schwenk at web.de
Thu Oct 8 08:52:17 CEST 2009
Hello!
I'm still working on my problem, which also occurs with the predict.lm()
function. - Providing newdata, which is a data.frame with all variables
being "numeric", as str() shows, R tells me the following:
ar1.xpred.test.pred <- predict(ar1.xpred.fitted, regdata.test, se.fit =
FALSE)
Fehler: variable 'lag(ret1)' was fitted with type "numeric" but type
"nmatrix.1" was supplied
Zusätzlich: Warnmeldung:
'newdata' had 23 rows but variable(s) found have 89 rows
Estimating a model from the test-data and examining, the resulting
lm-object I found out that the "data classes" switched to "nmatrix.1" -
while they were "numeric" for the original model using the traning data.
str(ar1.xpred.test.lm$model)
...
attr(*, "dataClasses")= Named chr [1:4] "nmatrix.1" "nmatrix.1"
"nmatrix.1" "nmatrix.1"
...
str(ar1.xpred.lm$model)
...
attr(*, "dataClasses")= Named chr [1:4] "numeric" "numeric" "nmatrix.1"
"nmatrix.1"
...
I've no clue what the type "nmatrix.1" is and how I could possibly
manipulate the lm()-object to change this into "numeric". What puzzles
me is the fact, that both training- and test-data.frames were created
exactly the same way, even controling the types of their variables.
Can anybody help me out or propose a bypass? I desperately need to make
some out-of-sample predictions!
Many thanks:
Gero
More information about the R-help
mailing list