简体   繁体   中英

ARIMA models in R

I am using the forecast package in R to implement ARIMA models. I'm having problems with fitting the model and the resulting residuals.

This an ARIMA model fitted to the training data:

m1_shattuck_train <- Arima(training_set_shattuck, order = c(0,1,1), seasonal = list(order = c(0,1,1), period = 7))

Then after i test several models on the test set suppose the one above performs the best, so i fit it on the entire data as so: (time_shattuck is the entire data set)

m1_shattuck_full <- Arima(time_shattuck, model = m1_shattuck_train)

When doing that, i get extremely low p-values for the Ljung-Box test indicating serial correlation in the residuals, which isn't at all apparent in the ACF plots.

Yet if i do this:

m1_shattuck_full <- Arima(time_shattuck, order = c(0,1,1), seasonal = list(order = c(0,1,1), period = 7))

i get different figures for the forecasts, and the p-values become high. The same ARIMA model is being applied in both cases. Does anyone know why the results are different? Thanks

You're fitting the same model, but the coefficients for each fitted model will be different because their input data are different. I don't have your data, so I'll be using the AirPassengers dataset.

library(forecast)

data("AirPassengers")

fit_same_model <- function(x) {
  Arima(x, order = c(0, 1, 1), seasonal = list(order = c(0, 1, 1), period = 12))
}

fit_same_model(AirPassengers)
# Series: x 
# ARIMA(0,1,1)(0,1,1)[12] 
# 
# Coefficients:
#           ma1     sma1
#       -0.3087  -0.1074
# s.e.   0.0890   0.0828
# 
# sigma^2 estimated as 137.5:  log likelihood=-507.5
# AIC=1021   AICc=1021.19   BIC=1029.63

training <- window(AirPassengers, end = c(1955, 12))
fit_same_model(training)
# Series: x 
# ARIMA(0,1,1)(0,1,1)[12] 
# 
# Coefficients:
#           ma1     sma1
#       -0.2436  -0.2393
# s.e.   0.1308   0.1161
# 
# sigma^2 estimated as 97.62:  log likelihood=-262.74
# AIC=531.48   AICc=531.84   BIC=538.27

Both models are ARIMA(0, 1, 1)(0, 1, 1)[12], but you can see the difference in how they were fitted.

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