R/arima.R

Defines functions my_arima

my_arima <- function(ts, h) {
  cat('--------------------寻找最合适的ARIMA模型参数--------------------\n')
  fit <- forecast::auto.arima(ts, trace = TRUE)
  cat('--------------------对残差进行Ljung-Box检验--------------------\n')
  test <- forecast::checkresiduals(fit)
  cat('p值为', test$p.value, 
      ifelse(test$p.value > 0.05, ',大于', ',小于'),
      '0.05,故残差',
      ifelse(test$p.value > 0.05, '为', '不为'),
      '白噪声\n\n', sep = '')
  cat('--------------------对接下来的', h, '个时间进行预测--------------------\n', sep = '')
  pred <- forecast::forecast(fit, h = h)
  pred
}
fanggong/MyDevTools documentation built on Sept. 28, 2020, 10:30 a.m.