[英]Forecasting Weekly Time-Series Data with Multiple Regressors
I'm wondering how I can adapt Rob Hyndman's use of fourier terms like in this blog post to forecast weekly time series data with an additional regressor. 我想知道我如何才能适应罗布·海恩德曼(Rob Hyndman)对傅立叶词的使用,如本博文中那样,通过附加回归变量来预测每周时间序列数据。 Below is my attempt, but I get an error reading that xreg is rank deficient
以下是我的尝试,但读取xreg is rank deficient
出现错误
library(forecast)
gascsv <- read.csv("https://robjhyndman.com/data/gasoline.csv", header=FALSE)[,1]
gas<- ts(gascsv[1:300], freq=365.25/7, start=1991+31/365.25)
#assume that gasreg is an additional regressor used to forecast gas
gasreg <- ts(gascsv[301:600], freq=365.25/7, start=1991+31/365.25)
bestfit <- list(aicc=Inf)
for(i in 1:25){
for(j in 1:25){
fit <- auto.arima(gas, xreg=cbind(fourier(gas, K=i),fourier(gasreg,K=j)), seasonal=FALSE)
if(fit$aicc < bestfit$aicc){
bestfit <- fit
k <-i
l <- j
}
else break;
}
}
Thanks! 谢谢!
Edit: After some additional digging around online, I've found some materials that seem helpful. 编辑:在网上进行了一些其他的挖掘之后,我发现一些有用的材料。 Another of Rob's blog posts uses a set of Fourier terms as well as a dummy variable as regressors. Rob的另一篇博客文章使用一组Fourier术语以及一个虚拟变量作为回归变量。 This post on kaggle (see 3. ARIMA model) uses multiple Fourier terms in a way very similar to what I'm doing, although I still receive the xreg is rank deficient
error. 关于kaggle的这篇文章 (请参阅3. ARIMA模型)以与我正在执行的方式非常相似的方式使用多个傅立叶项,尽管我仍然收到xreg is rank deficient
错误。 Could this be caused by gasreg
being the same data as gas? 这可能是因为gasreg
与gas的数据相同吗?
fourier(gas, K=i)
and fourier(gasreg,K=j)
produce the same fourier set- I believe that the results of fourier()
only depend on the length of the time series, and not the content. fourier(gas, K=i)
和fourier(gasreg,K=j)
产生相同的Fourier集-我相信fourier()
的结果仅取决于时间序列的长度,而不取决于内容。 The rank deficiency error was being caused by using the same regressor twice. 等级不足错误是由两次使用相同的回归变量引起的。 I don't think I need to input the fourier series twice, and the code below seems to suffice. 我认为我不需要两次输入傅立叶级数,下面的代码似乎足够了。
bestfit <- list(aicc=Inf)
for(i in 1:25){
for(j in 1:25){
fit <- auto.arima(gas, xreg=cbind(fourier(gas, K=i),gasreg), seasonal=FALSE)
if(fit$aicc < bestfit$aicc){
bestfit <- fit
k <-i
}
else break;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.