Learn R Programming

gets (version 0.38)

regressorsMean: Create the regressors of the mean equation

Description

The function generates the regressors of the mean equation in an arx model. The returned value is a matrix with the regressors and, by default, the regressand in column one. By default, observations (rows) with missing values are removed in the beginning and the end with na.trim, and the returned matrix is a zoo object.

Usage

regressorsMean(y, mc = FALSE, ar = NULL, ewma = NULL, mxreg = NULL,
  prefix="m", return.regressand = TRUE, return.as.zoo = TRUE, na.trim = TRUE,
  na.omit=FALSE)

Value

A matrix, by default of class zoo, with the regressand as column one (the default).

Arguments

y

numeric vector, time-series or zoo object.

mc

logical. TRUE includes an intercept, whereas FALSE (default) does not.

ar

either NULL (default) or an integer vector, say, c(2,4) or 1:4 with the AR-lags to include in the mean specification. If NULL, then no lags are included.

ewma

either NULL (default) or a list with arguments sent to the eqwma function. In the latter case a lagged moving average of y is included as a regressor.

mxreg

either NULL (default), numeric vector or matrix, say, a zoo object, or data.frame containing conditioning variables (covariates). Note that, if both y and mxreg are zoo objects, then their samples are matched.

prefix

character, possibly of length zero, e.g. "" or character(0). The prefix added to the constant and covariate labels. The default is "m", so that the default labels are "mconst" and "mxreg".

return.regressand

logical. TRUE, the default, includes the regressand as column one in the returned matrix.

return.as.zoo

TRUE, the default, returns the matrix as a zoo object.

na.trim

TRUE, the default, removes observations with NA-values in the beginning and the end with na.trim.

na.omit

TRUE, the non-default, removes observations with NA-values, not necessarily in the beginning or in the end, with na.omit.

Author

Genaro Sucarrat, http://www.sucarrat.net/

References

Pretis, Felix, Reade, James and Sucarrat, Genaro (2018): 'Automated General-to-Specific (GETS) Regression Modeling and Indicator Saturation for Outliers and Structural Breaks'. Journal of Statistical Software 86, Number 3, pp. 1-44. DOI: https://www.jstatsoft.org/article/view/v086i03

See Also

arx, isat, regressorsVariance, zoo, eqwma, na.trim and na.trim.

Examples

Run this code

##generate some data:
y <- rnorm(10) #regressand
x <- matrix(rnorm(10*5), 10, 5) #regressors

##create regressors (examples):
regressorsMean(y, mxreg=x)
regressorsMean(y, mxreg=x, return.regressand=FALSE)
regressorsMean(y, mc=TRUE, ar=1:3, mxreg=x)
regressorsMean(log(y^2), mc=TRUE, ar=c(2,4))

##let y and x be time-series:
y <- ts(y, frequency=4, end=c(2018,4))
x <- ts(x, frequency=4, end=c(2018,4))
regressorsMean(y, mxreg=x)
regressorsMean(y, mc=TRUE, ar=1:3, mxreg=x)
regressorsMean(log(y^2), mc=TRUE, ar=c(2,4))

##missing values (NA):
y[1] <- NA
x[10,3] <- NA
regressorsMean(y, mxreg=x)
regressorsMean(y, mxreg=x, na.trim=FALSE)

Run the code above in your browser using DataLab