R包forecast提供了用于显示和分析单变量时间序列预测的方法和工具,包括通过状态空间模型进行指数平滑和自动ARIMA建模。
一个相complementary的预测包是fable包,它在tidyverse框架中实现了许多相同的模型。
您可以从CRAN安装稳定版本。
install.packages("forecast", dependencies = TRUE)
您可以从Github安装开发版本。
# install.packages("remotes") remotes::install_github("robjhyndman/forecast")
library(forecast) library(ggplot2) # ETS预测 USAccDeaths |> ets() |> forecast() |> autoplot() # 自动ARIMA预测 WWWusage |> auto.arima() |> forecast(h=20) |> autoplot() # ARFIMA预测 library(fracdiff) x <- fracdiff.sim( 100, ma=-.4, d=.3)$series arfima(x) |> forecast(h=30) |> autoplot() # 使用STL进行预测 USAccDeaths |> stlm(modelfunction=ar) |> forecast(h=36) |> autoplot() AirPassengers |> stlf(lambda=0) |> autoplot() USAccDeaths |> stl(s.window='periodic') |> forecast() |> autoplot() # TBATS预测 USAccDeaths |> tbats() |> forecast() |> autoplot() taylor |> tbats() |> forecast() |> autoplot()
该包是免费和开源软件,基于GPL-3许可。