[英]How to specifically check value of order of AR or MA in ARIMA using auto.arima function for time series data using R
How do I check what the order of q
of MA(q)
or p
of AR(p)
or p
alone in ARIMA(p,d,q)
or q in ARIMA(p,d,q)
.我如何检查什么的顺序
q
的MA(q)
或p
的AR(p)
或p
独自在ARIMA(p,d,q)
或q在ARIMA(p,d,q)
。 If I simulate a time series data with arima.sim
like this.如果我像这样用
arima.sim
模拟时间序列数据。
sim <- arima.sim(n=100, list(order = c(1, 0, 1), ar=0.7, ma=-0.3), sd=sqrt(1))
mis <- auto.arima(sim)
I want a function like p<-function(mis,...)
or q<-function(mis,...)
or d<-function(mis,...)
that will print out 1 for p or 1 for q and 0 for d我想要一个像
p<-function(mis,...)
或q<-function(mis,...)
或d<-function(mis,...)
这样的d<-function(mis,...)
它会为 p 打印 1 或 1 for q 和 0 表示 d
How do I save the values of p,q,d
seperately so I can call each for reuse?如何分别保存
p,q,d
的值,以便我可以调用每个值以供重用?
I'm not sure if it's possible to get back the order=
of the simulation consistently, since the results of auto.arima
may differ.我不确定是否有可能始终恢复模拟的
order=
,因为auto.arima
的结果可能会有所不同。 However the auto.arima
result is stored inside mis$arma
.但是
auto.arima
结果存储在mis$arma
。
set.seed(42)
sim <- arima.sim(list(order=c(1, 0, 1), ar=0.7, ma=-0.3), sd=sqrt(1), n=100)
mis <- auto.arima(sim)
mis
# Series: sim
# ARIMA(1,0,0) with zero mean
#
# Coefficients:
# ar1
# 0.4188
# s.e. 0.0903
#
# sigma^2 estimated as 0.9638: log likelihood=-139.65
# AIC=283.29 AICc=283.41 BIC=288.5
fun <- function(x) setNames(x$arma[c(1, 6, 2)], c("p", "d", "q"))
fun(mis)
# p d q
# 1 0 0
The function can be extended to switch
between the order=
elements:该函数可以扩展为在
order=
元素之间switch
:
fun2 <- function(x, v) {
if (!v %in% c("p", "d", "q"))
stop('v has to be in c("p", "d", "q")')
r <- x$arma
setNames(switch(v, p=r[1], d=r[6], q=r[2]), v)
}
fun2(mis, "p")
# p
# 1
You may also use:您还可以使用:
fun2(mis, "d")
fun2(mis, "q")
You see, the result of the function at least corresponds with the output of auto.arima
.你看,函数的结果至少与
auto.arima
的输出auto.arima
。 You may check this with other set.seed
s to vary the results.您可以使用其他
set.seed
检查以改变结果。
The explanation of the c(1, 6, 2)
order can be derived from the "Value" section of the ?arima
help page, which instructs to decipher mis$arma
as follows: c(1, 6, 2)
顺序的解释可以从?arima
帮助页面的“值”部分导出,该部分指示解密mis$arma
如下:
setNames(mis$arma,
c("AR", "MA", "seas.AR", "seas.MA",
"period", "n.seas.dif", "seas.dif"))
# AR MA seas.AR seas.MA period n.seas.dif seas.dif
# 1 0 0 0 1 0 0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.