Learn R Programming

⚠️There's a newer version (8.23.0) of this package.Take me there.

forecast

The R package forecast provides methods and tools for displaying and analysing univariate time series forecasts including exponential smoothing via state space models and automatic ARIMA modelling.

A complementary forecasting package is the fable package, which implements many of the same models but in a tidyverse framework.

Installation

You can install the stable version from CRAN.

install.packages('forecast', dependencies = TRUE)

You can install the development version from Github

# install.packages("remotes")
remotes::install_github("robjhyndman/forecast")

Usage

library(forecast)
library(ggplot2)

# ETS forecasts
USAccDeaths %>%
  ets() %>%
  forecast() %>%
  autoplot()

# Automatic ARIMA forecasts
WWWusage %>%
  auto.arima() %>%
  forecast(h=20) %>%
  autoplot()

# ARFIMA forecasts
library(fracdiff)
x <- fracdiff.sim( 100, ma=-.4, d=.3)$series
arfima(x) %>%
  forecast(h=30) %>%
  autoplot()

# Forecasting with STL
USAccDeaths %>%
  stlm(modelfunction=ar) %>%
  forecast(h=36) %>%
  autoplot()

AirPassengers %>%
  stlf(lambda=0) %>%
  autoplot()

USAccDeaths %>%
  stl(s.window='periodic') %>%
  forecast() %>%
  autoplot()

# TBATS forecasts
USAccDeaths %>%
  tbats() %>%
  forecast() %>%
  autoplot()

taylor %>%
  tbats() %>%
  forecast() %>%
  autoplot()

For more information

License

This package is free and open source software, licensed under GPL-3.

Copy Link

Version

Install

install.packages('forecast')

Monthly Downloads

229,245

Version

8.21.1

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

August 31st, 2023

Functions in forecast (8.21.1)

autoplot.acf

ggplot (Partial) Autocorrelation and Cross-Correlation Function Estimation and Plotting
autolayer.mts

Automatically create a ggplot for time series objects
auto.arima

Fit best ARIMA model to univariate time series
autolayer

Create a ggplot layer appropriate to a particular data type
autoplot.decomposed.ts

Plot time series decomposition components using ggplot
bizdays

Number of trading days in each season
checkresiduals

Check that residuals from a time series model look like white noise
bld.mbb.bootstrap

Box-Cox and Loess-based decomposition bootstrap.
baggedModel

Forecasting using a bagged model
bats

BATS model (Exponential smoothing state space model with Box-Cox transformation, ARMA errors, Trend and Seasonal components)
dshw

Double-Seasonal Holt-Winters Forecasting
fitted.ARFIMA

h-step in-sample forecasts for time series models.
ets

Exponential smoothing state space model
croston

Forecasts for intermittent demand using Croston's method
easter

Easter holidays in each season
forecast-package

forecast: Forecasting Functions for Time Series and Linear Models
dm.test

Diebold-Mariano test for predictive accuracy
forecast.HoltWinters

Forecasting using Holt-Winters objects
forecast.fracdiff

Forecasting using ARIMA or ARFIMA models
findfrequency

Find dominant frequency of a time series
forecast.lm

Forecast a linear model with possible time series components
forecast.mlm

Forecast a multiple linear model with possible time series components
forecast.nnetar

Forecasting using neural network models
forecast.StructTS

Forecasting using Structural Time Series models
forecast.mts

Forecasting time series
forecast.modelAR

Forecasting using user-defined model
forecast.baggedModel

Forecasting using a bagged model
forecast.stl

Forecasting using stl objects
forecast.bats

Forecasting using BATS and TBATS models
forecast.ets

Forecasting using ETS models
is.constant

Is an object constant?
gold

Daily morning gold prices
gghistogram

Histogram with optional normal and kernel density functions
ggmonthplot

Create a seasonal subseries ggplot
gglagplot

Time series lag ggplots
getResponse

Get response variable from time series model.
mstl

Multiple seasonal decomposition
na.interp

Interpolate missing values in a time series
forecast.ts

Forecasting time series
gas

Australian monthly gas production
fourier

Fourier terms for modelling seasonality
msts

Multi-Seasonal Time Series
ma

Moving-average smoothing
rwf

Naive and Random Walk Forecasts
meanf

Mean Forecast
StatForecast

Forecast plot
plot.ets

Plot components from ETS model
nsdiffs

Number of differences required for a seasonally stationary series
ocsb.test

Osborn, Chui, Smith, and Birchenhall Test for Seasonal Unit Roots
nnetar

Neural Network Time Series Forecasts
ndiffs

Number of differences required for a stationary series
reexports

Objects exported from other packages
is.acf

Is an object a particular model type?
seasonal

Extract components from a time series decomposition
ggseasonplot

Seasonal plot
autoplot.mforecast

Multivariate forecast plot
subset.ts

Subsetting a time series
monthdays

Number of days in each season
simulate.ets

Simulation from a time series model
modelAR

Time Series Forecasts with a user-defined model
sindexf

Forecast seasonal index
seasonaldummy

Seasonal dummy variables
plot.forecast

Forecast plot
plot.bats

Plot components from BATS model
plot.Arima

Plot characteristic roots from ARIMA model
is.forecast

Is an object a particular forecast type?
ggtsdisplay

Time series display
splinef

Cubic Spline Forecast
taylor

Half-hourly electricity demand
residuals.forecast

Residuals for various time series models
seasadj

Seasonal adjustment
tbats

TBATS model (Exponential smoothing state space model with Box-Cox transformation, ARMA errors, Trend and Seasonal components)
thetaf

Theta method forecast
tbats.components

Extract components of a TBATS model
wineind

Australian total wine sales
tslm

Fit a linear model with time series components
tsoutliers

Identify and replace outliers in a time series
ses

Exponential smoothing forecasts
tsCV

Time series cross-validation
woolyrnq

Quarterly production of woollen yarn in Australia
tsclean

Identify and replace outliers and missing values in a time series
accuracy.default

Accuracy measures for a forecast model
Acf

(Partial) Autocorrelation and Cross-Correlation Function Estimation
CV

Cross-validation statistic
BoxCox.lambda

Automatic selection of Box Cox transformation parameter
arimaorder

Return the order of an ARIMA or ARFIMA model
Arima

Fit ARIMA model to univariate time series
arfima

Fit a fractionally differenced ARFIMA model
CVar

k-fold Cross-Validation applied to an autoregressive model
arima.errors

Errors from a regression model with ARIMA errors
BoxCox

Box Cox Transformation