Learn R Programming

astsa (version 2.3)

sarima: Fit ARIMA Models

Description

Fits ARIMA models (with diagnostics) in a short command. It can also be used to perform regression with autocorrelated errors.

Usage

sarima(xdata, p, d, q, P = 0, D = 0, Q = 0, S = -1, 
       details = TRUE, xreg = NULL, Model = TRUE,
       fixed = NULL, tol = sqrt(.Machine$double.eps), 
       no.constant = FALSE, col, ...)

Value

A t-table, the estimated noise variance, and AIC, AICc, BIC are printed. The following are returned invisibly as a list:

fit

[[1]] an object of class Arima with more information than you need

sigma2

[[2]] the estimate of the noise variance

degrees_of_freedom

[[3]] error degrees of freedom

t.table

[[4]] a little t-table with two-sided p-values

ICs

[[5]] AIC - AICc - BIC

Arguments

xdata

univariate time series

p

AR order

d

difference order

q

MA order

P

SAR order; use only for seasonal models

D

seasonal difference; use only for seasonal models

Q

SMA order; use only for seasonal models

S

seasonal period; use only for seasonal models

details

if FALSE, turns off the diagnostic plot and the output from the nonlinear optimization routine, which is optim. The default is TRUE.

xreg

Optionally, a vector or matrix of external regressors, which must have the same number of rows as xdata.

Model

if TRUE (default), the model orders are printed on the diagnostic plot.

fixed

optional numeric vector of the same length as the total number of parameters. If supplied, only parameters corresponding to NA entries will be estimated.

tol

controls the relative tolerance (reltol in optim) used to assess convergence. The default is sqrt(.Machine$double.eps), the R default.

no.constant

controls whether or not sarima includes a constant in the model. In particular, if there is no differencing (d = 0 and D = 0) you get the mean estimate. If there is differencing of order one (either d = 1 or D = 1, but not both), a constant term is included in the model. These two conditions may be overridden (i.e., no constant will be included in the model) by setting this to TRUE; e.g., sarima(x,1,1,0,no.constant=TRUE). Otherwise, no constant or mean term is included in the model. If regressors are included (via xreg), this is ignored.

col

color of diagnostic plots; default is 1 (black)

...

additional graphical arguments

Missing Data

Yes it's ok if input as NA and the observations are vector or ts objects (meaning equally spaced).

Details

If your time series is in x and you want to fit an ARIMA(p,d,q) model to the data, the basic call is sarima(x,p,d,q). As of version 2.3, the orders do not have to be specified if they are zero. For example, sarima(x, p=1) is the same as sarima(x,1,0,0).

To fit a seasonal ARIMA model, the basic call is sarima(x,p,d,q,P,D,Q,S). For example, sarima(x, 2,1,0, 0,1,1,12) will fit a seasonal ARIMA\((2,1,0) \times (0,1,1)_{12}\) model to the series in x. The orders do not have to be specified if they are zero; e.g., sarima(x, d=1,q=1, D=1,Q=1,S=4) works.

The results are the parameter estimates, standard errors, AIC, AICc, BIC and diagnostics. The difference between the information criteria given by sarima() and arima() is that they differ by a scaling factor of the effective sample size.

References

You can find demonstrations of astsa capabilities at FUN WITH ASTSA.

The most recent version of the package can be found at https://github.com/nickpoison/astsa/.

In addition, the News and ChangeLog files are at https://github.com/nickpoison/astsa/blob/master/NEWS.md.

The webpages for the texts and some help on using R for time series analysis can be found at https://nickpoison.github.io/.

See Also

sarima.for, sarima.sim

Examples

Run this code

# easy to use 
sarima(rec, 2,0,0)  # data, p, d, and q
# redux - minimal output
sarima(rec, p=2, details=FALSE)

# fun for the whole family
dog = sarima(log(AirPassengers), 0,1,1, 0,1,1,12, details=FALSE)
# dog[[1]] has most of the results ...
tsplot(resid(dog[[1]]))


# fixed parameters
x = sarima.sim( ar=c(0,-.9), n=200 ) + 50 
sarima(x, p=2, fixed=c(0,NA,NA))  # phi1 fixed, phi2 and mean free

# regression with autocorrelated errors  
sarima(log(cpg), p=1, xreg=time(cpg))

# missing data (color, gris-gris, and pch, added for fun)
sarima(ar1miss, p=1, col=4, gg=TRUE, pch=19)

Run the code above in your browser using DataLab