Skip to content
Prev 201286 / 398502 Next

dynlm predict with newdata?

The dyn package has a predict method that can typically be used to
predict one step ahead (and you can use a loop to get multiple steps).
 To use just preface lm (or glm or any model fitting function in R
that uses model.frame in the same way as lm).  It works with zoo,
zooreg, ts, its and irts class series.

library(dyn) # this also pulls in zoo

# generate test data
set.seed(123)
x <- zooreg(rep(1, 10))
for(i in 2:10) x[i] <- x[i-1] + rnorm(1)

# fit model
Lag <- function(x, k = 1) lag(x, -k)
mod <- dyn$lm(x ~ Lag(x))

# perform prediction and plot
x. <- predict(mod, list(x = x))
plot(cbind(x, x.), col = 1:2, screen = 1)

# get more info
package?dyn
?dyn
On Sun, Nov 22, 2009 at 9:43 PM, zubin <binabina at bellsouth.net> wrote: