## 8.1 平稳性和差分

### 差分

Box.test(diff(goog200),lag=10,type="Ljung-Box")
#>
#>  Box-Ljung test
#>
#> data:  diff(goog200)
#> X-squared = 11, df = 10, p-value = 0.4

### 随机游走模型

• 长期的明显上升或下降趋势。
• 游走方向上突然的、不能预测的变化。

### 季节性差分

8.3 中下方的图显示的是 A10（抗糖尿病）药剂在澳大利亚月销售量的对数的季节差值。经过变换和差分，序列变得相对平稳。

cbind("销售量 (\$百万)" = a10,
"每月销量对数" = log(a10),
"每年销量变化对数" = diff(log(a10),12)) %>%
autoplot(facets=TRUE) +
xlab("年份") + ylab("") +
ggtitle("抗糖尿病药剂销量")+
theme(text = element_text(family = "STHeiti"))+
theme(plot.title = element_text(hjust = 0.5))

cbind("十亿千瓦时" = usmelec,
"对数" = log(usmelec),
"季节性\n 差分对数" = diff(log(usmelec),12),
"二次\n 差分对数" = diff(diff(log(usmelec),12),1)) %>%
autoplot(facets=TRUE) +
xlab("年份") + ylab("") +
ggtitle("美国电网每月发电量")+
theme(text = element_text(family = "STHeiti"))+
theme(plot.title = element_text(hjust = 0.5))

### 单位根检验

library(urca)
goog %>% ur.kpss() %>% summary()
#>
#> #######################
#> # KPSS Unit Root Test #
#> #######################
#>
#> Test is of type: mu with 7 lags.
#>
#> Value of test-statistic is: 10.72
#>
#> Critical value for a significance level of:
#>                 10pct  5pct 2.5pct  1pct
#> critical values 0.347 0.463  0.574 0.739

goog %>% diff() %>% ur.kpss() %>% summary()
#>
#> #######################
#> # KPSS Unit Root Test #
#> #######################
#>
#> Test is of type: mu with 7 lags.
#>
#> Value of test-statistic is: 0.0324
#>
#> Critical value for a significance level of:
#>                 10pct  5pct 2.5pct  1pct
#> critical values 0.347 0.463  0.574 0.739

ndiffs(goog)
#> [1] 1

usmelec %>% log() %>% nsdiffs()
#> [1] 1
usmelec %>% log() %>% diff(lag=12) %>% ndiffs()
#> [1] 1

### 参考文献

Kwiatkowski, D., Phillips, P. C. B., Schmidt, P., & Shin, Y. (1992). Testing the null hypothesis of stationarity against the alternative of a unit root: How sure are we that economic time series have a unit root? Journal of Econometrics, 54(1-3), 159–178. [DOI]

1. 更准确地说，如果 $$y_t$$平稳时间序列，那么对于所有 $$s$$$$(y_t,\dots,y_{t+s})$$ 的分布不依赖于 $$t$$↩︎