简体   繁体   中英

How to specifically check value of RMSE of AR or MA in ARIMA using auto.arima function for time series data using R

How do I check what the RMSE alone is in ARIMA(p,d,q) . If I simulate a time series data with arima.sim like this.

wn <- rnorm(10, mean = 0, sd = 1)
ar <- wn[1:2]
for (i in 3:10){
  ar<-arima.sim(n=10,model=list(ar=-0.7048,order=c(1,1,0)),start.innov=4.1,n.start=1,innov=wn)
}
ar <-ar[-1]

I have tried the r code bellow:

mis <- auto.arima(ar)
summary(auto.arima(ar))
mod1 <- auto.arima(ar)
refit <- Arima(ar, model=mod1)
acu<-accuracy(refit)
acu$

I want a function like rmse<-function(mis,...) that will print out just the value of RMSE

All you need is acu[1, 2] but if you want a function:

library(forecast)
set.seed(100)
wn <- rnorm(10, mean = 0, sd = 1)
ar <- wn[1:2]
for (i in 3:10){
  ar<-arima.sim(n=10,model=list(ar=-0.7048,order=c(1,1,0)),start.innov=4.1,n.start=1,innov=wn)
}
ar <-ar[-1]
ar

mis <- auto.arima(ar)
acu <- accuracy(mis)
acu
#                       ME      RMSE      MAE      MPE  MAPE      MASE      ACF1
# Training set -0.06866332 0.5832581 0.510061 -15.2432 52.34 0.2901498 0.5778458

acu[1, 2]
# [1] 0.5832581

rmse_mis_fun <- function(x) {
  a <- accuracy(x)
  a[1, 2]
}

rmse_mis_fun(mis)
# [1] 0.5832581

being able to pass ar might be a more useful function:

rmse <- function(x) {
  m <- auto.arima(x)
  acu <- accuracy(m)
  acu[1, 2]
}

rmse(ar)
# [1] 0.5832581

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM