[R] Dyn or Dynlm and out of sample forecasts
Gabor Grothendieck
ggrothendieck at gmail.com
Thu May 25 20:27:05 CEST 2006
This is just the ordinary lag.ts function as described in ?lag.ts .
dyn has no lag function and does not itself understand lags. It
just produces a model frame that has the left and right sides aligned
along time.
One could either regress y ~ lag(y,-1) or regress
lag(y,1) ~ y and get the same coefficients. The fitted
result will be the same except that the second one
will be lagged in comparison to the first one (which is
why the first is likely preferred).
Compare
lm1 <- dyn$lm(y ~ lag(y,-1))
lm1
and
lm2 <- dyn$lm(lag(y,1) ~ y)
lm2
and compare fitted(lm1) and fitted(lm2) .
Try
package?dyn
which will point you to the various help files and demos in the package.
On 5/25/06, Kerpel, John <John.Kerpel at infores.com> wrote:
> 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