[R] dynlm predict with newdata?

Achim Zeileis Achim.Zeileis at wu-wien.ac.at
Mon Nov 23 08:53:02 CET 2009


On Sun, 22 Nov 2009, zubin wrote:

> Hello, can one use predict, as you can with other model objects like lm,
> with dynlm to predict a new data set that is identical in field names,
> just a different time period.
>
> Be nice if you could, I don't really want to create a new data set with
> all the lags, hoping it would generate dynamically.  Does not seem to
> work, get a # of column error.  Any suggestions?

Currently, this is not possible, yet. It would indeed be nice if dynlm() 
could figure out which of the variables are determined by the response and 
predict these recursively, while the remaining variables would need to be 
provided (or even updated by auxiliary AR models). But currently, it's not 
clear to me how all these cases should be resolved exactly and how the 
additional formula parsing should be done, so it's not implemented yet. 
Sorry...
Z


>
> R> str(dfz)
> An 'xts' object from 2009-09-25 09:45:06 to 2009-10-19 15:00:57 containing:
>  Data: num [1:28232, 1:8] 0.54771 -0.00825 1.27406 0.69705 1.08107 ...
> - attr(*, "dimnames")=List of 2
>  ..$ : NULL
>  ..$ : chr [1:8] "PC1" "PC2" "PC3" "PC4" ...
>  Indexed by objects of class: [POSIXt,POSIXct] TZ: GMT
>  xts Attributes:
> NULL
>
> R> str(z)
> An 'xts' object from 2009-10-21 09:45:04 to 2009-10-21 15:00:56 containing:
>  Data: num [1:2304, 1:8] -0.5044 1.237 -0.7764 0.3931 0.0629 ...
> - attr(*, "dimnames")=List of 2
>  ..$ : NULL
>  ..$ : chr [1:8] "PC1" "PC2" "PC3" "PC4" ...
>  Indexed by objects of class: [POSIXt,POSIXct] TZ: GMT
>  xts Attributes:
> NULL
>
>
> dols = dynlm(FAS0 ~ L(FAS0,1:10) + L(PC1,0:10) + L(PC2,0:10) +
> L(PC3,0:10) + L(PC4,0:10) + L(PC5,0:10) + L(PC6,0:10) + L(PC7,0:10),
> data=dfz)
>
> R> predict(dols,newdata=z)
>
> /*Error in fix.by(by.x, x) : 'by' must match numbers of columns*/
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>




More information about the R-help mailing list