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
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.