Suen, Michael
2007-Dec-13 13:59 UTC
[R] How to use R to estimate a model which has two sets of lagged time series independent variables
Hi, I would like to use R to estimate the following model: X(t) = a + b1*X(t-1) + b2*X(t-2) + c1*Y(t) + c2*Y(t-1) + c3*Y(t-2) Is there any R function that performs this type of estimation? I know that if I only have one time series (i.e. lagged value of X) on the right hand side then there are R functions to do the estimation. I am thinking a work around by preparing X(t-1), X(t-2),Y(t),Y(t-1) and Y(t-2) as five independent variables and use the lm() function to performance the estimation. Please advise. Thanks. Michael This e-mail message including any attachments may be legally privileged and confidential under applicable law, and is meant only for the intended recipient(s). If you received this message in error, please reply to the sender, adding "SENT IN ERROR" to the subject line, then delete this message. Thank you. [[alternative HTML version deleted]]
Gabor Grothendieck
2007-Dec-13 14:41 UTC
[R] How to use R to estimate a model which has two sets of lagged time series independent variables
If you don't need a complex error structure then the dyn package (and also the dynlm package) can do it. Using R's builtin EuStockMarkets time series: library(dyn) z <- as.zoo(EuStockMarkets) mod1 <- dyn$lm(DAX ~ lag(DAX, -(1:2)) + lag(FTSE, -(0:2)), z) mod1 # compare to model without FTSE mod2 <- dyn$lm(DAX ~ lag(DAX, -(1:2)), z) anova(mod2, mod1) On Dec 13, 2007 8:59 AM, Suen, Michael <Michael.Suen at inginvestment.com> wrote:> Hi, > > I would like to use R to estimate the following model: > > X(t) = a + b1*X(t-1) + b2*X(t-2) + c1*Y(t) + c2*Y(t-1) + c3*Y(t-2) > > Is there any R function that performs this type of estimation? I know > that if I only have one time series (i.e. lagged value of X) on the > right hand side then there are R functions to do the estimation. I am > thinking a work around by preparing X(t-1), X(t-2),Y(t),Y(t-1) and > Y(t-2) as five independent variables and use the lm() function to > performance the estimation. Please advise. Thanks. > > Michael > > This e-mail message including any attachments may be legally privileged and confidential under applicable law, > and is meant only for the intended recipient(s). If you received this message in error, please reply to the sender, > adding "SENT IN ERROR" to the subject line, then delete this message. > Thank you. > > [[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. >
Pfaff, Bernhard Dr.
2007-Dec-13 14:44 UTC
[R] How to use R to estimate a model which has two sets of laggedtime series independent variables
>Hi, > >I would like to use R to estimate the following model: > >X(t) = a + b1*X(t-1) + b2*X(t-2) + c1*Y(t) + c2*Y(t-1) + c3*Y(t-2) > >Is there any R function that performs this type of estimation? I know >that if I only have one time series (i.e. lagged value of X) on the >right hand side then there are R functions to do the estimation. I am >thinking a work around by preparing X(t-1), X(t-2),Y(t),Y(t-1) and >Y(t-2) as five independent variables and use the lm() function to >performance the estimation. Please advise. Thanks. > >Michael >Hello Michael, you can use the function dynlm() contained in the CRAN-package with the same name, or you can use the function VAR() contained in the package vars. Here, you would only need the lm-object belonging to X_T as lhs-variable. Best, Bernhard>This e-mail message including any attachments may be legally >privileged and confidential under applicable law, >and is meant only for the intended recipient(s). If you >received this message in error, please reply to the sender, >adding "SENT IN ERROR" to the subject line, then delete this message. >Thank you. > > [[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. >***************************************************************** Confidentiality Note: The information contained in this ...{{dropped:10}}