[R] Dyn or Dynlm and out of sample forecasts

Kerpel, John John.Kerpel at infores.com
Thu May 25 19:42:26 CEST 2006


Gabor:

Should lags while using dyn be specified using a negative - (e.g.
lag(y,-1) instead of lag(y,1) to indicate one period earlier ?  Is this
different from the lag function which seems to use lag(y,1) to denote
one period earlier?

Thanks,
John 

-----Original Message-----
From: Gabor Grothendieck [mailto:ggrothendieck at gmail.com] 
Sent: Monday, May 15, 2006 11:09 AM
To: Kerpel, John
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] Dyn or Dynlm and out of sample forecasts

Try this:

# test data
set.seed(1)
y <- ts(1:10 + rnorm(10, 0, 0.1))

# fit model
library(dyn)
y.lm <- dyn$lm(y ~ lag(y,-1))

# use predict
tail(predict(y.lm, list(y = y)), 1)

# or multiply by coefficients giving same result
coef(y.lm) %*% c(1, tail(y,1))

# Now try it using quantile regression
library(quantreg)
y.rq <- dyn$rq(y ~ lag(y,-1))
tail(predict(y.rq, list(y = y)), 1)
coef(y.rq) %*% c(1, tail(y,1))

On 5/15/06, Kerpel, John <John.Kerpel at infores.com> wrote:
> All:
>
>
>
> How do I obtain one step ahead out-of-sample forecasts from a model
> using "dyn" or "dynlm" ?
>
>
>
> Thanks!
>
>
>
> Best,
>
>
>
> John
>
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
>



More information about the R-help mailing list