# auto.arima does not see seasonal component (D)

I use R and the auto.arima function for time series analysis. My data is here. Some are nonstationary, and with an apparent seasonal component. Plots of the data show trend and seasonality.

The code snippet:

library(tseries)
library(forecast)

tts<-ts(t$qty,start=1, frequency=52) FR = auto.arima(tts, stepwise=FALSE, seasonal=TRUE,approximation=FALSE,trace=TRUE) fcast_l=forecast(FR,h=90,level = c(0.9,0.8,0.7)) plot(fcast_l,type="l", col="dark red", xlab="Week", main="Value") summary(FR) auto.arima chooses the best model ARIMA(2,1,2)(1,0,0)[52], AIC = 6541.54. The function does not see seasonality. If you set the D = 1 FR = auto.arima(tts, D=1, stepwise=FALSE, seasonal=TRUE,approximation=FALSE,trace=TRUE) then the best model is ARIMA(0,0,2)(1,1,1)[52], AIC = 5128.24. AIC of the second model is less than that of the first. And the forecasts of the second model are essentially correct. Why does auto.arima not see the season? Is this an error of the OCSB test? • If you like my answer.. accept it ... to close the question . – IrishStat Dec 8 '16 at 19:56 • I was going through my old answers and noticed this one was not accepted. Do you perhaps need further clarification? – Richard Hardy Aug 16 '18 at 14:36 ## 3 Answers First, auto.arima does see seasonality as it selects a seasonal model: it has a seasonal AR (SAR) component. Second, auto.arima does not find seasonal integratedness, and this has to do with the OCSB test. But are you entirely sure the test fails? Eyeballing your data does not indicate clear presence of seasonal integratedness to me. Your series does not seem to be a combination of 52 alternating random walks (plus some stationary components). Third, I am not entirely sure the AIC values of the two models are comparable. Some of the observations might be effectively lost when fitting the models due to different autoregressive orders and different orders of integration, and then there is a transformation involved (differencing) -- but you need the depedent variable to be exactly the same to compare AICs of alternative models directly. Your weekly data not only has short term arima structure but 20 significant weekly indicators (rather than seasonal arima) plus one positive time trend . Model structure may include seasonal arima but it premises a consistent/constant behaviour/response from the previous year for all weeks. Model structure could be arima , pulses , level shifts , seasonal pulses , local time trends , changes in error variance over time possibly a symptom of changing parameters . deterministic error variance change at one or more points or the need for a Box-Cox transformation. Simple methods (aic/bic) assuming a list of possible models eccluding time trends premise that all of the possible violations are not present particularly outliers which are very prominent in your data. The possible violations should always be tested for by tests on the error process I took your 230 weekly observations and graphed them and found obvious anomalies/outliers which tend to obfuscate/hide statistical structure reflecting the majority of observations. . The ACF of the original data is here . A model was developed which lead to an ACF of residuals[ with plot here . The model is presented here in two parts and here . The statistics for this model are here . Finally the Actual/Fit and Forecast graph with forecasts here In summary simple solutions require simple data . Complex data requires complex solutions. You data is just too complex for the tools you are attempting to use as they don't automatically evaluate a viable alternative to seasona larima and that is a suffucuent set of seasonal dummies which is why you correctly asked WHY .... . I used AUTOBOX (which I have helped to develop) which adjusts it's solution to the appropriate level of complexity suggested/evidented by the data itself. When a series is non-stationary (a symptom) the cause can be a number of cases. In this case one trend with a positive slope is sufficent. Differencing is often needed BUT not in this case. The seasonality in your data is not pervasive ... some 20 weeks are systematically seasonal while 32 are not . See the forecast graph for this story in a visual manner. It is important to note a a differenced model with a steady state differential (your model) is not a trend model in Time. If you wish to see the shortcomings/deficiencies in your Models simply plot the residuals . Note that the identified anomalies/outliers in the model presented above should/could be investigated to potentially detect/identify possible cause support variables that you might add to the model thus vitiating the pulses which reflect ignorance. auto.arima is designed only to identify stochastic seasonality (either AR or MA )but it does so by ignoring possible deterministic seasonality which is required in this case. Thank you very much for your answers. I realized that I could not compare directly AIC models with different orders of integration. Unfortunately delete EMISSION no Capability to remove outliers. The problem is such that it is necessary to analyze more than 6,000 sales of the series at the beginning of each month. See graphics models is very difficult. Taking into account your advice. I have done so. 1. logarithmic time series. 2. Do auto.arima () with D = 0 and D = 1. I took the best models at D = 0 and D = 1. Then using RMSE metric to choose the best model. If D=0 RMSE=0.50 If D=1 RMSE=0.69 If D=1 it's best model! So do correctly? tts_l<-ts(log(t$qty),start=1, frequency=52)
glimpse(tts_l)
h<-30
train.end <- time(tts_l)[length(tts)-h]
test.start <- time(tts_l)[length(tts)-h+1]

train <- window(tts_l,end=train.end)
test <- window(tts_l,start=test.start)

fit <- Arima(train, order=c(0,0,2),seasonal=c(1,1,1))
fc <- forecast(fit,h=h)
plot(fc,type="l", col="dark red", xlab="номер месяца",
main="Динамика ФОТ")
M<-accuracy(fc,test)[2,"RMSE"]
M

fit2 <- Arima(train, order=c(2,1,2),seasonal=c(1,0,0))
fc2 <- forecast(fit2,h=h)
plot(fc2,type="l", col="dark red", xlab="номер месяца",
main="Динамика ФОТ")
M<-accuracy(fc2,test)[2,"RMSE"]
M
• It seems you are comparing in-sample RMSEs. Out-of-sample comparison would be more relevant, because in sample you may always overfit (that is why you would use information criteria rather than in-sample likelihood or in-sample RMSE). – Richard Hardy Nov 20 '16 at 19:51
• Regarding outlier detection, there are automated procedures for that. There are functions tsoutliers and tsclean for handling outliers in the same package that contains the function auto.arima, namely, "forecast". – Richard Hardy Nov 20 '16 at 20:02
• Thank you. What criteria should I use? RMSE is quite bad metrics? – Евгений Толюпа Nov 20 '16 at 20:08
• Thank you for your function tsoutliers and tsclean. I'll study them! – Евгений Толюпа Nov 20 '16 at 20:10
• Be advised that tsoutliers assumes that one builds/identifies an ARIMA model first and the identifies the outliers. If there are outliers as in tour case the first step is flawed. Identifying an ARIMA model must be done considering the outliers not ignoring them. – IrishStat Nov 20 '16 at 21:11