The `tsarima` function is used to fit an ARIMA model to a univariate time series.
tsarima(
x,
order = c(0L, 0L, 0L),
seasonal = list(order = c(0L, 0L, 0L), period = NA),
xreg = NULL,
xreg.order = NA,
include.const = TRUE,
log = FALSE,
train.prop = 1,
arch.test = FALSE,
transform.pars = TRUE,
fixed = NULL,
init = NULL,
method = c("CSS-ML", "ML", "CSS"),
SSinit = c("Gardner1980", "Rossignol2011"),
optim.method = "BFGS",
optim.control = list(),
kappa = 1e+06
)# S3 method for tsarima
print(
x,
digits = max(3L, getOption("digits") - 3L),
se = TRUE,
signif.stars = TRUE,
...
)
# S3 method for tsarima
summary(
object,
digits = max(3L, getOption("digits") - 3L),
se = TRUE,
signif.stars = TRUE,
...
)
A list of class `tsarima` with components:
a vector of AR, MA and regression coefficients, which can be extracted by the coef method.
a value of the model's constant term. Return NULL if include.const = FALSE.
the maximum likelihood estimate of the white noise variance.
he estimated variance matrix of the coefficients coef, which can be extracted by the vcov method.
the maximized log-likelihood (of the differenced data), or the approximation to it used.
the AIC, AICc, and BIC values corresponding to the log-likelihood. Only valid for method = `ML` fits.
a list of prediction error estimators, including $ME for mean error, $RMSE for root mean squared error, $MAE for mean absolute error, $MPE for mean percentage error, $MAPE for mean absolute percentage error, $MASE for mean absolute scaled error, $MASE.S for seasonal mean absolute scaled error, and $ACF1 for lag 1 autocorrelation.
a vector of the ARIMA order: \((p, P, q, Q, \ell, d, D)\).
proportion of training data.
data of the original series.
list of time in which the series values were observed.
time gap between the series and forecasted values.
name of the time series for which forecasts was requested.
list of time in which the series values were used for model fitting. It will be the same as x.time if train.prop = 1.
data of the original series which were used for model fitting. It will be the same as x if train.prop = 1.
a vector of fitted series values. If train.prop is smaller than 1, it will have the same length as x.used.
a vector of the series residuals. If train.prop is smaller than 1, it will have the same length as x.used.
a vector of fitted series values after inverted from log-transformation. Only available if log = TRUE. If train.prop is smaller than 1, it will have the same length as x.used.
a vector of the series residuals after inverted from log-transformation. Only available if log = TRUE. If train.prop is smaller than 1, it will have the same length as x.used.
logical. Indicates whether series values are log-transformed for model fitting or not.
the matched call.
series name x in match call.
the convergence value returned by optim.
the number of `used` observations for the fitting, can also be extracted via nobs and is used by BIC.
a list representing the Kalman filter used in the fitting. See KalmanLike.
resulting chi-square test statistics and the corresponding p-values of the McLeod-Li test for ARCH effect. Only available if arch.test = TRUE.
a list of information regarding the prediction of the testing data including `x.test` (part of `x` used for testing), `fitted.test` (predicted values of the testing data), `residuals.test` (prediction error of the testing data), and `error.test` (prediction error measurements based on the testing data). Only available if train.prop is smaller than 1.
a univariate time series or an `tsarima` object.
a specification of the non-seasonal part of the ARIMA model: the three integer components \((p, d, q)\) are the AR order, the degree of differencing, and the MA order.
a specification of the seasonal part of the ARIMA model \((P, D, Q)\), the seasonal AR order, the degree of seasonal differencing, and the seasonal MA order, plus the period (which defaults to frequency(x)). This should be a list with components order and period, but a specification of just a numeric vector of length 3 will be turned into a suitable list with the specification as the order.
optional. A vector or matrix of external regressors, which must have the same number of rows as x.
optional. A vector, list, or numeric value of the external regressors' lags included in the model. If `xreg` has more than one column, the number of values provided in `xreg.order` will be assigned to the columns. the orders should be provided as a list with the entries in the same sequence as the columns in `xreg`. If the number of values does not match the number of columns, the values in `xreg.order` will be trimmed (too many) or repeated (too less). If omitted, no lagged version of `xreg` will be generated. Default is NA.
logical. Indicates if the ARMA model should include a mean/intercept term. The default is TRUE for non-differenced series. For ARIMA models with differencing, it may fail to estimate the standard errors.
optional. A logical value indicating whether the forecasted values are log-transformed and should be inverted back to the original series scale. If the object is an tsarima model and this parameter is omitted, the value will be taken over by the settings of the model given in object. Default is NULL here.
a numerical value specifying the proportion of training data in the series. The value must be between 0 and 1. Default is 1.
optional. A logical value indicating whether the ARCH effect in the residuals should be tested by the McLeod-Li test of not. Default is FALSE.
logical. If TRUE, the AR parameters are transformed to ensure that they remain in the region of stationarity. Not used for method = "CSS". For method = "ML", it has been advantageous to set transform.pars = FALSE in some cases, see also fixed.
optional. Numeric vector of the same length as the total number of coefficients to be estimated. It should be of the form
$$(\phi_1,\ldots,\phi_p,\theta_1,\ldots,\theta_q,\Phi_1,\ldots,\Phi_P,\Theta_1,\ldots,\Theta_Q,\mu)$$
where \(\phi_i\) are the AR coefficients, \(\theta_i\) are the MA coefficients, \(\Phi_i\) are the seasonal AR coefficients, \(\Theta_i\) are the seasonal MA coefficients and \(\mu\) is the intercept term.
Note that the \(\mu\) entry is required if and only if include.const is TRUE. In particular it should not be present if the model is an ARIMA model with differencing.
The entries of the fixed vector should consist of the values at which the user wishes to `fix` the corresponding coefficient, or NA if that coefficient should not be fixed, but estimated.
The argument transform.pars will be set to FALSE if any AR parameters are fixed. A warning will be given if transform.pars is set to (or left at its default) TRUE. It may be wise to set transform.pars = FALSE even when fixing MA parameters, especially at values that cause the model to be nearly non-invertible.
optional. Numeric vector of initial parameter values. Missing values will be filled in, by zeroes except for regression coefficients. Values already specified in fixed will be ignored.
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.
a string specifying the algorithm to compute the state-space initialization of the likelihood; see KalmanLike for details. Can be abbreviated.
The value passed as the method argument to optim.
List of control parameters for optim.
the prior variance (as a multiple of the innovations variance) for the past observations in a differenced model. Do not reduce this.
the number of significant digits.
logical. If TRUE, standard error will be included in displaying the result. Default is TRUE.
logical. If TRUE, a shorthand used to indicate the statistical significance of a result will be displayed next to the p-values with *** for p < 0.001, ** for p < 0.01, * for p < 0.05, and . for p < 0.1. Default is TRUE.
other printing or summary parameters.
a tsarima object for summary.
The exact likelihood is computed via a state-space representation of the ARIMA process, and the innovations and their variance found by a Kalman filter. The initialization of the differenced ARMA process uses stationarity and is based on Gardner et. al. (1980). For a differenced process the non-stationary components are given a diffuse prior (controlled by kappa). Observations which are still controlled by the diffuse prior (determined by having a Kalman gain of at least 1e4) are excluded from the likelihood calculations. (This gives comparable results to arima0 in the absence of missing values, when the observations excluded are precisely those dropped by the differencing.)
Missing values are allowed, and are handled exactly in method `ML`.
If transform.pars is TRUE, the optimisation is done using an alternative parametrization which is a variation on that suggested by Jones (1980) and ensures that the model is stationary. For an AR(p) model the parametrisation is via the inverse tanh of the partial autocorrelations: the same procedure is applied (separately) to the AR and seasonal AR terms. The MA terms are not constrained to be invertible during optimisation, but they will be converted to invertible form after optimisation if transform.pars is TRUE.
Conditional sum-of-squares is provided mainly for expositional purposes. This computes the sum of squares of the fitted innovations from observation n.cond on, (where n.cond is at least the maximum lag of an AR term), treating all earlier innovations to be zero. Argument n.cond can be used to allow comparability between different fits. The `part log-likelihood` is the first term, half the log of the estimated mean square. Missing values are allowed, but will cause many of the innovations to be missing.
When regressors are specified, they are orthogonalised prior to fitting unless any of the coefficients is fixed. It can be helpful to roughly scale the regressors to zero mean and unit variance.
Ka Yui Karl Wu
Different definitions of ARMA models have different signs for the AR and/or MA coefficients. The definition used here is the original Box & Jenkins (1970) formulation:
\(x_t=\phi_1 x_{t-1}+\ldots+\phi_p x_{t-p}+\varepsilon_t-\theta_1\varepsilon_{t-1}-\ldots-\theta_p\varepsilon_{t-q}\)
and so the MA coefficients differ in sign from the output of stats::arima. Further, if include.const is TRUE (the default for an ARMA model), this formula applies to \(x_t-\mu\) rather than \(x_t\). For ARIMA models with differencing, the differenced series usually follows a zero-mean ARMA model, but include.const is still available in case a constant term is required for the model. However, the estimation of the coefficients' standard error may not be successful. If an xreg term is included, a linear regression (with a constant term if include.mean is TRUE and there is no differencing) is fitted with an ARMA model for the error term.
The variance matrix of the estimates is found from the Hessian of the log-likelihood, and so may only be a rough guide.
Optimization is done by optim. It will work best if the columns in xreg are roughly scaled to zero mean and unit variance, but does attempt to estimate suitable scalings.
If train.prop is smaller than 1, the function will only treat the training part of the series as past data. When applying `tsforecast` or `predict`, the forecast will start after the end of the training part of the original series.
Box, G. E. P., & Jenkins, G. M. (1970). Time series analysis: Forecasting and control. Holden-Day.
Hyndman, R. J., & Athanasopoulos, G. (2021). Forecasting: Principles and practice (3rd ed.). OTexts.
https://otexts.com/fpp3/
Hyndman, R. J., Athanasopoulos, G., Bergmeir, C., Caceres, G., Chhay, L., O'Hara-Wild, M., Petropoulos, F., Razbash, S., Wang, E., & Yasmeen, F. (2025). forecast: Forecasting functions for time series and linear models. R package version 8.24.0,
https://pkg.robjhyndman.com/forecast/.
Hyndman, R. J., & Khandakar, Y. (2008). Automatic time series forecasting: the forecast package for R. Journal of Statistical Software, 27(3), 1-22. tools:::Rd_expr_doi("10.18637/jss.v027.i03").
Brockwell, P. J., & Davis, R. A. (1996). Introduction to Time Series and Forecasting. Springer, New York. Sections 3.3 and 8.3.
Durbin, J., & Koopman, S. J. (2001). Time Series Analysis by State Space Methods. Oxford University Press.
Gardner, G, Harvey, A. C., & Phillips, G. D. A. (1980). Algorithm AS 154: An algorithm for exact maximum likelihood estimation of autoregressive-moving average models by means of Kalman filtering. Applied Statistics, 29, 311-322. tools:::Rd_expr_doi("10.2307/2346910").
Harvey, A. C. (1993). Time Series Models. 2nd Edition. Harvester Wheatsheaf. Sections 3.3 and 4.4.
Jones, R. H. (1980). Maximum likelihood fitting of ARMA models to time series with missing observations. Technometrics, 22, 389-395. tools:::Rd_expr_doi("10.2307/1268324").
Ripley, B. D. (2002). Time series in R 1.5.0. R News, 2(2), 2-7. https://www.r-project.org/doc/Rnews/Rnews_2002-2.pdf
tsarima(airport$Travellers,
order = c(1, 1, 0), seasonal = c(0, 1, 1),
log = TRUE, include.const = TRUE)
Run the code above in your browser using DataLab