从图中可以看出其K阶滞后自相关系数都非常小呈截现象,因此判断时间系列为平稳性是合理的。
函数4:ACF检验函数 参数:时间序列
检验p值,默认为0.05 图形保存路径,默认为空 返回值:以框架形式
线性回归函数各个系数的检验p值 ACF函数的返回值
> modely=lm(y~time(y)) > summary(modely)
Call:
lm(formula = y ~ time(y))
Residuals:
Min 1Q Median 3Q Max -13.2206 -5.6292 -0.6742 6.3185 13.6971
Coefficients:
Estimate Std. Error t value Pr(>|t|) (Intercept) 8.659376 0.620538 13.96 <2e-16 *** time(y) 0.032966 0.002146 15.36 <2e-16 *** ---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 6.927 on 498 degrees of freedom Multiple R-squared: 0.3214, Adjusted R-squared: 0.3201 F-statistic: 235.9 on 1 and 498 DF, p-value: < 2.2e-16
> acf(rstudent(modely),main='关于y的acf自相关系数')
从图中可以看出ACF随着k的增大而缓慢下降,自相关系数大且为正因此判断y序列为非平稳时间序列是合理的。
3.2 例二
以TSA自带的数据tempdub为例验证数据的平稳性检验
3.2.1 绘图
>library(\y\
从图中可以看出此时间序列具有非常明显的周期性趋势。
3.2.2 Adf检验
> adf.test(tempdub) Augmented Dickey-Fuller Test
data: tempdub
Dickey-Fuller = -11.0773, Lag order = 5, p-value = 0.01 alternative hypothesis: stationary
结论:p-value = 0.01所以tempdub时间序列是平稳的。
3.2.3 Pp检验
> pp.test(tempdub) Phillips-Perron Unit Root Test
data: tempdub
Dickey-Fuller Z(alpha) = -51.0795, Truncation lag parameter = 4, p-value = 0.01
alternative hypothesis: stationary
警告信息:
In pp.test(tempdub) : p-value smaller than printed p-value 结论:p-value = 0.01再次验证该时间序列的平稳性。
3.2.4 ACF自相关函数判断
> modeltemp=lm(tempdub~time(tempdub)) > summary(modeltemp)
Call:
lm(formula = tempdub ~ time(tempdub))
Residuals:
Min 1Q Median 3Q Max -37.871 -19.066 2.394 17.053 28.156
Coefficients:
Estimate Std. Error t value Pr(>|t|) (Intercept) -214.1324 920.7668 -0.233 0.816 time(tempdub) 0.1322 0.4674 0.283 0.778
Residual standard error: 19.43 on 142 degrees of freedom Multiple R-squared: 0.0005629, Adjusted R-squared: -0.006475
F-statistic: 0.07998 on 1 and 142 DF, p-value: 0.7777
> acf(rstudent(modeltemp),main='关于tempdub的acf自相关系数')
从图中可以看出ACF也具有明显的周期性。
相关推荐: