Skip to contents

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)

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.

Value

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

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

Author

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

Examples


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

##create regressors (examples):
regressorsMean(y, mxreg=x)
#>              y      mxreg1     mxreg2      mxreg3     mxreg4     mxreg5
#> 1   1.25416787  1.46997845 -1.5801205 -0.46808644  1.3654882  1.7657239
#> 2   1.84371542  0.11882472 -0.3937083 -0.49073909 -0.9148793  1.0738832
#> 3   0.93173603  0.45574257  0.8794478 -1.27397411  1.4078254 -0.3441977
#> 4  -0.86357664  0.75439623 -0.4293480 -1.44569311 -1.2659095  0.5354364
#> 5  -0.98729366 -0.03665632  1.8174858 -0.32953481 -0.6776105 -1.3271364
#> 6  -0.04148188  0.06776830  1.7839376  0.08334871  0.6678258  1.3716810
#> 7  -1.02505398 -2.57267355 -1.0502001 -0.09801576  0.2394278  0.3285052
#> 8  -1.07696951 -0.63668837 -0.4884562 -0.78468636 -0.5226493  0.4018755
#> 9   0.92930845 -0.67702521  1.4318177 -0.68567176 -1.4594364  0.6088788
#> 10 -0.24258145 -1.28738037  1.3931588 -0.92063615  0.5670741  0.2137858
regressorsMean(y, mxreg=x, return.regressand=FALSE)
#>         mxreg1     mxreg2      mxreg3     mxreg4     mxreg5
#> 1   1.46997845 -1.5801205 -0.46808644  1.3654882  1.7657239
#> 2   0.11882472 -0.3937083 -0.49073909 -0.9148793  1.0738832
#> 3   0.45574257  0.8794478 -1.27397411  1.4078254 -0.3441977
#> 4   0.75439623 -0.4293480 -1.44569311 -1.2659095  0.5354364
#> 5  -0.03665632  1.8174858 -0.32953481 -0.6776105 -1.3271364
#> 6   0.06776830  1.7839376  0.08334871  0.6678258  1.3716810
#> 7  -2.57267355 -1.0502001 -0.09801576  0.2394278  0.3285052
#> 8  -0.63668837 -0.4884562 -0.78468636 -0.5226493  0.4018755
#> 9  -0.67702521  1.4318177 -0.68567176 -1.4594364  0.6088788
#> 10 -1.28738037  1.3931588 -0.92063615  0.5670741  0.2137858
regressorsMean(y, mc=TRUE, ar=1:3, mxreg=x)
#>              y mconst         ar1         ar2         ar3      mxreg1
#> 4  -0.86357664      1  0.93173603  1.84371542  1.25416787  0.75439623
#> 5  -0.98729366      1 -0.86357664  0.93173603  1.84371542 -0.03665632
#> 6  -0.04148188      1 -0.98729366 -0.86357664  0.93173603  0.06776830
#> 7  -1.02505398      1 -0.04148188 -0.98729366 -0.86357664 -2.57267355
#> 8  -1.07696951      1 -1.02505398 -0.04148188 -0.98729366 -0.63668837
#> 9   0.92930845      1 -1.07696951 -1.02505398 -0.04148188 -0.67702521
#> 10 -0.24258145      1  0.92930845 -1.07696951 -1.02505398 -1.28738037
#>        mxreg2      mxreg3     mxreg4     mxreg5
#> 4  -0.4293480 -1.44569311 -1.2659095  0.5354364
#> 5   1.8174858 -0.32953481 -0.6776105 -1.3271364
#> 6   1.7839376  0.08334871  0.6678258  1.3716810
#> 7  -1.0502001 -0.09801576  0.2394278  0.3285052
#> 8  -0.4884562 -0.78468636 -0.5226493  0.4018755
#> 9   1.4318177 -0.68567176 -1.4594364  0.6088788
#> 10  1.3931588 -0.92063615  0.5670741  0.2137858
regressorsMean(log(y^2), mc=TRUE, ar=c(2,4))
#>       log(y^2) mconst         ar2         ar4
#> 5  -0.02557551      1 -0.14141147  0.45294460
#> 6  -6.36499736      1 -0.29334527  1.22356557
#> 7   0.04949054      1 -0.02557551 -0.14141147
#> 8   0.14830218      1 -6.36499736 -0.29334527
#> 9  -0.14662914      1  0.04949054 -0.02557551
#> 10 -2.83283552      1  0.14830218 -6.36499736

##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)
#>                   y    Series 1   Series 2    Series 3   Series 4   Series 5
#> 2016 Q3  1.25416787  1.46997845 -1.5801205 -0.46808644  1.3654882  1.7657239
#> 2016 Q4  1.84371542  0.11882472 -0.3937083 -0.49073909 -0.9148793  1.0738832
#> 2017 Q1  0.93173603  0.45574257  0.8794478 -1.27397411  1.4078254 -0.3441977
#> 2017 Q2 -0.86357664  0.75439623 -0.4293480 -1.44569311 -1.2659095  0.5354364
#> 2017 Q3 -0.98729366 -0.03665632  1.8174858 -0.32953481 -0.6776105 -1.3271364
#> 2017 Q4 -0.04148188  0.06776830  1.7839376  0.08334871  0.6678258  1.3716810
#> 2018 Q1 -1.02505398 -2.57267355 -1.0502001 -0.09801576  0.2394278  0.3285052
#> 2018 Q2 -1.07696951 -0.63668837 -0.4884562 -0.78468636 -0.5226493  0.4018755
#> 2018 Q3  0.92930845 -0.67702521  1.4318177 -0.68567176 -1.4594364  0.6088788
#> 2018 Q4 -0.24258145 -1.28738037  1.3931588 -0.92063615  0.5670741  0.2137858
regressorsMean(y, mc=TRUE, ar=1:3, mxreg=x)
#>                   y mconst         ar1         ar2         ar3    Series 1
#> 2017 Q2 -0.86357664      1  0.93173603  1.84371542  1.25416787  0.75439623
#> 2017 Q3 -0.98729366      1 -0.86357664  0.93173603  1.84371542 -0.03665632
#> 2017 Q4 -0.04148188      1 -0.98729366 -0.86357664  0.93173603  0.06776830
#> 2018 Q1 -1.02505398      1 -0.04148188 -0.98729366 -0.86357664 -2.57267355
#> 2018 Q2 -1.07696951      1 -1.02505398 -0.04148188 -0.98729366 -0.63668837
#> 2018 Q3  0.92930845      1 -1.07696951 -1.02505398 -0.04148188 -0.67702521
#> 2018 Q4 -0.24258145      1  0.92930845 -1.07696951 -1.02505398 -1.28738037
#>           Series 2    Series 3   Series 4   Series 5
#> 2017 Q2 -0.4293480 -1.44569311 -1.2659095  0.5354364
#> 2017 Q3  1.8174858 -0.32953481 -0.6776105 -1.3271364
#> 2017 Q4  1.7839376  0.08334871  0.6678258  1.3716810
#> 2018 Q1 -1.0502001 -0.09801576  0.2394278  0.3285052
#> 2018 Q2 -0.4884562 -0.78468636 -0.5226493  0.4018755
#> 2018 Q3  1.4318177 -0.68567176 -1.4594364  0.6088788
#> 2018 Q4  1.3931588 -0.92063615  0.5670741  0.2137858
regressorsMean(log(y^2), mc=TRUE, ar=c(2,4))
#>            log(y^2) mconst         ar2         ar4
#> 2017 Q3 -0.02557551      1 -0.14141147  0.45294460
#> 2017 Q4 -6.36499736      1 -0.29334527  1.22356557
#> 2018 Q1  0.04949054      1 -0.02557551 -0.14141147
#> 2018 Q2  0.14830218      1 -6.36499736 -0.29334527
#> 2018 Q3 -0.14662914      1  0.04949054 -0.02557551
#> 2018 Q4 -2.83283552      1  0.14830218 -6.36499736

##missing values (NA):
y[1] <- NA
x[10,3] <- NA
regressorsMean(y, mxreg=x)
#>                   y    Series 1   Series 2    Series 3   Series 4   Series 5
#> 2016 Q4  1.84371542  0.11882472 -0.3937083 -0.49073909 -0.9148793  1.0738832
#> 2017 Q1  0.93173603  0.45574257  0.8794478 -1.27397411  1.4078254 -0.3441977
#> 2017 Q2 -0.86357664  0.75439623 -0.4293480 -1.44569311 -1.2659095  0.5354364
#> 2017 Q3 -0.98729366 -0.03665632  1.8174858 -0.32953481 -0.6776105 -1.3271364
#> 2017 Q4 -0.04148188  0.06776830  1.7839376  0.08334871  0.6678258  1.3716810
#> 2018 Q1 -1.02505398 -2.57267355 -1.0502001 -0.09801576  0.2394278  0.3285052
#> 2018 Q2 -1.07696951 -0.63668837 -0.4884562 -0.78468636 -0.5226493  0.4018755
#> 2018 Q3  0.92930845 -0.67702521  1.4318177 -0.68567176 -1.4594364  0.6088788
regressorsMean(y, mxreg=x, na.trim=FALSE)
#>                   y    Series 1   Series 2    Series 3   Series 4   Series 5
#> 2016 Q3          NA  1.46997845 -1.5801205 -0.46808644  1.3654882  1.7657239
#> 2016 Q4  1.84371542  0.11882472 -0.3937083 -0.49073909 -0.9148793  1.0738832
#> 2017 Q1  0.93173603  0.45574257  0.8794478 -1.27397411  1.4078254 -0.3441977
#> 2017 Q2 -0.86357664  0.75439623 -0.4293480 -1.44569311 -1.2659095  0.5354364
#> 2017 Q3 -0.98729366 -0.03665632  1.8174858 -0.32953481 -0.6776105 -1.3271364
#> 2017 Q4 -0.04148188  0.06776830  1.7839376  0.08334871  0.6678258  1.3716810
#> 2018 Q1 -1.02505398 -2.57267355 -1.0502001 -0.09801576  0.2394278  0.3285052
#> 2018 Q2 -1.07696951 -0.63668837 -0.4884562 -0.78468636 -0.5226493  0.4018755
#> 2018 Q3  0.92930845 -0.67702521  1.4318177 -0.68567176 -1.4594364  0.6088788
#> 2018 Q4 -0.24258145 -1.28738037  1.3931588          NA  0.5670741  0.2137858