[英]Estimating multiple OLS with AR residuals
I am new to modeling in R, so I'm stumbling a bit...我是 R 建模的新手,所以我有点磕磕绊绊......
I have a model in Eviews, which I have to translate to R and make further upgrades.我在 Eviews 中有一个 model,我必须将其转换为 R 并进行进一步升级。 The model is multiple OLS with AR(1) of residuals.
model 是具有残差 AR(1) 的多个 OLS。 I implemented it like this
我是这样实现的
model1 <- lm(y ~ x1 + x2 + x3, data)
data$e <- dplyr:: lag(residuals(model1), 1)
model2 <- lm(y ~ x1 + x2 + x3 + e, data)
My issue is the same as it is in this thread and I expected it: while parameter estimations are similar, they are different enought that I cannot use it.我的问题与此线程中的问题相同,并且我期望它:虽然参数估计相似,但它们的不同足以让我无法使用它。
I am planing of using ARIMA
from stats
package, but the problem is implementation.我计划使用
stats
package 中的ARIMA
,但问题在于实施。 How to make AR(1) on residuals, and make other variables as they are?如何在残差上制作 AR(1),并按原样制作其他变量?
Provided I understood you correctly, you can supply external regressors to your arima
model through the xreg
argument.如果我理解正确,您可以通过
xreg
参数为您的arima
model 提供外部回归量。
You don't provide sample data so I don't have anything to play with, but your model should translate to something like您不提供示例数据,所以我没有什么可玩的,但是您的 model 应该转换为类似
model <- arima(data$y, xreg = as.matrix(data[, c("x1", "x2", "x3")]), order = c(1, 0, 0))
Explanation: The first argument data$y
contains your time series data.说明:第一个参数
data$y
包含您的时间序列数据。 xreg
contains your external regressors as a matrix
, with every column containing as many observations for that regressor as you have time points. xreg
将您的外部回归量包含为一个matrix
,每一列都包含与您的时间点一样多的该回归量的观察值。 order = c(1, 0, 0)
defines an AR(1) model. order = c(1, 0, 0)
定义了一个 AR(1) model。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.