2013-10-28 70 views
0

我正在預測時間序列數據的需求預測。在時間序列中自動尋找季節性

dput輸出保存到Data可變

Data <- structure(list(Yr = c(2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2011L, 2011L, 2011L, 
2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 
2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 
2012L, 2012L, 2012L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
2013L, 2013L, 2013L), Month = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 
12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 
3L, 4L, 5L, 6L, 7L, 8L, 9L), Demand = c(58L, 59L, 108L, 145L, 
109L, 105L, 104L, 175L, 101L, 105L, 254L, 199L, 187L, 201L, 149L, 
93L, 126L, 115L, 136L, 94L, 135L, 116L, 112L, 95L, 122L, 247L, 
188L, 121L, 237L, 190L, 187L, 206L, 206L, 156L, 198L, 154L, 231L, 
190L, 237L, 250L, 182L, 250L, 118L, 123L, 222L)), .Names = c("Yr", 
"Month", "Demand"), class = "data.frame", row.names = c(NA, -45L 
)) 

str(Data) 

我採取的Demand變量和Decompose對數變換,檢查季節性

Data$Log_Demand = log(Data$Demand) 
splot <- ts(Data$Log_Demand, start=c(2010, 1),end=c(2013,9),frequency=12)    
fit <- stl(splot, s.window="period") 
monthplot(splot) 
library(forecast) 
seasonplot(splot) 

我一個月拿劇情和季節性的情節 - 我發現編碼觀察到的季節性模式很難。這裏

Data$Seasonal_Jan = ifelse(Data$time %in% c(1,13,25,37),1,0) 

我的問題是:

從我想自動找出什麼個月的季節性模式,觀察圖表和代碼的虛擬變量(如上)對於那些季節性使用該變量lm模型爲了擬合趨勢分量和來自lm模型殘差,我擬合ARIMA模型來預測預測。

回答

1

這不是你問的問題,但因爲沒有人回答這裏有一些評論可能會幫助你。

首先,我沒有看到在這個系列中需要取對數。這個簡單的情節並不表示該系列的方差隨着平均值的增加而增加。

x <- ts(Data$Demand, start=c(2010, 1), end=c(2013,9), frequency=12) 
lx <- split(x, gl(length(x)/6, 6)) 
m <- unlist(lapply(lx, mean)) 
r <- unlist(lapply(lx, function(x) diff(range(x)))) 
plot(m, r) 
abline(lm(r ~ m)) 

更詳細的方法不建議採取日誌。

library("forecast") 
> BoxCox.lambda(x, lower=0, upper=1) 
[1] 0.9999339 

至於季節性模式,你有興趣,自相關函數不表現出季節性的訂單顯著自相關。

par(mfrow = c(2, 1), mar = c(3,2,3,2)) 
acf(x, lag.max = 60) 
pacf(x, lag.max = 60) 

一階自迴歸模型AR(1)適用於本系列。

函數預測:: seasonaldummy建立可以包括在迴歸季節性假人(所有這些除了一個以避免在迴歸因子多重)

SD <- seasonaldummy(x) 
> summary(lm(x ~ SD[,-1])) 
[...] 
Coefficients: 
      Estimate Std. Error t value Pr(>|t|)  
(Intercept) 149.42857 22.69524 6.584 1.52e-07 *** 
SD[, -1]Feb 24.82143 37.63580 0.660 0.514  
SD[, -1]Mar 21.07143 37.63580 0.560 0.579  
SD[, -1]Apr 2.82143 37.63580 0.075 0.941  
SD[, -1]May 14.07143 37.63580 0.374 0.711  
SD[, -1]Jun 15.57143 37.63580 0.414 0.682  
SD[, -1]Jul -13.17857 37.63580 -0.350 0.728  
SD[, -1]Aug 0.07143 37.63580 0.002 0.998  
SD[, -1]Sep 16.57143 37.63580 0.440 0.662  
SD[, -1]Oct -23.76190 41.43566 -0.573 0.570  
SD[, -1]Nov 38.57143 41.43566 0.931 0.358  
--- 
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
[...] 

季節假人不是在5%顯著水平。用原始系列的對數得到類似的結果。