gpt4 book ai didi

r - 提取 ARIMA 规范

转载 作者:行者123 更新时间:2023-12-04 09:41:04 24 4
gpt4 key购买 nike

从 auto.arima() 打印拟合模型对象包括一行,例如
“有漂移的 ARIMA(2,1,0),”
这将是一个很好的项目,可以包含在说明拟合模型的 sweave(或其他)输出中。是否可以将该行提取为块?在这一点上,我所做的最好的事情是从 arma 组件中提取适当的顺序(可能与拟合模型系数名称中的措辞相结合,例如“漂移”或“非零均值”。)

# R 3.0.2 x64 on Windows, forecast 5.3 
library(forecast)
y <- ts(data = c(-4.389, -3.891, -4.435, -5.403, -2.501, -1.858, -4.735, -1.085, -2.701, -3.908, -2.520, -2.009, -6.961, -2.891, -0.6791, -1.459, -3.210, -2.178, -1.972, -1.207, -1.376, -1.355, -1.950, -2.862, -3.475, -1.027, -2.673, -3.116, -1.290, -1.510, -1.736, -2.565, -1.932, -0.8247, -2.067, -2.148, -1.236, -2.207, -1.120, -0.6152), start = 1971, end = 2010)
fm <- auto.arima(y)
fm

# what I want is the line: "ARIMA(2,1,0) with drift`"

str(fm)
paste("ARIMA(", fm$arma[1], ",", fm$arma[length(fm$arma)-1], ",", fm$arma[2], ") with ",intersect("drift", names(fm$coef)), sep = "")

最佳答案

检查 auto.arima函数,我注意到它在内部调用了另一个名为 arima.string 的函数.

然后我做了:

getAnywhere(arima.string)

输出是:
A single object matching ‘arima.string’ was found
It was found in the following places
namespace:forecast
with value

function (object)
{
order <- object$arma[c(1, 6, 2, 3, 7, 4, 5)]
result <- paste("ARIMA(", order[1], ",", order[2], ",", order[3],
")", sep = "")
if (order[7] > 1 & sum(order[4:6]) > 0)
result <- paste(result, "(", order[4], ",", order[5],
",", order[6], ")[", order[7], "]", sep = "")
if (is.element("constant", names(object$coef)) | is.element("intercept",
names(object$coef)))
result <- paste(result, "with non-zero mean")
else if (is.element("drift", names(object$coef)))
result <- paste(result, "with drift ")
else if (order[2] == 0 & order[5] == 0)
result <- paste(result, "with zero mean ")
else result <- paste(result, " ")
return(result)

}

然后我复制了函数代码并将其粘贴到一个名为 arima.string1 的新函数中。
arima.string1(fm)

# [1] "ARIMA(2,1,0) with drift "

关于r - 提取 ARIMA 规范,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23617662/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com