检验时间序列残差
在应用预测方法时,务必检查残差是否"表现良好"(即没有离群点或模式),并且类似白噪声。预测区间是在假设残差也服从正态分布的前提下计算的。您可以使用 checkresiduals() 函数来验证这些特性;它还会给出 Ljung-Box 检验的结果。
到目前为止,您还没有使用过管道函数(%>%),现在是个很好的时机来引入它。当函数嵌套较多时,使用管道可以让代码更易读。为保持一致,请始终在函数名后加上圆括号,以便与其他对象区分,即使函数没有参数。示例如下:
> function(foo) # 这两行
> foo %>% function() # 是等价的!
> foo %>% function # 不一致
在本练习中,您将对与上一个练习等价的预测对象运行以上函数(fcgoog 来自对 goog 应用 naive(),fcbeer 来自对 ausbeer 应用 snaive())。
本练习是课程的一部分
R 中的预测
练习说明
- 使用上述管道写法,在与
fcgoog等价的预测对象上运行checkresiduals()。 - 根据该 Ljung-Box 检验的结果,残差是否类似白噪声?将
googwn赋值为TRUE或FALSE。 - 用类似的管道写法,在与
fcbeer等价的预测对象上运行checkresiduals()。 - 根据该 Ljung-Box 检验的结果,残差是否类似白噪声?将
beerwn赋值为TRUE或FALSE。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Check the residuals from the naive forecasts applied to the goog series
goog %>% naive() %>% ___
# Do they look like white noise (TRUE or FALSE)
googwn <- ___
# Check the residuals from the seasonal naive forecasts applied to the ausbeer series
___
# Do they look like white noise (TRUE or FALSE)
beerwn <- ___