[R] error using predict() / "fRegression"-package
Gero Schwenk
gero.schwenk at web.de
Wed Oct 7 20:20:36 CEST 2009
Hello!
I'm puzzled by the following problem. It occurs while trying to predict
responses in a test-dataset using a linear model fitted with regFit from
the rMetrics "fRegression"-package.
All goes well when I call "predict" using the training dataset. However,
a call using the test-dataset retuns an error message - telling me that
the latter dataset provides variables of different type than the
training set. But inspection of the structure of both dataframes shows,
that the variables are still all of the type "numeric". (See attached
session protocol.)
Does anyone have an idea how to fix this? Any help would greatly be
appreciated!
Kind regards,
Gero
> str(regdata)
'data.frame': 89 obs. of 7 variables:
$ ret1 : num 0.0275 -0.01013 0.00569 -0.01582 0.0226 ...
$ lag(ret1) : num NA 0.0275 -0.01013 0.00569 -0.01582 ...
$ lag(ret2) : num NA 0.04072 -0.00509 0.02055 -0.01548 ...
$ lag(ret3) : num NA 0.05393 0.00299 0.02432 0.02251 ...
$ (lag(ret1)*lag(ret2)): num NA 1.12e-03 5.16e-05 1.17e-04 2.45e-04 ...
$ (lag(ret1)*lag(ret3)): num NA 1.48e-03 -3.03e-05 1.38e-04 -3.56e-04 ...
$ (lag(ret2)*lag(ret3)): num NA 2.20e-03 -1.52e-05 5.00e-04 -3.48e-04 ...
> str(regdata.test)
'data.frame': 23 obs. of 6 variables:
$ lag(ret1) : num NA 0.01554 0.01458 0.00333 0.01674 ...
$ lag(ret2) : num NA 0.01373 0 0.01331 0.00686 ...
$ lag(ret3) : num NA 0.0278 0.0152 0.0211 -0.0104 ...
$ (lag(ret1)*lag(ret2)): num NA 2.13e-04 0.00 4.43e-05 1.15e-04 ...
$ (lag(ret1)*lag(ret3)): num NA 4.32e-04 2.21e-04 7.03e-05 -1.75e-04 ...
$ (lag(ret2)*lag(ret3)): num NA 3.82e-04 0.00 2.81e-04 -7.16e-05 ...
> ar1.xpred.fitted <- regFit(ar1.xpred.model, data = regdata, use = "lm")
> ar1.xpred.train.pred <- predict(ar1.xpred.fitted, regdata, se.fit =
FALSE)
> 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
>
More information about the R-help
mailing list