| msarima | R Documentation |
Fits an ARIMA model with one or more seasonal components to a univariate time series. This function extends the standard ARIMA framework to time series with several seasonal patterns, such as daily and weekly seasonality in hourly data, or weekly and yearly seasonality in daily data.
msarima(
y,
order = c(0, 0, 0),
seasonal = list(),
seasonal.period = NULL,
fixed = NULL,
include.constant = FALSE,
optim_control = list(maxit = 200)
)
y |
A numeric vector or time series object ( |
order |
A numeric vector of length 3 specifying the non-seasonal part of the
ARIMA model: the AR order (p), the degree of differencing (d), and the MA order (q).
Default is |
seasonal |
A list of numeric vectors, each of length 3, specifying the seasonal
components. Each vector gives the seasonal AR order (P), the seasonal differencing
order (D), and the seasonal MA order (Q) of one component. For example,
|
seasonal.period |
A numeric vector of seasonal periods, one for each element of
|
fixed |
A numeric vector with one entry per parameter, used to hold some of them
at a given value: only the |
include.constant |
Should the model include a constant term? The constant is the
intercept of the model equation, not the mean of the series: for a stationary model
the two are related by |
optim_control |
A list of control parameters passed to |
The model is estimated by conditional maximum likelihood: the residuals are computed
recursively and the resulting Gaussian log-likelihood is maximised numerically with
optim, using the BFGS algorithm.
When d or any D is non-zero, the series is differenced before estimation
and the ARMA part is estimated on the differenced data. The first
d + sum(D * S) observations are therefore not used, which is why the residuals
and the fitted values start with as many NA values: these observations have
no differenced value to predict, so no residual is defined for them under the
conditional likelihood.
Standard errors are computed from the inverse of the observed information matrix
(negative Hessian). If the Hessian is singular, a warning is issued and the standard
errors are set to NA.
An object of class "msarima", which is a list containing:
order |
The non-seasonal ARIMA order (p, d, q). |
seasonal |
List of seasonal orders (P, D, Q), one vector per seasonal component. |
seasonal.period |
Vector of seasonal periods. |
coef |
Named vector of estimated coefficients: the AR, SAR, MA and SMA
parameters, followed by the intercept if |
var_coef |
Variance-covariance matrix of the coefficient estimates, with
the same dimension and order as |
mask |
Logical vector with the same length and order as |
loglik |
Log-likelihood of the fitted model. |
aic |
Akaike Information Criterion. |
bic |
Bayesian Information Criterion. |
aicc |
Corrected Akaike Information Criterion. |
sigma2 |
Estimated innovation variance. |
x |
The original time series. |
fitted |
One-step-ahead fitted values, on the scale of the original series. |
residuals |
Model residuals. Together with |
method |
Character string describing the fitted model, e.g.
|
series |
Name of the series. |
nobs |
Number of observations in the original series. |
n.used |
Number of observations used in estimation (after differencing). |
call |
The matched call. |
convergence |
Convergence code from |
The series must have at least 10 observations, both before and after differencing.
Seasonal periods must be at least 2 and at most half the length of the series.
If y is a ts or msts object, x, fitted and
residuals keep the same time series structure. If y is a plain numeric
vector, they are returned as ts with one seasonal period, or as msts
with several.
# Example 1: ARIMA with two seasonal components
set.seed(123)
y <- msarima.sim(nsim = 200,
order = c(1, 0, 0),
seasonal = list(c(1, 0, 0), c(0, 0, 1)),
seasonal.period = c(4, 11),
ar = c(0.5, 0.5), ma = 0.3, sigma2 = 1)
fit <- msarima(y, order = c(1, 0, 0),
seasonal = list(c(1, 0, 0), c(0, 0, 1)),
seasonal.period = c(4, 11))
print(fit)
summary(fit)
# Example 2: msts input, seasonal periods detected automatically
y_msts <- msts(y, seasonal.periods = c(4, 11))
fit_msts <- msarima(y_msts, order = c(1, 0, 0),
seasonal = list(c(1, 0, 0), c(0, 0, 1)))
# Example 3: differencing
fit_diff <- msarima(cumsum(y), order = c(1, 1, 0),
seasonal = list(c(0, 0, 1)),
seasonal.period = 4)
head(residuals(fit_diff)) # the first residual is NA
# Example 4: fixing parameters
# Note: the length of 'fixed' must match AR + SAR + MA + SMA + sigma
fit_fixed <- msarima(y, order = c(1, 0, 0),
seasonal = list(c(1, 0, 0), c(0, 0, 1)),
seasonal.period = c(4, 11),
fixed = c(0.5, NA, NA, NA))
AIC(fit); AIC(fit_fixed)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.