stepar {aTSA} R Documentation

## Stepwise Autoregressive Model

### Description

Fit a stepwise autoregressive model

### Usage

```stepar(y, xreg = NULL, trend = c("linear", "quadratic", "constant"),
order = NULL, lead = 0, newx = NULL, output = TRUE, ...)
```

### Arguments

 `y` a numeric vector of response `xreg` a numeric vector or matrix of exogenous input variables. The default is `NULL`. `trend` the type of trend with respective to time. The default is `linear`. `order` the order to fit the AR model for residuals. The default is `NULL`. `lead` the number of steps ahead for which prediction is required. The default is `0`. `newx` a matrix of new data of `xreg` for predictions. The default is `NULL`. `output` a logical value indicating to print the results in R console. The default is `NULL`. `...` additional arguments for `ar` function.

### Details

The stewise autoregressive model uses a two-stage procedure to fit time series. The first stage is to fit a (`constant`,`linear`,`quadratic`) model with respective to time sequence: t = (1:n)/n, where n = length(y). If `xreg` is supplied, the fitted model is updated by

y = μ + β*xreg + e[t]

for `trend = "constant"`, and

y = μ + β*xreg + α*t + e[t]

for `trend = "linear"`, and

y = μ + β*xreg + α*t + α*t^2 + e[t]

for `trend = "quadratic"`. The second stage is to fit an autoregressive process to the residuals of the fitted model obtained in the first stage, which is accomplished by using `ar` function in `stats` package.

### Value

A list with class "`stepar`" containing the following components:

 `coef` a estimated coefficient matrix including the t-test results. `sigma` the square root of the estimated variance of the random error. `R.squared` the R^2 for fitted model in the first stage. `pred` the predictions, only available for `lead` > 0.

### Note

If `lead` > 0 and `xreg` is supplied, `newx` must also be supplied in order to make a prediction. The `newx` must be a matrix with the same number of columns as `xreg` and the number of rows being equal to `lead`. The predictions should be used with cautions.

Debin Qiu

### Examples

```x <- 5*(1:100)/100
x <- x + arima.sim(list(order = c(1,0,0),ar = 0.4),n = 100)
stepar(x)
stepar(x,order = 1)

# with xreg supplied
X <- matrix(rnorm(200),100,2)
y <- 0.1*X[,1] + 1.2*X[,2] + rnorm(100)
stepar(y,X)
# make a prediction with lead = 1; used with caution.
newdat1 <- matrix(rnorm(2),nrow = 1)
fit1 <- stepar(y,X,lead = 1,newx = newdat1,output = FALSE)
# make a prediction with lead = 2; used with caution.
newdat2 <- matrix(rnorm(4),nrow = 2)
fit2 <- stepar(y,X,lead = 2,newx = newdat2,output = FALSE)
```

[Package aTSA version 3.1.2 Index]