# Time series with autoregressive error

How can I in R fit a time series, $x_t$, with external regressors, $v_t$, and an autoregressive error? This time series model is given as follows, $x_t = \beta v_t + \epsilon_t$ where $\epsilon_t = w_t + \sum_{i = 1}^p \gamma_i\epsilon_{t - i}$ and $w_t \sim N(0, \sigma^2)$.

Use the arima() function in the stats package:

fit <- arima(x, xreg=v, order=c(p,0,0))


If you want the autoregressive order selected automatically, use auto.arima() from the forecast package:

fit <- auto.arima(x, xreg=v, seasonal=FALSE, max.q=0)


If you are willing to have more general correlated error structures:

fit <- auto.arima(x, xreg=v)

• I used this package but I was under the assumption that arima will fit an autocorrelated time series of the form, $$x_t = \beta v_t + \sum_{i = 1}^p \gamma_i x_{t-i}} + \epsilon_t$$? – Stereo Oct 14 '14 at 12:56
• Read the help file. – Rob Hyndman Oct 15 '14 at 3:09

gls function in nlme package can do it, with gls(y~x, data=Data.Frame, correlation=corARMA(p=1,q=0))