从STL /分解中获取趋势和季节性模型

时间:2016-03-01 07:24:12

标签: r time-series

一旦我对时间序列数据进行了STL或分解,我该如何提取每个组件的模型? 例如,如何获得趋势的斜率和截距,季节性数据的周期等等? 如果需要,我可以提供样本数据,但这是一个普遍的问题。

1 个答案:

答案 0 :(得分:4)

作为您问题的部分答案,如果趋势是线性的,则可以很容易地提取趋势。这是一个例子:

library(forecast)
plot(decompose(AirPassengers))

enter image description here

在线性趋势的情况下,我们可以使用tslm()函数来提取截距和斜率

tslm(AirPassengers ~ trend)

Call:
lm(formula = formula, data = "AirPassengers", na.action = na.exclude)

Coefficients:
(Intercept)        trend  
     87.653        2.657  

为了获得包括季节的合适,这可以像

那样延伸
fit <- tslm(AirPassengers ~ trend + season)
> summary(fit)

Call:
lm(formula = formula, data = "AirPassengers", na.action = na.exclude)

Residuals:
    Min      1Q  Median      3Q     Max 
-42.121 -18.564  -3.268  15.189  95.085 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept)  63.50794    8.38856   7.571 5.88e-12 ***
trend         2.66033    0.05297  50.225  < 2e-16 ***
season2      -9.41033   10.74941  -0.875 0.382944    
season3      23.09601   10.74980   2.149 0.033513 *  
season4      17.35235   10.75046   1.614 0.108911    
season5      19.44202   10.75137   1.808 0.072849 .  
season6      56.61502   10.75254   5.265 5.58e-07 ***
season7      93.62136   10.75398   8.706 1.17e-14 ***
season8      90.71103   10.75567   8.434 5.32e-14 ***
season9      39.38403   10.75763   3.661 0.000363 ***
season10      0.89037   10.75985   0.083 0.934177    
season11    -35.51996   10.76232  -3.300 0.001244 ** 
season12     -9.18029   10.76506  -0.853 0.395335    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 26.33 on 131 degrees of freedom
Multiple R-squared:  0.9559,    Adjusted R-squared:  0.9518 
F-statistic: 236.5 on 12 and 131 DF,  p-value: < 2.2e-16

如果我正确地解释这个结果,每月平均增加2.66名乘客,第二个月平均比第一个月减少9.4名乘客,等等。