如何预测时间序列,包括 R 中的季节性因素

How to forecast time series, including a seasonality factor in R

我有以下示例数据:

library(data.table)
dt <- data.table('time' = c(1:10),
                    'units'= c(89496264,81820040,80960072,109164545,96226255,96270421,95694992,117509717,105134778,0))

我想为 time = 10units 制作一个 forecast

我可以看到在 time = 4*k,其中 k = 1,2,... 单位有很大的增加,我想将其作为季节性因素包括在内。

我怎么能在 R 中做到这一点?我已经查看了 auto.arima,但似乎不是这样。

谢谢

Prophet API 可让您轻松计算预测值,其中的非线性趋势与每年、每周和每天的季节性相吻合。

引自上文link:

It works best with time series that have strong seasonal effects and several seasons of historical data. Prophet is robust to missing data and shifts in the trend, and typically handles outliers well.

install.packages(‘prophet’)
library(prophet)
model <- prophet(dt) # see ?prophet for details, this builds the model (like auto.arima)
future <- make_future_dataframe(model, periods = 10) # creates the "future" data 
forecast <- predict(model, future) # predictions

tail(forecast)

Here the complete Example in R.

你是对的,你可以 98.4% 打赌 t=4*k 有一个季节性,它的值为 +21108156。如果假定季节性是乘法而不是加法,则可以得到 98.5%,即存在季节性,其值为 +18.7%。

我就是这样进行的,没有使用现成的包,这样你就可以提出各种类似的问题。

首先引入一个新的布尔变量 dt$season = (dt$time %% 4)==0,它在 t=0,4,8,... 时为真(即 =1),在其他地方为假(即 =0)。然后函数 x~a*season+b 等于 a+b 对于 t=0,4,8,... 和 b 其他地方。换句话说,a是季节性影响和非季节性影响之间的差异。

线性回归 fit <- lm(units ~ season, data= dt),给你 a=21108156summary(fit) 告诉你标准误差 a 是 6697979,所以观察值 a=21108156 出现的概率小于 0.0161,如果它为 0。因此,您可以合理地打赌有 4 个周期的季节性,有超过 1-0.0161=98.388% 的概率是正确的。

如果您假设季节性是乘法的,请使用与变量 dt$mult = dt$units * dt$season 相同的推理。这次 a * dt$mult + b 在季节性适用时等于 a * dt$units + b,在不适用时等于 b。因此,季节性带来了 a * dt$units 的差异,即用平均值乘以 a=.1877=18.77%,显着性为 0.01471=1-98.5%

这就是现成包的工作原理。