gpt4 book ai didi

r - bsts 包的预测置信区间比预测中的 auto.arima 宽得多

转载 作者:行者123 更新时间:2023-12-04 12:17:18 25 4
gpt4 key购买 nike

我最近阅读了有关贝叶斯结构时间序列模型的 Steven Scott 的 bsts 包,并想用它来对抗我一直用于各种预测任务的 forecast 包中的 auto.arima 函数。

我在几个示例中进行了尝试,并且对包的效率和点预测印象深刻。但是当我查看预测方差时,我几乎总是发现与 auto.arima 相比,bsts 最终给出了更宽的置信区间。这是白噪声数据的示例代码

library("forecast")
library("data.table")
library("bsts")
truthData = data.table(target = rnorm(250))
freq = 52
ss = AddGeneralizedLocalLinearTrend(list(), truthData$target)
ss = AddSeasonal(ss, truthData$target, nseasons = freq)
tStart = proc.time()[3]
model = bsts(truthData$target, state.specification = ss, niter = 500)
print(paste("time taken: ", proc.time()[3] - tStart))
burn = SuggestBurn(0.1, model)
pred = predict(model, horizon = 2 * freq, burn = burn, quantiles = c(0.10, 0.90))

## auto arima fit
max.d = 1; max.D = 1; max.p = 3; max.q = 3; max.P = 2; max.Q = 2; stepwise = FALSE
dataXts = ts(truthData$target, frequency = freq)
tStart = proc.time()[3]
autoArFit = auto.arima(dataXts, max.D = max.D, max.d = max.d, max.p = max.p, max.q = max.q, max.P = max.P, max.Q = max.P, stepwise = stepwise)
print(paste("time taken: ", proc.time()[3] - tStart))
par(mfrow = c(2, 1))
plot(pred, ylim = c(-5, 5))
plot(forecast(autoArFit, 2 * freq), ylim = c(-5, 5))

这是剧情 forecast variance bsts top panel auto.arima lower panel我想知道是否有人可以阐明这种行为以及我们如何控制预测方差。据我从 Hyndman 博士的论文中记忆起,auto.arima 的预测方差计算没有考虑参数估计方差,即估计的 ar 和 ma 系数的方差。这是我在这里看到的差异的驱动原因,还是我遗漏了其他微妙的点,可以通过一些参数来控制。

谢谢

这是一个脚本,用于测试比较 bsts 和 auto.arima 的中短期预测问题的包含概率

library("forecast")
library("data.table")
library("bsts")
set.seed(1234)
n = 260
freq = 52
h = 10
rep = 50
max.d = 1; max.D = 1; max.p = 2; max.q = 2; max.P = 1; max.Q = 1; stepwise = TRUE
containsProb = NULL
for (i in 1:rep) {
print(i)
truthData = data.table(time = 1:n, target = rnorm(n))
yTrain = truthData$target[1:(n - h)]
yTest = truthData$target[(n - h + 1):n]

## fit bsts model
ss = AddLocalLevel(list(), truthData$target)
ss = AddSeasonal(ss, truthData$target, nseasons = freq)
tStart = proc.time()[3]
model = bsts(yTrain, state.specification = ss, niter = 500)
print(paste("time taken: ", proc.time()[3] - tStart))
pred = predict(model, horizon = h, burn = SuggestBurn(0.1, model), quantiles = c(0.10, 0.90))
containsProbBs = sum(yTest > pred$interval[1,] & yTest < pred$interval[2,]) / h

## auto.arima model fit
dataTs = ts(yTrain, frequency = freq)
tStart = proc.time()[3]
autoArFit = auto.arima(dataTs, max.D = max.D, max.d = max.d, max.p = max.p, max.q = max.q, max.P = max.P, max.Q = max.P, stepwise = stepwise)
print(paste("time taken: ", proc.time()[3] - tStart))
fcst = forecast(autoArFit, h = h)

## inclusion probabilities for 80% CI
containsProbBs = sum(yTest > pred$interval[1,] & yTest < pred$interval[2,]) / h
containsProbAr = sum(yTest > fcst$lower[,1] & yTest < fcst$upper[,1]) / h
containsProb = rbindlist(list(containsProb, data.table(bs = containsProbBs, ar = containsProbAr)))
}
colMeans(containsProb)
> bs ar
0.79 0.80
c(sd(containsProb$bs), sd(containsProb$ar))
> [1] 0.13337719 0.09176629

最佳答案

区别在于BSTS模型是非平稳的,而本例中选择的ARIMA模型是平稳的(实际上只是白噪声)。对于 BSTS 模型,预测区间在预测范围内继续扩大,而 ARIMA 模型具有恒定的预测区间。对于第一个预测范围,它们相对接近,但对于更长的范围,它们会有所不同。

关于r - bsts 包的预测置信区间比预测中的 auto.arima 宽得多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38840467/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com