Learn R Programming

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 = -0.4, d = 0.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

453,617

Version

9.0.0

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Rob Hyndman

Last Published

January 11th, 2026

Functions in forecast (9.0.0)

forecast.fracdiff

Forecasting using ARIMA or ARFIMA models
fitted.ARFIMA

h-step in-sample forecasts for time series models.
dm.test

Diebold-Mariano test for predictive accuracy
croston_model

Croston forecast model
ets

Exponential smoothing state space model
findfrequency

Find dominant frequency of a time series
forecast.mts

Forecasting time series
forecast.HoltWinters

Forecasting using Holt-Winters objects
forecast.modelAR

Forecasting using user-defined model
forecast.baggedModel

Forecasting using a bagged model
forecast.StructTS

Forecasting using Structural Time Series models
easter

Easter holidays in each season
dshw

Double-Seasonal Holt-Winters Forecasting
forecast.mean_model

Mean Forecast
forecast.mlm

Forecast a multiple linear model with possible time series components
autolayer

Create a ggplot layer appropriate to a particular data type
forecast-package

forecast: Forecasting Functions for Time Series and Linear Models
forecast.stl

Forecasting using stl objects
forecast.croston_model

Forecasts for intermittent demand using Croston's method
forecast.bats

Forecasting using BATS and TBATS models
forecast.spline_model

Returns local linear forecasts and prediction intervals using cubic smoothing splines estimated with spline_model().
forecast.lm

Forecast a linear model with possible time series components
fourier

Fourier terms for modelling seasonality
forecast.ets

Forecasting using ETS models
forecast.nnetar

Forecasting using neural network models
modelAR

Time Series Forecasts with a user-defined model
mean_model

Mean Forecast Model
forecast.rw_model

Naive and Random Walk Forecasts
gas

Australian monthly gas production
forecast.theta_model

Theta method forecasts.
is.forecast

Is an object a particular forecast type?
ma

Moving-average smoothing
nnetar

Neural Network Time Series Forecasts
gghistogram

Histogram with optional normal and kernel density functions
gglagplot

Time series lag ggplots
nsdiffs

Number of differences required for a seasonally stationary series
is.constant

Is an object constant?
is.acf

Is an object a particular model type?
forecast.ts

Forecasting time series
na.interp

Interpolate missing values in a time series
ocsb.test

Osborn, Chui, Smith, and Birchenhall Test for Seasonal Unit Roots
plot.forecast

Forecast plot
reexports

Objects exported from other packages
plot.Arima

Plot characteristic roots from ARIMA model
residuals.forecast

Residuals for various time series models
ndiffs

Number of differences required for a stationary series
autoplot.mforecast

Multivariate forecast plot
modeldf

Compute model degrees of freedom
monthdays

Number of days in each season
StatForecast

Forecast plot
getResponse

Get response variable from time series model.
msts

Multi-Seasonal Time Series
mstl

Multiple seasonal decomposition
ggmonthplot

Create a seasonal subseries ggplot
rw_model

Random walk model
seasadj

Seasonal adjustment
simulate.ets

Simulation from a time series model
sindexf

Forecast seasonal index
gold

Daily morning gold prices
tbats

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

Half-hourly electricity demand
subset.ts

Subsetting a time series
tsCV

Time series cross-validation
plot.ets

Plot components from ETS model
plot.bats

Plot components from BATS model
theta_model

Theta model
tsclean

Identify and replace outliers and missing values in a time series
ses

Exponential smoothing forecasts
ggtsdisplay

Time series display
ggseasonplot

Seasonal plot
seasonal

Extract components from a time series decomposition
tbats.components

Extract components of a TBATS model
spline_model

Cubic spline stochastic model
stlm

Forecasting model using STL with a generative time series model
seasonaldummy

Seasonal dummy variables
tsoutliers

Identify and replace outliers in a time series
tslm

Fit a linear model with time series components
wineind

Australian total wine sales
woolyrnq

Quarterly production of woollen yarn in Australia