| Title: | Parametric Modal ARIMA and Seasonal ARIMA Models using the SKD Family |
|---|---|
| Description: | Implements parametric modal Autoregressive Integrated Moving Average (ARIMA) and seasonal ARIMA (SARIMA) models utilizing the Skewed Distribution (SKD) family, in which the conditional mode, rather than the conditional mean, follows the (seasonal) ARIMA recursion. Current distributions supported are the Skew-Normal, Skewed Student-t, and Skewed Laplace. The parameters are estimated by maximum likelihood using analytical gradients. Includes residual diagnostics, simulation envelopes, automatic order selection, joint and marginal modal forecasts, exact and parametric bootstrap prediction intervals, and classical asymptotic inference via the Fisher Information matrix. Methods are described in Galarza, C.E., Lachos, V.H., Cabral, C.R.B., & Castro, L.M. (2017) <doi:10.1002/sta4.140>. |
| Authors: | Christian Galarza [aut, cre], Sergio Luis Mercado Londoño [ctb], Víctor Hugo Lachos [ctb] (ORCID: <https://orcid.org/0000-0002-7239-2459>) |
| Maintainer: | Christian Galarza <[email protected]> |
| License: | GPL-3 |
| Version: | 0.2.0 |
| Built: | 2026-09-24 23:08:20 UTC |
| Source: | https://github.com/chedgala/modalforecast |
Automatic selection of Parametric Modal ARIMA and SARIMA models
auto.modal.arima( y, d = NA, D = NA, max.p = 5, max.q = 5, max.P = 1, max.Q = 1, seasonal = TRUE, period = stats::frequency(y), ic = c("aic", "bic"), dist = c("normal", "t", "laplace"), trace = FALSE )auto.modal.arima( y, d = NA, D = NA, max.p = 5, max.q = 5, max.P = 1, max.Q = 1, seasonal = TRUE, period = stats::frequency(y), ic = c("aic", "bic"), dist = c("normal", "t", "laplace"), trace = FALSE )
y |
numeric vector or time series of observations |
d |
Integer, degree of differencing. If NA, it's determined automatically. |
D |
Integer, degree of seasonal differencing. If NA, it's determined automatically. Ignored for non-seasonal models. |
max.p |
Maximum AR order |
max.q |
Maximum MA order |
max.P |
Maximum seasonal AR order |
max.Q |
Maximum seasonal MA order |
seasonal |
Logical. If |
period |
Seasonal period. Defaults to |
ic |
Information criterion to be used in model selection ("aic", "bic") |
dist |
Character string specifying the error distribution.
|
trace |
Logical. If |
This function performs a grid search over AR and MA orders, and over
seasonal AR and MA orders when the series is seasonal, to find the Modal
(S)ARIMA model with the smallest information criterion (AIC or BIC). As in
forecast::auto.arima, the seasonal differencing order D is
chosen with forecast::nsdiffs and then the regular order d with
forecast::ndiffs on the seasonally differenced series, unless they are
supplied.
An object of class modal_arima.
GitHub repository: https://github.com/chedgala/ModalForecast
Galarza, C. E., Lachos, V. H., Cabral, C. R. B., and Castro, L. M. (2017). Robust quantile regression using a generalized class of skewed distributions. Stat, 6(1), 113-130.
library(forecast) # Non-seasonal fit_auto <- auto.modal.arima(log10(lynx), d = 0, max.p = 2, max.q = 2) summary(fit_auto) # Seasonal, with a small search grid fit_sauto <- auto.modal.arima(log(AirPassengers), max.p = 1, max.q = 1, max.P = 1, max.Q = 1) fit_sautolibrary(forecast) # Non-seasonal fit_auto <- auto.modal.arima(log10(lynx), d = 0, max.p = 2, max.q = 2) summary(fit_auto) # Seasonal, with a small search grid fit_sauto <- auto.modal.arima(log(AirPassengers), max.p = 1, max.q = 1, max.P = 1, max.Q = 1) fit_sauto
Provides visual and statistical diagnostics for the residuals of a fitted Modal (S)ARIMA model. Produces a panel with the differenced series and fitted modes, the ACF and PACF of the randomized quantile residuals (RQR), a normal QQ-plot, a histogram and Ljung-Box p-values. For seasonal models the ACF, PACF and Ljung-Box statistics cover at least two seasonal periods.
diagnostics(object, ...) ## S3 method for class 'modal_arima' diagnostics(object, ...)diagnostics(object, ...) ## S3 method for class 'modal_arima' diagnostics(object, ...)
object |
An object of class |
... |
Additional arguments (unused). |
A list of ggplot objects (invisibly) and draws the panel.
# Non-seasonal fit <- fit_modal_arima(log10(lynx), order = c(2, 0, 0)) diagnostics(fit) # Seasonal airline model fit_air <- fit_modal_arima(log(AirPassengers), order = c(0, 1, 1), seasonal = list(order = c(0, 1, 1), period = 12)) diagnostics(fit_air)# Non-seasonal fit <- fit_modal_arima(log10(lynx), order = c(2, 0, 0)) diagnostics(fit) # Seasonal airline model fit_air <- fit_modal_arima(log(AirPassengers), order = c(0, 1, 1), seasonal = list(order = c(0, 1, 1), period = 12)) diagnostics(fit_air)
Constructs simulation envelopes for the distances
of the modal residuals, based on their
theoretical distribution under the SKD family (Galarza et al., 2017):
twice the distance follows the half-normal, half-t or standard exponential
distribution for the Skew-Normal, Skewed Student-t and Skewed Laplace
members, respectively.
envelope(object, ...) ## S3 method for class 'modal_arima' envelope(object, B = 100, refit = TRUE, ...)envelope(object, ...) ## S3 method for class 'modal_arima' envelope(object, B = 100, refit = TRUE, ...)
object |
An object of class |
... |
Additional arguments (unused). |
B |
Number of Monte Carlo replications for envelope construction. Default is 100. |
refit |
Logical. If |
With refit = TRUE (the default), each replication simulates a series
from the fitted model, re-estimates the model and computes the distances of
the re-estimated residuals, so the envelope accounts for parameter
estimation. This matters most for the Skewed Laplace, whose maximum
likelihood fit, like least absolute deviations, pulls several residuals to
zero: without refitting, the smallest distances fall below the envelope even
when the model is correct. With refit = FALSE, the envelope is built
from simulated innovations at the estimated parameters, which is faster.
A ggplot object (invisibly) and draws the envelope plot.
fit <- fit_modal_arima(log10(lynx), order = c(2, 0, 0)) envelope(fit, B = 10) # Seasonal model; refit = FALSE is faster, refit = TRUE accounts for estimation fit_air <- fit_modal_arima(log(AirPassengers), order = c(0, 1, 1), seasonal = list(order = c(0, 1, 1), period = 12)) envelope(fit_air, B = 10, refit = FALSE)fit <- fit_modal_arima(log10(lynx), order = c(2, 0, 0)) envelope(fit, B = 10) # Seasonal model; refit = FALSE is faster, refit = TRUE accounts for estimation fit_air <- fit_modal_arima(log(AirPassengers), order = c(0, 1, 1), seasonal = list(order = c(0, 1, 1), period = 12)) envelope(fit_air, B = 10, refit = FALSE)
Fits a Modal ARIMA or Modal SARIMA model, where the conditional mode follows an (optionally seasonal) ARIMA recursion and the innovations follow a member of the SKD (Skewed Distribution) family: Skew-Normal, Skewed Student-t or Skewed Laplace.
fit_modal_arima( y, order = c(1, 0, 0), seasonal = list(order = c(0, 0, 0), period = NA), dist = c("normal", "t", "laplace") )fit_modal_arima( y, order = c(1, 0, 0), seasonal = list(order = c(0, 0, 0), period = NA), dist = c("normal", "t", "laplace") )
y |
numeric vector or time series of observations. |
order |
A specification of the non-seasonal part of the model: the three components (p, d, q) are the AR order, the degree of differencing, and the MA order. |
seasonal |
A specification of the seasonal part of the model, as in
|
dist |
Character string specifying the error distribution from the
SKD family. One of |
Let . The model is
where are independent errors
with mode zero, so that is the conditional
mode of . The non-seasonal Modal ARIMA model is the special case
.
All members share the parameterization of Galarza et al. (2017),
with and , where
is the standard normal, Student-t or Laplace density. The mode
is also the -th quantile, and gives a
heavier right tail.
Parameters are estimated by maximum likelihood with BFGS and analytical
gradients, started from a conditional-sum-of-squares Gaussian (S)ARIMA fit.
The Skewed Laplace log-likelihood is not differentiable when a residual is
zero, so for dist = "laplace" the BFGS solution is refined with
Nelder-Mead. Stationarity and invertibility of the regular and seasonal
polynomials are enforced during optimization.
An object of class modal_arima containing:
yThe original time series.
orderThe non-seasonal order (p,d,q).
seasonalList with the seasonal order (P,D,Q) and period.
coefficientsNamed vector of estimated parameters.
vcovAsymptotic covariance matrix of the coefficients, from the observed information (delta method for sigma, gamma and nu).
loglikThe maximized log-likelihood.
nobsNumber of observations used in the likelihood, .
hessianThe observed information on the optimization scale: the Hessian of the negative log-likelihood, or the outer product of the per-observation scores (OPG) for the Skewed Laplace, whose log-likelihood is not twice differentiable, and whenever the Hessian is not positive definite.
informationWhich estimator was used for hessian: "hessian" or "opg".
convergenceConvergence code from optim.
distThe distribution used ("normal", "t", or "laplace").
fitted.values, residuals
Fitted modes and modal residuals on the scale of y (NA for the first observations).
GitHub repository: https://github.com/chedgala/ModalForecast
Galarza, C. E., Lachos, V. H., Cabral, C. R. B., and Castro, L. M. (2017). Robust quantile regression using a generalized class of skewed distributions. Stat, 6(1), 113-130.
auto.modal.arima, forecast.modal_arima
library(forecast) # Non-seasonal: Lynx data y <- log10(lynx) fit_n <- fit_modal_arima(y, order = c(2, 0, 0), dist = "normal") fit_t <- fit_modal_arima(y, order = c(2, 0, 0), dist = "t") fit_l <- fit_modal_arima(y, order = c(2, 0, 0), dist = "laplace") c(Normal = AIC(fit_n), Student = AIC(fit_t), Laplace = AIC(fit_l)) summary(fit_n) # Seasonal: the airline model for monthly air passengers fit_air <- fit_modal_arima(log(AirPassengers), order = c(0, 1, 1), seasonal = list(order = c(0, 1, 1), period = 12)) summary(fit_air) fc <- forecast(fit_air, h = 24) autoplot(fc)library(forecast) # Non-seasonal: Lynx data y <- log10(lynx) fit_n <- fit_modal_arima(y, order = c(2, 0, 0), dist = "normal") fit_t <- fit_modal_arima(y, order = c(2, 0, 0), dist = "t") fit_l <- fit_modal_arima(y, order = c(2, 0, 0), dist = "laplace") c(Normal = AIC(fit_n), Student = AIC(fit_t), Laplace = AIC(fit_l)) summary(fit_n) # Seasonal: the airline model for monthly air passengers fit_air <- fit_modal_arima(log(AirPassengers), order = c(0, 1, 1), seasonal = list(order = c(0, 1, 1), period = 12)) summary(fit_air) fc <- forecast(fit_air, h = 24) autoplot(fc)
Produces modal point forecasts and prediction intervals for a fitted
modal_arima object, with or without a seasonal component.
## S3 method for class 'modal_arima' forecast( object, h = 10, level = c(80, 95), interval = c("asymptotic", "bootstrap"), npaths = 1000, point = c("joint", "marginal"), ... )## S3 method for class 'modal_arima' forecast( object, h = 10, level = c(80, 95), interval = c("asymptotic", "bootstrap"), npaths = 1000, point = c("joint", "marginal"), ... )
object |
A modal_arima object. |
h |
The forecast horizon. |
level |
Confidence level for prediction intervals. |
interval |
Method for computing prediction intervals ("asymptotic" or "bootstrap"). |
npaths |
Number of simulated paths for bootstrap intervals. Defaults to 1000. |
point |
Modal point forecast: |
... |
Additional arguments. |
Because the mode is not a linear operator, two modal point forecasts are
available. point = "joint" (the default) returns the joint modal
trajectory: the most probable future path, obtained by iterating the model
with future innovations set to zero. point = "marginal" returns, for
each horizon , the conditional mode of itself. The two
coincide at and for symmetric errors (); for
skewed errors and the marginal mode equals the joint path plus
the mode of the forecast error
, which can be substantial for
integrated series.
With interval = "asymptotic", the prediction intervals use the exact
distribution of the forecast error at the estimated parameters, computed by
numerical convolution of the SKD densities. With interval = "bootstrap",
they use empirical quantiles of npaths simulated future paths.
An object of class forecast. Besides the usual components, it
contains mode_path (the joint modal trajectory) and mode_shift
(the correction from the joint path to the marginal mode).
library(forecast) # Non-seasonal fit <- fit_modal_arima(log10(lynx), order = c(2, 0, 0)) pred <- forecast(fit, h = 5, level = c(80, 95)) autoplot(pred) accuracy(pred) # Seasonal airline model: joint trajectory versus marginal mode fit_air <- fit_modal_arima(log(AirPassengers), order = c(0, 1, 1), seasonal = list(order = c(0, 1, 1), period = 12)) fc_joint <- forecast(fit_air, h = 24) fc_marg <- forecast(fit_air, h = 24, point = "marginal") round(cbind(joint = fc_joint$mean, marginal = fc_marg$mean)[c(1, 12, 24), ], 4) fc_boot <- forecast(fit_air, h = 12, interval = "bootstrap", npaths = 200)library(forecast) # Non-seasonal fit <- fit_modal_arima(log10(lynx), order = c(2, 0, 0)) pred <- forecast(fit, h = 5, level = c(80, 95)) autoplot(pred) accuracy(pred) # Seasonal airline model: joint trajectory versus marginal mode fit_air <- fit_modal_arima(log(AirPassengers), order = c(0, 1, 1), seasonal = list(order = c(0, 1, 1), period = 12)) fc_joint <- forecast(fit_air, h = 24) fc_marg <- forecast(fit_air, h = 24, point = "marginal") round(cbind(joint = fc_joint$mean, marginal = fc_marg$mean)[c(1, 12, 24), ], 4) fc_boot <- forecast(fit_air, h = 12, interval = "bootstrap", npaths = 200)
Returns the joint modal trajectory of the future values: the recursion is
iterated with future innovations set to their mode, zero. For the one-step
horizon this is the conditional mode of ; for longer horizons
it is the most probable path, see forecast.modal_arima.
## S3 method for class 'modal_arima' predict(object, n.ahead = 10, ...)## S3 method for class 'modal_arima' predict(object, n.ahead = 10, ...)
object |
A |
n.ahead |
The forecast horizon. |
... |
Additional arguments (unused). |
A numeric vector with the modal trajectory on the scale of y.