How do I fit a linear model with autocorrelated errors in R? In stata I would use the
prais command, but I can't find an R equivalent...
Have a look at
You can set a correlation profile for the errors in the regression, e.g. ARMA, etc:
for ARMA(1,1) errors.
In addition to the
The advantage of the arima() function is that you can fit a much larger variety of ARMA error processes. If you use the auto.arima() function from the forecast package, you can automatically identify the ARMA error:
Use function gls from package nlme. Here is the example.
Since model is fitted using maximum likelihood you need to supply starting values. The default starting value is 0, but as always it is good to try several values to ensure the convergence.
As Dr. G pointed out you can also use other correlation structures, namely ARMA.
Note that in general least squares estimates are consistent if covariance matrix of regression errors is not multiple of identity matrix, so if you fit model with specific covariance structure, first you need to test whether it is appropriate.