问题:我想从 R 中的 arima() 对象中提取 BIC 和 AICc。
背景: arima() 函数产生结果输出,其中包括估计系数、标准误差、AIC、BIC 和 AICc。让我们运行一些示例代码来看看它是什么样子的:
# 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
模型的结果输出如下所示:
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
在底线上,我们可以看到 AIC、BIC 和 AICc 的值。(注意:这是 arima() 在加载预测包时显示的输出,即 library(forecast))
访问 AIC 值非常容易。可以简单地键入:
> model$aic
[1] 23563.39
以这种方式访问 AIC 值是可能的,因为它被存储为模型的属性之一。以下代码和输出将清楚地说明这一点:
> attributes(model)
$names
[1] "coef" "sigma2" "var.coef" "mask" "loglik"
[6] "aic" "arma" "residuals" "call" "series"
[11] "code" "n.cond" "model"
$class
[1] "Arima"
但是请注意,bic 和 aicc 不是模型属性,所以下面的代码对我们没有用处:
> model$bic
NULL
> model$aicc
NULL
BIC 和 AICc 值确实是由 arima() 函数计算的,但它返回的对象并没有让我们直接访问它们的值。这很不方便,我遇到过其他人提出这个问题。不幸的是,我还没有找到解决问题的方法。
有人可以帮忙吗?我可以使用哪种方法从 Arima 对象类访问 BIC 和 AICc。
注意:我在下面提出了一个答案,但想听听改进和建议。
编辑(要求的版本详细信息):
> 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"