Problem: I would like to extract the BIC and AICc from an arima() object in R.
Background: The arima() function produces an output of results, which includes the estimated coefficients, standard errors, AIC, BIC, and AICc. Let's run some sample code to see what this looks like:
# Load the sunspots dataset
data(sunspots)
# Build an ARIMA(2,0,2) model and store as an object
model <- arima(x=sunspots, order=c(2,0,2), method="ML")
# Show a summary of the model
model
The output of results for the model appears like this:
Series: sunspots
ARIMA(2,0,2) with non-zero mean
Coefficients:
ar1 ar2 ma1 ma2 intercept
0.9822 0.0004 -0.3997 -0.1135 51.2652
s.e. 0.1221 0.1196 0.1206 0.0574 8.1441
sigma^2 estimated as 247.9: log likelihood=-11775.69
AIC=23563.39 AICc=23563.42 BIC=23599.05
On the bottom line, we can see values for AIC, BIC, and AICc. (Note: this is the output shown by arima() when the forecast package has been loaded, i.e. library(forecast))
Accessing the AIC value is quite easy. One can simply type:
> model$aic
[1] 23563.39
Access to the AIC value in this manner is made possible due to the fact that it's stored as one of the model's attributes. The following code and output will make this clear:
> attributes(model)
$names
[1] "coef" "sigma2" "var.coef" "mask" "loglik"
[6] "aic" "arma" "residuals" "call" "series"
[11] "code" "n.cond" "model"
$class
[1] "Arima"
Notice, however, that bic and aicc are not model attributes, so the following code is no use to us:
> model$bic
NULL
> model$aicc
NULL
The BIC and AICc values are, indeed, calculated by the arima() function, but the object that it returns does not give us direct access to their values. This is inconvenient and I've come across others who've raised the issue. Unfortunately, I've not found a solution to the problem.
Can anyone out there help? Which method can I use to access the BIC and AICc from the Arima class of object.
Note: I've suggested an answer below, but would like to hear improvements and suggestions.
Edit (Version details as requested):
> R.Version()
$platform
[1] "i686-pc-linux-gnu"
$arch
[1] "i686"
$os
[1] "linux-gnu"
$system
[1] "i686, linux-gnu"
$status
[1] ""
$major
[1] "3"
$minor
[1] "0.2"
$year
[1] "2013"
$month
[1] "09"
$day
[1] "25"
$`svn rev`
[1] "63987"
$language
[1] "R"
$version.string
[1] "R version 3.0.2 (2013-09-25)"
$nickname
[1] "Frisbee Sailing"