简体   繁体   中英

Estimating multiple OLS with AR residuals

I am new to modeling in R, so I'm stumbling a bit...

I have a model in Eviews, which I have to translate to R and make further upgrades. The model is multiple OLS with AR(1) of residuals. 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. How to make AR(1) on residuals, and make other variables as they are?

Provided I understood you correctly, you can supply external regressors to your arima model through the xreg argument.

You don't provide sample data so I don't have anything to play with, but your model should translate to something like

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. xreg contains your external regressors as a matrix , with every column containing as many observations for that regressor as you have time points. order = c(1, 0, 0) defines an AR(1) model.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM