Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
分层数据预测的回归ARIMA方法_R_Time Series_Hierarchical Data_Forecasting - Fatal编程技术网

分层数据预测的回归ARIMA方法

分层数据预测的回归ARIMA方法,r,time-series,hierarchical-data,forecasting,R,Time Series,Hierarchical Data,Forecasting,在gts对象上尝试使用ARIMA进行回归时,我遇到此错误: 傅里叶(x,K,长度(x)+(1:h))中的误差: K不得大于周期/2 下面是一段简单的可复制代码。我应该将k设置为什么?我尝试过不同的价值观,但似乎都不管用 library(hts) y3 <- ts(matrix(rnorm(300),ncol=60,nrow=5)) blnames3 <- paste0(rep(c("CA", "NY"), each = 30), # State rep(

在gts对象上尝试使用ARIMA进行回归时,我遇到此错误:

傅里叶(x,K,长度(x)+(1:h))中的误差: K不得大于周期/2

下面是一段简单的可复制代码。我应该将k设置为什么?我尝试过不同的价值观,但似乎都不管用

library(hts)
y3 <- ts(matrix(rnorm(300),ncol=60,nrow=5))
blnames3 <- paste0(rep(c("CA", "NY"), each = 30), # State
               rep(c("AL", "LA", "CL", "ES"), each = 15), # County
               rep(c("O", "O", "O", "C", "C"), 12), # Industry
               rep(c("p", "q", "r", "p", "q"), 12),  # Sub-industry
               rep(504:507, 15)) # Product
colnames(y3) <- blnames3

gy3 <- gts(y3, characters=list(c(2,2),c(1,1,3)))

i=5
fc <- forecast(gy3, fmethod="arima", seasonal=FALSE, h=6, xreg=fourier(gy3, K=i), newxreg=fourierf(gy3, K=i, h=6))
库(hts)

y3这里有几个问题。首先,您的时间序列仅包含5个观测值,每个观测值太少,无法用于预测目的。其次,在
ts()
调用中不指定数据的频率。第三,不能将gts对象作为第一个参数传递给
fourier
()

以下是一些有效的代码:

library(hts)
y3 <- ts(matrix(rnorm(3000),ncol=60), frequency=12)
blnames3 <- paste0(rep(c("CA", "NY"), each = 30), # State
                   rep(c("AL", "LA", "CL", "ES"), each = 15), # County
                   rep(c("O", "O", "O", "C", "C"), 12), # Industry
                   rep(c("p", "q", "r", "p", "q"), 12),  # Sub-industry
                   rep(504:507, 15)) # Product
colnames(y3) <- blnames3

gy3 <- gts(y3, characters=list(c(2,2),c(1,1,3)))

i <- 5
fc <- forecast(gy3, fmethod="arima", seasonal=FALSE, h=6,
        xreg=fourier(y3[,1], K=i), newxreg=fourierf(y3[,1], K=i, h=6))
库(hts)

y3抱歉,已通过包含i更正代码。gts来自hts包-您的时间序列还需要频率属性。