R 中的简单移动平均函数 "sma","level" 参数无法正常工作

Simple moving average function "sma" in R, "level" argument not working properly

我需要为我尝试执行的预测获得 80% 和 95% 的置信水平,而简单移动平均函数除了提供 95% 的置信水平外,没有提供任何其他信息。 是否有解决此问题的方法或任何变通方法以获得 80% 的置信度?

这是一个示例代码,您会注意到下(上)界 80% 和下(上)界 95% 的输出完全相同。

library(smooth)
library(forecast)
iris
x1 = sma(iris$Sepal.Length, level = .80)
x2 = sma(iris$Sepal.Length, level = .95)
forecast(x1)
forecast(x2)

> forecast(x1)
Time Series:
Start = 151 
End = 160 
Frequency = 1 
    Point forecast Lower bound (2.5%) Upper bound (97.5%)
151       6.320000           5.153756            7.486244
152       6.244000           5.054660            7.433340
153       6.232800           5.010969            7.454631
154       6.179360           4.912203            7.446517
155       6.175232           4.845518            7.504946
156       6.230278           4.815333            7.645224
157       6.212334           4.755426            7.669243
158       6.206001           4.702861            7.709141
159       6.200641           4.648248            7.753034
160       6.204897           4.602211            7.807583
> forecast(x2)
Time Series:
Start = 151 
End = 160 
Frequency = 1 
    Point forecast Lower bound (2.5%) Upper bound (97.5%)
151       6.320000           5.153756            7.486244
152       6.244000           5.054660            7.433340
153       6.232800           5.010969            7.454631
154       6.179360           4.912203            7.446517
155       6.175232           4.845518            7.504946
156       6.230278           4.815333            7.645224
157       6.212334           4.755426            7.669243
158       6.206001           4.702861            7.709141
159       6.200641           4.648248            7.753034
160       6.204897           4.602211            7.807583

关于如何查找预测区间,您有两种选择。在第一个 sma 模型中,没有指定期望水平或预测范围。然后可以使用包 smooth 中的函数 forecast

x1 <- sma(iris$Sepal.Length)
x2 <- sma(iris$Sepal.Length)
smooth::forecast(x1, level = 0.80, h=12) # no need to used forecast package
smooth::forecast(x2, level = 0.95, h=12)

第二个选项是在 sma 调用中指定预测属性:

x1 <- sma(iris$Sepal.Length, level = 0.80, h=12, intervals="parametric")

预测数据存储在变量x1中

x1$forecast
x1$lower
x1$upper