了解季节性傅里叶 [英] Understanding Fourier for Seasonality

查看:36
本文介绍了了解季节性傅里叶的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 R 中预测包中的 auto.arima 来确定傅立叶级数的最佳 K 项.

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)

seasonality$total 列是否会被季节性变量"考虑用于以后的建模,还是我需要为其添加系数?

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

推荐答案

不,seasonality$total 不是季节性变量.要看到这一点,请注意 fourier(gas, K = optimization_k_value) 的每一列只是一个从 -1 到 1 的季节性分量,因此它们只是 sin(...) 和 cos(...) 没有任何系数.显然,不同的季节性成分必须具有不同的系数,因此您不应该只是将它们相加.

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.

旁注 1:由于 i 始终只是一个数字,因此使用 max(i) 没有任何意义,只需 optimal_k_value <- i 就足够了.

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.

旁注2:我建议检查

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

一方面,可能存在低于年度频率的季节性(似乎 fourier 不允许考虑这一点),尽管您可能会将其单独建模为趋势.此外,将数据拆分为 1970 年之前和之后的数据可能是个好主意.

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.

这篇关于了解季节性傅里叶的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆