Domanda

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?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top