1
$\begingroup$

I am fitting a model using the auto.arima function in package forecast. I get a model that is AR(1), for example. I then extract residuals from this model. How does this generate the same number of residuals as the original vector? If this is an AR(1) model then the number of residuals should be 1 less than the dimensionality of the original time series. What am I missing?

Example:

require(forecast)
arprocess = as.numeric(arima.sim(model = list(ar=.5), n=100))
#auto.arima(arprocess, d=0, D=0, ic="bic", stationary=T)
#  Series: arprocess 
#  ARIMA(1,0,0) with zero mean     

#  Coefficients:
#          ar1
#       0.5198
# s.e.  0.0867

# sigma^2 estimated as 1.403:  log likelihood=-158.99
# AIC=321.97   AICc=322.1   BIC=327.18
r = resid(auto.arima(arprocess, d=0, D=0, ic="bic", stationary=T))
> length(r)
  [1] 100

Update: Digging into the code of auto.arima, I see that it uses Arima which in turn uses stats:::arima. Therefore the question is really how does stats:::arima compute residuals for the very first observation?

$\endgroup$
  • 1
    $\begingroup$ You need to find out how they find the fitted value for the first observation. One way is to remove the first observation. Then reverse the whole time series data that you have and then fit your AR(1) to this new data. Finally, forecast for just one step a head (i.e. h=1) to find the fitted value for the first observation. I am not sure if they implement this, but I have already read this method somewhere! I cannot remember the reference though! $\endgroup$ – Stat Sep 7 '13 at 3:11
3
$\begingroup$

The residuals are the actual values minus the fitted values. For the first observation, the fitted value is the estimated mean of the process. For subsequent observations, the fitted value is $\phi$ times the previous observation, assuming an AR(1) process had been estimated.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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