Returns forecasts and prediction intervals for a context-aware theta method forecast.

ctxthetaf(
  y,
  h = if (frequency(y) > 1) 2 * frequency(y) else 10,
  level = 95,
  theta = 0.5,
  fit_func = lm,
  predict_func = predict,
  type_pi = c("gaussian", "block-bootstrap", "surrogate", "kde", "bootstrap", "fitdistr",
    "meboot"),
  nsim = 100L,
  block_size = 5,
  seed = 123L,
  B = NULL,
  x = y,
  ...
)

Arguments

y

Time series (ts object or numeric vector)

h

Forecast horizon (default: 2*frequency for seasonal, 10 for non-seasonal)

level

Confidence level(s) for prediction intervals (default: 95)

theta

Theta coefficient for drift weighting (default: 0.5, giving theta line = 2)

  • theta = 0: No drift (pure SES)

  • theta = 0.5: Classical Theta method (theta line = 2)

  • theta = 1: Full drift

  • theta > 1: Amplified drift

fit_func

Model fitting function (default: lm)

predict_func

Prediction function (default: predict)

type_pi

Default is "gaussian", otherwise, uses sequential split conformal prediction as in Moudiki, T. (2025)

nsim

Number of simulations when type_pi is not "gaussian"

block_size

Size of block when type_pi is "block-bootstrap"

seed

Reproducibility seed

B

Alias for nsim

x

Deprecated, use y instead

...

Additional arguments passed to fit_func

Value

An object of class forecast

Details

The classical theta method of Assimakopoulos and Nikolopoulos (2000) is equivalent to simple exponential smoothing with drift, using theta = 2. This implementation extends the method by:

  1. Allowing flexible specification of theta parameter (default 0.5, which gives theta = 2)

  2. Using machine learning models to capture non-linear drift patterns

  3. Computing time-varying slopes via numerical differentiation

References

Hyndman, R.J., and Billah, B. (2003) Unmasking the Theta method. International J. Forecasting, 19, 287-290.

Moudiki, T. (2025). Conformal Predictive Simulations for Univariate Time Series. Proceedings of Machine Learning Research, 266, 1-2.

Author

T. Moudiki (based on RJH)

Examples

# Classical theta-like behavior (theta = 0.5)
fit1 <- ctxthetaf(AirPassengers)
plot(fit1)


# No drift (theta = 0)
fit2 <- ctxthetaf(AirPassengers, theta = 0)
plot(fit2)


# Amplified drift (theta = 1)
fit3 <- ctxthetaf(AirPassengers, theta = 1)
plot(fit3)


# With Random Forest
fit4 <- ctxthetaf(AirPassengers, fit_func = randomForest::randomForest)
plot(fit4)