Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a linear regression model with some correlated errors: $Y_t=\beta_0+\beta_1X_1+\beta_2X_2+\epsilon_t$, where $\epsilon_t$ is a AR(1) i.e. $\epsilon_t=\phi\epsilon_{t-1}+\nu_t$ with $\nu_t$ as white noise terms. I want to obtain the joint maximum likelihood estimates of $\beta_j$'s for $j=0,1,2$ and $\phi$ as well as the residual standard error i.e. $\sigma$ for the white noise term. I guess it can be done with a time series package in R, maybe the forecast package. But I am not sure exactly how to write the code. My first guess is something like this:


Please let me know if there is any package available for this. Thanks.

share|improve this question
up vote 5 down vote accepted

You don't need the forecast package. The arima() command from the stats package will do it:

fit <- arima(dat[,"Y"],order=c(1,0,0),xreg=dat[,c("X1","X2")],method="ML")

But if you also want to do some forecasting, the forecast package makes it easier. In that case, use

fit <- Arima(dat[,"Y"],order=c(1,0,0),xreg=dat[,c("X1","X2")],method="ML")
share|improve this answer
Thank you so much Rob. – Stat Dec 24 '12 at 7:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.