Title: | Likelihood Based Inference for ARIMA Modeling |
---|---|
Description: | Estimating and analyzing auto regressive integrated moving average (ARIMA) models. The primary function in this package is arima(), which fits an ARIMA model to univariate time series data using a random restart algorithm. This approach frequently leads to models that have model likelihood greater than or equal to that of the likelihood obtained by fitting the same model using the arima() function from the 'stats' package. This package enables proper optimization of model likelihoods, which is a necessary condition for performing likelihood ratio tests. This package relies heavily on the source code of the arima() function of the 'stats' package. For more information, please see Jesse Wheeler and Edward L. Ionides (2023) <arXiv:2310.01198>. |
Authors: | Jesse Wheeler [aut, cre, cph], Noel McAllister [aut], Dhajanae Sylvertooth [aut], Edward Ionides [ctb], Brian Ripley [ctb] (Author of arima source code in stats package.), R Core Team [cph] (Author of arima source code in stats package.) |
Maintainer: | Jesse Wheeler <[email protected]> |
License: | GPL (>= 3) |
Version: | 3.3.0.9000 |
Built: | 2024-10-27 05:04:56 UTC |
Source: | https://github.com/jeswheel/arima2 |
Construct table of AIC for all combinations 0<=p<=P and 0<=q<=Q
aicTable(data, P, Q, D = 0, ic = c("aic", "aicc"), ...)
aicTable(data, P, Q, D = 0, ic = c("aic", "aicc"), ...)
data |
a time series object, or a dataset that can be used as input into the arima function. |
P |
a positive integer value representing the maximum number of AR coefficients that should be included in the table. |
Q |
a positive integer value representing the maximum number of MA coefficients that should be included in the table. |
D |
a positive integer value representing the degree of differencing |
ic |
Information criterion to be used in the table. |
... |
Additional arguments passed to |
This function creates an AIC table for ARMA models of varying sizes. Each row for the table corresponds to a different AR value, and each column of the table corresponds to a different MA value.
A matrix containing the model AIC values.
set.seed(654321) aicTable(presidents, 3, 2)
set.seed(654321) aicTable(presidents, 3, 2)
Fit an ARIMA model to a univariate time series. This function builds on
the ARIMA model fitting approach used in stats::arima()
by fitting
model parameters via a random restart algorithm.
arima( x, order = c(0L, 0L, 0L), seasonal = list(order = c(0L, 0L, 0L), period = NA), xreg = NULL, include.mean = TRUE, transform.pars = TRUE, fixed = NULL, init = NULL, method = c("CSS-ML", "ML", "CSS"), n.cond, SSinit = c("Rossignol2011", "Gardner1980"), optim.method = "BFGS", optim.control = list(), kappa = 1e+06, diffuseControl = TRUE, max_iters = 100, max_repeats = 10, max_inv_root = 1, min_inv_root_dist = 0, eps_tol = 1e-04 )
arima( x, order = c(0L, 0L, 0L), seasonal = list(order = c(0L, 0L, 0L), period = NA), xreg = NULL, include.mean = TRUE, transform.pars = TRUE, fixed = NULL, init = NULL, method = c("CSS-ML", "ML", "CSS"), n.cond, SSinit = c("Rossignol2011", "Gardner1980"), optim.method = "BFGS", optim.control = list(), kappa = 1e+06, diffuseControl = TRUE, max_iters = 100, max_repeats = 10, max_inv_root = 1, min_inv_root_dist = 0, eps_tol = 1e-04 )
x |
a univariate time series |
order |
A specification of the non-seasonal part of the ARIMA
model: the three integer components |
seasonal |
A specification of the seasonal part of the ARIMA
model, plus the period (which defaults to |
xreg |
Optionally, a vector or matrix of external regressors,
which must have the same number of rows as |
include.mean |
Should the ARMA model include a mean/intercept term? The
default is |
transform.pars |
logical; if true, the AR parameters are
transformed to ensure that they remain in the region of
stationarity. Not used for |
fixed |
optional numeric vector of the same length as the total number of coefficients to be estimated. It should be of the form
where The entries of the The argument |
init |
optional numeric vector of initial parameter
values. Missing values will be filled in, by zeroes except for
regression coefficients. Values already specified in |
method |
fitting method: maximum likelihood or minimize conditional sum-of-squares. The default (unless there are missing values) is to use conditional-sum-of-squares to find starting values, then maximum likelihood. Can be abbreviated. |
n.cond |
only used if fitting by conditional-sum-of-squares: the number of initial observations to ignore. It will be ignored if less than the maximum lag of an AR term. |
SSinit |
a string specifying the algorithm to compute the
state-space initialization of the likelihood; see
|
optim.method |
The value passed as the |
optim.control |
List of control parameters for |
kappa |
the prior variance (as a multiple of the innovations variance) for the past observations in a differenced model. Do not reduce this. |
diffuseControl |
Boolean indicator of whether or initial observations will have likelihood values ignored if controlled by the diffuse prior, i.e., have a Kalman gain of at least 1e4. |
max_iters |
Maximum number of random restarts for methods "CSS-ML" and
"ML". If set to 1, the results of this algorithm is the same as
|
max_repeats |
Integer. If the last |
max_inv_root |
positive numeric value less than or equal to 1. This number represents the maximum size of the inverted MA or AR polynomial roots for a new parameter estimate to be considered an improvement to previous estimates. Concerns of numeric stability arise when the size of polynomial roots are near unity circle. The default value 1 means that the the parameter values corresponding with the best log-likelihood will be returned, even if they are near unity. Suitable values of this parameter are near the value 1. |
min_inv_root_dist |
positive numeric value less than 1. This number represents the minimum distance between AR and MA polynomial roots for a new parameter estimate to be considered an improvement on previous estimates. This is intended to avoid the possibility of returning parameter estimates with nearly canceling roots. Appropriate choices are values near 0. |
eps_tol |
Tolerance for accepting a new solution to be better than a previous solution in terms of log-likelihood. The default corresponds to a one ten-thousandth unit increase in log-likelihood. |
A list of class c("Arima2", "Arima")
. This list contains all of the
same elements as the output of stats::arima, along with some additional
elements. All elements of the output list are:
coef
A vector of AR, MA, and regression coefficients. These can be extracted by the stats::coef method.
sigma2
The MLE of the variance of the innovations.
var.coef
The estimated variance matrix of the coefficients
coef
, which can be extracted by the stats::vcov method.
mask
A vector containing boolean values, indicating which parameters of the model were estimated.
loglik
The maximized log-likelihood (of the differenced data).
aic
The AIC value corresponding to the log-likelihood.
arma
A compact form of the model specification, as a vector giving the number of AR, MA, seasonal AR and seasonal MA coefficients, plus the period and the number of non-seasonal and seasonal differences.
residuals
The fitted innovations.
call
The matched call.
series
The name of the series x.
code
The convergence value returned by stats::optim.
n.cond
The number of initial observations not used in the fitting.
nobs
The number of observations used for the fitting.
model
A list representing the Kalman Filter used in the fitting.
x
The input time series.
num_starts
Number of restarts before convergence criteria was satisfied.
all_values
Numeric vector of length num_starts
containing the
loglikelihood of every parameter initialization.
# example code set.seed(12345) arima(miHuron_level$Average, order = c(2, 0, 1), max_iters = 100)
# example code set.seed(12345) arima(miHuron_level$Average, order = c(2, 0, 1), max_iters = 100)
This function calculates the roots of the AR or MA polynomials that correspond to an ARMA model.
ARMApolyroots(model, type = c("AR", "MA"))
ARMApolyroots(model, type = c("AR", "MA"))
model |
Either of fitted object of class |
type |
character of value "AR" or "MA", indicating whether or not the AR or MA polynomial roots are desired. |
A numeric vector containing the roots of the MA or AR polynomials
set.seed(123456) ARMApolyroots(sample_ARMA_coef((order = c(2, 1))), type = "AR") mod <- arima(lh, order = c(3,0,0)) ARMApolyroots(mod, type = "AR")
set.seed(123456) ARMApolyroots(sample_ARMA_coef((order = c(2, 1))), type = "AR") mod <- arima(lh, order = c(3,0,0)) ARMApolyroots(mod, type = "AR")
The dataset is a subset of the monthly average depth (ft) of lake Michigan-Huron. The data were retrieved online from the Great Lakes Environmental Research Laboratory. Various measurement gauges exist; this data was taken from the master gauge.
miHuron_level
miHuron_level
miHuron_level
A data frame with 155 observations and two columns:
Date
column that records when the observation was made.
numeric
column representing the average depth in feet.
https://www.glerl.noaa.gov/data/dashboard/data/levels/mGauge/miHuronMog.csv
Arima2
objectThis function plots time series data loaded from an Arima2
object or plots
inverse roots of the AR or MA polynomials in a fitted ARIMA model on the
complex unit circle.
## S3 method for class 'Arima2' plot(x, roots = TRUE, title = NULL, tick.lab = NULL, ...)
## S3 method for class 'Arima2' plot(x, roots = TRUE, title = NULL, tick.lab = NULL, ...)
x |
An |
roots |
Would you instead prefer to plot the roots on a unit circle? Insert logical type here. |
title |
Title of plot |
tick.lab |
Time vector of numeric or character/string type. |
... |
Other parameters |
The output of this function is a ggplot
object, so layers may be added to
the output of this function using ggplot2
's plus operator.
Arima 2
plot, which is a ggplot2
object. Type of plot is
indicated through roots
parameter.
plot(arima(lh, order = c(1,0,1))) plot(x = arima(lh, order = c(3,0,1)), roots = FALSE)
plot(arima(lh, order = c(1,0,1))) plot(x = arima(lh, order = c(3,0,1)), roots = FALSE)
Arima2
objectThis function performs profile log-likelihood of an Arima2
function.
## S3 method for class 'Arima2' profile( fitted, d = 0, npts = 100L, lower = -1, upper = 1, which = 1L, max_iters = 1, ... )
## S3 method for class 'Arima2' profile( fitted, d = 0, npts = 100L, lower = -1, upper = 1, which = 1L, max_iters = 1, ... )
fitted |
An |
d |
Integer number of differences. Should match the differences used to
obtain the |
npts |
Integer number of points to evaluate the profile. |
lower |
Numeric lower bound for the profile search. |
upper |
Numeric upper bound for the profile search. |
which |
Integer indicating which parameter to perform the profile over. See Details section for more information. |
max_iters |
Maximum number of random restarts. See arima for more details. |
... |
additional arguments needed for the profile function |
The parameter which
specifies parameter in the following vector will be
profiled over:
where are non-negative integers representing the number of AR and
MA coefficients of
fitted
, respectively, and are the AR
coefficients,
are the MA coefficients,
are the
seasonal AR coefficients,
are the seasonal MA coefficients and
is the model intercept.
data.frame object containing the results of the profile likelihood.
# example code set.seed(123) mod <- arima(miHuron_level$Average, order = c(1, 0, 1), max_iters = 100) prof <- profile(mod, which = 2L, lower = -0.5, upper = 0.5) plot(prof$ma1, prof$loglik)
# example code set.seed(123) mod <- arima(miHuron_level$Average, order = c(1, 0, 1), max_iters = 100) prof <- profile(mod, which = 2L, lower = -0.5, upper = 0.5) plot(prof$ma1, prof$loglik)
This function randomly samples the ARMA coefficients of a specified ARMA model. The coefficients are sampled so that the resulting ARMA model is both causal and invertible.
sample_ARMA_coef( order = c(0L, 0L), seasonal = list(order = c(0L, 0L), period = NA), n = 1, Mod_bounds = c(0.05, 0.95), min_inv_root_dist = 0 )
sample_ARMA_coef( order = c(0L, 0L), seasonal = list(order = c(0L, 0L), period = NA), n = 1, Mod_bounds = c(0.05, 0.95), min_inv_root_dist = 0 )
order |
A specification of the non-seasonal part of the ARIMA model:
this is different than the |
seasonal |
A specification of the seasonal part of the ARIMA model. Can
be either a vector of length 2, or a list with an |
n |
An integer indicating how many sets of ARMA coefficients should be sampled. |
Mod_bounds |
Bounds on the magnitude of the roots. |
min_inv_root_dist |
This parameter is included so as to help avoid ARMA
models that contain parameter redundancy, if desired. Specifically,
this parameter ensures that the minimum distance between any of the
inverted roots in the AR and MA polynomials is greater than
|
For an ARMA model to be causal and invertible, the roots of the AR and MA polynomials must lie outside the the complex unit circle. The AR and MA polynomials are defined as:
where is a complex number,
are the
AR coefficients of the ARMA model, and
are the
MA coefficients of the ARMA
model.
ARMA coefficients are sampled by sampling inverse roots to be inside the complex unit circle, and then calculating the resulting polynomial. To ensure that the resulting polynomial coefficients are real, we only sample half of the needed number of complex roots, and set the remaining half to be the complex conjugate of the sampled points. In the case where the number of coefficients is odd, the remaining root is sampled uniformly, satisfying the Mod_bounds parameter.
a vector of randomly sampled ARMA coefficients.
{ sample_ARMA_coef( order = c(2, 1), seasonal = list(order = c(1, 0), period = 2), n = 100 ) }
{ sample_ARMA_coef( order = c(2, 1), seasonal = list(order = c(1, 0), period = 2), n = 100 ) }