[R] the arima()-function and AICc
Benedikt Gehr
benedikt.gehr at ieu.uzh.ch
Tue Sep 28 17:06:44 CEST 2010
Hi
I'm trying to fit arima models with the arima() function and I have two
questions.
######
##1. ##
######
I have n observations for my time series. Now, no matter what
arima(p,d,q)- model I fit, I always get n residuals. How is that possible?
For example: If I try this out myself on an AR(1) and calculate the
fitted values from the estimated coefficients I can calculate n-1
residuals. What is the first residual -> residuals[1] in the model?
Does it have something to do with the mean?
Here is what I did: -> X is the time series I'm analysing
X<-c(6.770705, 6.842524, 6.881832, 6.896694, 7.004967, 7.065750,
7.139447, 7.227818, 7.274945, 7.333097, 7.350763, 7.404271, 7.426247,
7.394454, 7.303650, 7.176984, 7.170972, 7.113736, 7.154326, 7.136678,
7.103826, 7.146775, 7.084247, 7.016302, 6.784539, 6.705846, 6.709989,
6.851557, 6.973064, 7.232223)
## The AR(1) Model
model10<-arima(X,order=c(1,0,0),include.mean=T)
mu<-model10[[1]][[2]]
a<-model10[[1]][[1]]
## Get the fitted values and residuals of the arima(1,0,0)-model
fitted<-vector(mode="numeric")
E<-vector(mode="numeric")
for (i in 2:30){
fitted[i]<-a*(X[i-1]-mu)+mu
E[i]<-X[i]-fitted[i]
}
fitted
E # Innovations
residuals(model10) # Compare with the residuals from the arima()
model
######
##2. ##
######
I want to calculate the AICc Value for model selection. Is there a way
to calculate the AICc from the model output without doing it manually. I
guess I could write a function myself somehow but it's always nice to
have an inbuilt function with which to compare what one does. I know
that there has been some discussion on this on the platform but I didn't
find anything that helped me. I tried AICctab from the bbmle package but
I couldn't figure out how to get my output from arima into the function.
I tried with making a list of the logLik(mdoel) output and several other
things but it never worked.
Any help with this is most appreciated
many thanks in advance
cheers
Beni
More information about the R-help
mailing list