本文介绍了R的有理误差:不可缺少的观测值太少的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用R的arima()auto.arima()来获得销售预测.该数据是三年的每周水平.

I am using arima() and auto.arima() of R to get the prediction of sales. The data is at week level for three years.

我的代码如下:

x<-c(1571,1501,895,1335,2306,930,2850,1380,975,1080,990,765,615,585,838,555,1449,615,705,465,165,630,330,825,555,720,615,360,765,1080,825,525,885,507,884,1230,342,615,1161,1585,723,390,690,993,1025,1515,903,990,1510,1638,1461.67,1082,1075,2315,1014,2140,1572,794,1363,1184,1248,1344,1056,816,720,896,608,624,560,512,304,640,640,704,1072,768,816,640,272,1168,736,1003,864,658.67,768,841,1727,944,848,432,704,850.67,1205,592,1104,976,629,814,1626,933.33,1100.33,1730,2742,1552,1038,826,1888,1440,1372,824,1824,1392,1424,768,464,960,320,384,512,478,1488,384,338.67,176,624,464,528,592,288,544,418.67,336,752,400,1232,477.67,416,810.67,1256,1040,823,240,1422,704,718,1193,1541,1008,640,752,1008,864,1507,4123,2176,899,1717,935)

x<-c(1571,1501,895,1335,2306,930,2850,1380,975,1080,990,765,615,585,838,555,1449,615,705,465,165,630,330,825,555,720,615,360,765,1080,825,525,885,507,884,1230,342,615,1161,1585,723,390,690,993,1025,1515,903,990,1510,1638,1461.67,1082,1075,2315,1014,2140,1572,794,1363,1184,1248,1344,1056,816,720,896,608,624,560,512,304,640,640,704,1072,768,816,640,272,1168,736,1003,864,658.67,768,841,1727,944,848,432,704,850.67,1205,592,1104,976,629,814,1626,933.33,1100.33,1730,2742,1552,1038,826,1888,1440,1372,824,1824,1392,1424,768,464,960,320,384,512,478,1488,384,338.67,176,624,464,528,592,288,544,418.67,336,752,400,1232,477.67,416,810.67,1256,1040,823,240,1422,704,718,1193,1541,1008,640,752,1008,864,1507,4123,2176,899,1717,935)

length_data<-length(x)

length_train<-round(length_data*0.80)

forecast_period<-length_data-length_train

train_data<-x[1:length_train]

train_data<-ts(train_data,frequency=52,start=c(1,1))

validation_data<-x[(length_train+1):length_data]

validation_data<-ts(validation_data,frequency=52,start=c(ceiling((length_train)/52),((length_train)%%52+1)))

arima_output<-auto.arima(train_data) # fit the ARIMA Model

arima_validate <- Arima(x=validation_data,model=arima_output)

错误:

Error in stats::arima(x = x, order = order, seasonal = seasonal, include.mean = include.mean, :

too few non-missing observations

我做错了什么?缺少的必读内容太少"是什么意思?我现在已经在网上搜索过,但是没有得到更好的解释.

What I am doing wrong?What does it mean by "too few non-missing observations"? I have searched it now net, but did not get any better explanation.

感谢您的任何帮助!

推荐答案

arima_output季节性 ARIMA模型:

arima_output is a seasonal ARIMA model:

> arima_output
Series: train_data 
ARIMA(1,0,1)(0,1,0)[52]

然后

Arima()尝试将该特定模型重新装配为validation_data.但是要使季节模型适合时间序列,您至少需要进行一年的观测,因为季节ARIMA取决于季节差异.

Arima() then attempts to refit this particular model to validation_data. But to fit a seasonal model to a time series, you need at least one full year of observations, since seasonal ARIMA depends on seasonal differencing.

作为说明,请注意,Arima()将很高兴且没有错误地重新设置两倍于validation_data的时间序列:

As an illustration, note that Arima() will happily and without errors refit a time series that is double as long as validation_data:

validation_data <- x[(length_train+1):length_data]
validation_data<-ts(rep(validation_data,2),frequency=52,
  start=c(ceiling((length_train)/52),((length_train)%%52+1)))
arima_validate <- Arima(x=validation_data,model=arima_output)

一种解决方法是通过指定D=0来强制auto.arima()使用非季节性模型:

One way of dealing with this would be to force auto.arima() to use a nonseasonal model, by specifying D=0:

validation_data <- x[(length_train+1):length_data]
validation_data<-ts(validation_data,frequency=52,
  start=c(ceiling((length_train)/52),((length_train)%%52+1)))
arima_output<-auto.arima(train_data, D=0) # fit the ARIMA Model
arima_validate <- Arima(x=validation_data,model=arima_output)

所以这个 did 原来更多是一个CrossValidated问题...

So this did turn out to be more of a CrossValidated question...

这篇关于R的有理误差:不可缺少的观测值太少的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 07:41