Understanding Fourier for Seasonality

跟風遠走 提交于 2020-01-23 15:28:51

问题


I am using the auto.arima from the forecast package in R to determine the optimal K-terms for fourier series.

After I do that, I want to then calculate the seasonality and plug that one seasonality variable into a multiple regression model.

Using the dataset from the forecast package, I was able to extract the optimal amount of fourier terms:

library(forecast)

##Public dataset from the forecast package
head(gas)

##Choose Optimal Amount of K-Terms
bestfit <- list(aicc=Inf)
for(i in 1:6)
{
  fit <- auto.arima(gas, xreg=fourier(gas, K=i), seasonal=FALSE)
  if(fit$aicc < bestfit$aicc)
    bestfit <- fit
  else break;
  optimal_k_value<-max(i)
  print(i)
}

##Extract Fourier Terms 
seasonality<-data.frame(fourier(gas, K=optimal_k_value))

##Convert Gas TS Data to Dataframe
gas_df <- data.frame(gas, year = trunc(time(gas)), 
                 month = month.abb[cycle(gas)])

##Extract True Seasonality by Taking Sum of Rows
seasonality$total<- rowSums(seasonality)

##Combine Seasonality to Month and Year
final_df<-cbind(gas_df, seasonality$total)

Would the seasonality$total column be considered by "seasonality variable" for later modelling or do I need to add coefficients to it?


回答1:


No, seasonality$total is not the seasonality variable. To see that, note that each column of fourier(gas, K = optimal_k_value) is just a seasonal component going from -1 to 1 so that they are just sin(...) and cos(...) without any coefficients. Clearly, different seasonal components must have different coefficients, so you shouldn't just sum them up.

Side comment 1: since i is always just a single number, there is no point in using max(i), just optimal_k_value <- i is enough.

Side comment 2: I suggest to inspect

plot(resid(auto.arima(gas, xreg = fourier(gas, K = optimal_k_value), seasonal = FALSE)))

For one, there may be seasonality of lower than yearly frequency (it seems like fourier doesn't allow to consider that), although perhaps you are going to model it separately as a trend. Also, it may be a good idea to split the data to something like before and after 1970.



来源:https://stackoverflow.com/questions/53198334/understanding-fourier-for-seasonality

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!