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?