简体   繁体   English

如何使用auto.arima函数专门检查ARIMA中AR或MA的顺序值,用于使用R的时间序列数据

[英]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) .我如何检查什么的顺序qMA(q)pAR(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.

相关问题 如何使用 auto.arima 函数专门检查 ARIMA 中 AR 或 MA 的 RMSE 值,用于使用 R 的时间序列数据 - How to specifically check value of RMSE of AR or MA in ARIMA using auto.arima function for time series data using R 使用 auto.arima 在 R 中预测多个时间序列 - forecasting multiple time series in R using auto.arima 如何使用 purrr/tidyverse 将多个时间序列模型(如 ets、auto.arima 等)应用于 R 中的数据分组? - How to apply several time series models like ets, auto.arima etc. to groups in the data in R using purrr/tidyverse? 如何在r中找到时间序列数据的AR,MA,ARIMA.ARMA,SARIMA,SARMA - How to find AR,MA,ARIMA.ARMA,SARIMA,SARMA of a time series data in r 在每日数据的R,auto.arima函数中正确创建时间序列 - Properly Creating a Time Series in R, auto.arima Function on Daily Data 在R中使用auto.arima显示初始数据的预测值 - display predicted values for initial data using auto.arima in R 如何使用 R 中的 auto.arima 生成带有日期的未来预测? - How to generate future forecasts with dates using auto.arima in R? 将数据帧转换为适合auto.arima的时间序列 - Convert data frame to time series suitable for auto.arima R中AR模型选择的auto.arima和ar之间的差异 - difference between auto.arima and ar for AR model selection in R auto.arima()R中的is.constant()函数 - is.constant() function in auto.arima() R
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM