【问题标题】:Finding Seasonality automatically in Time Series在时间序列中自动查找季节性
【发布时间】:2013-11-06 20:13:14
【问题描述】:

我正在预测时间序列数据的需求预测。

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)

我对@9​​87654324@ 变量和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 模型来预测预测。

【问题讨论】:

    标签: r time-series


    【解决方案1】:

    这不是你问的,但由于这里没有人回答,所以一些 cmets 可能会对你有所帮助。

    首先,我认为不需要在这个系列上取对数。这个简单的图并不表明该系列的方差随着均值的增加而增加。

    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) 可能适用于该系列。

    函数 forecast: 'seasonaldummy' 为所有季节构建季节性虚拟变量,除了可以包含在回归中的一个(以避免多重共线性)。

    SD <- seasonaldummy(x)
    > summary(lm(x ~ SD))
    [...]
    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% 的水平上不显着。用原始序列的对数得到类似的结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-26
      • 1970-01-01
      • 2018-11-15
      • 2012-08-26
      • 1970-01-01
      • 2017-02-26
      相关资源
      最近更新 更多