R fable包或其他包中是否有模型或参数施加与对数函数曲线一致的预测约束?

问题描述 投票:0回答:0

我从事时间序列预测工作,主要关注 R 寓言包。我有 32 个月的数据,我正在尝试不同的模型来测试在第 13-32 个月期间累计月度单位转换到死状态“X”的假设预测,作为时间 0 时单位总数的百分比,通过根据 1-12 个月的数据进行训练。过渡曲线是指数衰减的倒数;它是一条对数曲线,只能随时间上升或变平,并且永远不会超过 100%;它不能蜷缩,因为死去的人永远不会回来。我将 13-32 个月的预测与实际数据进行比较。并不是所有的初始单位都会死亡,只有一部分会死亡。在下图中,粗黑线显示了 13-32 个月的实际数据,细彩色线显示了使用 fable 包中的 NAIVE 函数对这些月份的预测模拟路径,如底部发布的代码所示。

是否有任何参数约束可以应用于与这种非常真实的曲线一致的寓言包,其中曲线不能随着时间的推移指向下方并且永远不会超过 100%?或者是否有任何其他 R 包可以帮助预测这种类型的时间序列?

数据与代码:

library(dplyr)
library(fabletools)
library(fable)
library(feasts)
library(ggplot2)
library(tidyr)
library(tsibble)

DF <- data.frame(
  Month =c(1:32),
  rateCumX=c(
    0.1623159,0.23137659,0.29942238,0.35294557,0.39603576,0.42849893,0.45752922,0.48252959,
    0.50369408,0.52248541,0.53859013,0.55262019,0.56639651,0.57797878,0.58750131,0.59563576,
    0.60380006,0.61141211,0.61706891,0.62215854,0.62606905,0.62966611,0.63217361,0.63448708,
    0.63647219,0.63760653,0.63863640,0.63930805,0.63956178,0.63969611,0.63977074,0.63977074
  )
) %>% 
  as_tsibble(index = Month)

fit_bstrp <- DF[1:12,] %>%
  model(NAIVE(rateCumX))
sim <- fit_bstrp %>% generate(h = 20, times = 100, bootstrap = TRUE)
DF[1:12,] %>%
  ggplot(aes(x = Month)) +
  autolayer(
    filter_index(DF, 13 ~ .), # 13th + month historical data
    colour = "black", size = 1.5) +
  geom_line(aes(y = rateCumX)) +
  geom_line(aes(y = .sim, colour = as.factor(.rep)),
            data = sim) +
  labs(title="Percentage transitions using untransformed naive method", 
       y="Cum % of original population that transitions") +
  guides(colour = "none")
r time-series forecasting exponential-distribution fable
© www.soinside.com 2019 - 2024. All rights reserved.