Create the regressors of the mean equation
regressorsMean.Rd
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, whereasFALSE
(default) does not.- ar
either
NULL
(default) or an integer vector, say,c(2,4)
or1:4
with the AR-lags to include in the mean specification. IfNULL
, then no lags are included.- ewma
either
NULL
(default) or alist
with arguments sent to theeqwma
function. In the latter case a lagged moving average ofy
is included as a regressor.- mxreg
either
NULL
(default), numeric vector or matrix, say, azoo
object, ordata.frame
containing conditioning variables (covariates). Note that, if bothy
andmxreg
arezoo
objects, then their samples are matched.- prefix
character, possibly of length zero, e.g.
""
orcharacter(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 azoo
object.- na.trim
TRUE
, the default, removes observations withNA
-values in the beginning and the end withna.trim
.- na.omit
TRUE
, the non-default, removes observations withNA
-values, not necessarily in the beginning or in the end, withna.omit
.
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/
See also
arx
, isat
, regressorsVariance
, zoo
, eqwma
, na.trim
and na.trim
.
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 -2.0376825 -0.321892586 0.474911714 -1.8863252 0.23111493 0.2763155
#> 2 -0.1958892 1.487837832 -0.279072171 -0.6537798 0.64751336 -0.1582940
#> 3 0.5397906 -1.667928046 0.813400374 0.3943948 0.35628334 -2.5079178
#> 4 0.6164557 -0.436829977 0.904435464 -0.9135660 -0.65801021 -1.5652818
#> 5 0.6165678 0.457462079 0.002691661 0.8867490 0.85520221 -0.0776732
#> 6 -1.6921015 -1.617773765 -1.176692158 0.3333700 1.15293623 0.2062940
#> 7 0.3687421 0.279627862 -1.318220727 -0.1706396 0.27627456 0.2768725
#> 8 0.9678592 1.877864021 -0.592997366 0.8188281 0.14410466 0.8215068
#> 9 1.2765787 -0.004060653 0.797380501 0.3883652 -0.07562508 -0.1941524
#> 10 -0.2249613 -0.278454025 -1.958205175 -0.4459350 2.16141585 1.2145888
regressorsMean(y, mxreg=x, return.regressand=FALSE)
#> mxreg1 mxreg2 mxreg3 mxreg4 mxreg5
#> 1 -0.321892586 0.474911714 -1.8863252 0.23111493 0.2763155
#> 2 1.487837832 -0.279072171 -0.6537798 0.64751336 -0.1582940
#> 3 -1.667928046 0.813400374 0.3943948 0.35628334 -2.5079178
#> 4 -0.436829977 0.904435464 -0.9135660 -0.65801021 -1.5652818
#> 5 0.457462079 0.002691661 0.8867490 0.85520221 -0.0776732
#> 6 -1.617773765 -1.176692158 0.3333700 1.15293623 0.2062940
#> 7 0.279627862 -1.318220727 -0.1706396 0.27627456 0.2768725
#> 8 1.877864021 -0.592997366 0.8188281 0.14410466 0.8215068
#> 9 -0.004060653 0.797380501 0.3883652 -0.07562508 -0.1941524
#> 10 -0.278454025 -1.958205175 -0.4459350 2.16141585 1.2145888
regressorsMean(y, mc=TRUE, ar=1:3, mxreg=x)
#> y mconst ar1 ar2 ar3 mxreg1 mxreg2
#> 4 0.6164557 1 0.5397906 -0.1958892 -2.0376825 -0.436829977 0.904435464
#> 5 0.6165678 1 0.6164557 0.5397906 -0.1958892 0.457462079 0.002691661
#> 6 -1.6921015 1 0.6165678 0.6164557 0.5397906 -1.617773765 -1.176692158
#> 7 0.3687421 1 -1.6921015 0.6165678 0.6164557 0.279627862 -1.318220727
#> 8 0.9678592 1 0.3687421 -1.6921015 0.6165678 1.877864021 -0.592997366
#> 9 1.2765787 1 0.9678592 0.3687421 -1.6921015 -0.004060653 0.797380501
#> 10 -0.2249613 1 1.2765787 0.9678592 0.3687421 -0.278454025 -1.958205175
#> mxreg3 mxreg4 mxreg5
#> 4 -0.9135660 -0.65801021 -1.5652818
#> 5 0.8867490 0.85520221 -0.0776732
#> 6 0.3333700 1.15293623 0.2062940
#> 7 -0.1706396 0.27627456 0.2768725
#> 8 0.8188281 0.14410466 0.8215068
#> 9 0.3883652 -0.07562508 -0.1941524
#> 10 -0.4459350 2.16141585 1.2145888
regressorsMean(log(y^2), mc=TRUE, ar=c(2,4))
#> log(y^2) mconst ar2 ar4
#> 5 -0.96717392 1 -1.23314796 1.4236263
#> 6 1.05194252 1 -0.96753758 -3.2604117
#> 7 -1.99531582 1 -0.96717392 -1.2331480
#> 8 -0.06533729 1 1.05194252 -0.9675376
#> 9 0.48836719 1 -1.99531582 -0.9671739
#> 10 -2.98365404 1 -0.06533729 1.0519425
##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 -2.0376825 -0.321892586 0.474911714 -1.8863252 0.23111493 0.2763155
#> 2016 Q4 -0.1958892 1.487837832 -0.279072171 -0.6537798 0.64751336 -0.1582940
#> 2017 Q1 0.5397906 -1.667928046 0.813400374 0.3943948 0.35628334 -2.5079178
#> 2017 Q2 0.6164557 -0.436829977 0.904435464 -0.9135660 -0.65801021 -1.5652818
#> 2017 Q3 0.6165678 0.457462079 0.002691661 0.8867490 0.85520221 -0.0776732
#> 2017 Q4 -1.6921015 -1.617773765 -1.176692158 0.3333700 1.15293623 0.2062940
#> 2018 Q1 0.3687421 0.279627862 -1.318220727 -0.1706396 0.27627456 0.2768725
#> 2018 Q2 0.9678592 1.877864021 -0.592997366 0.8188281 0.14410466 0.8215068
#> 2018 Q3 1.2765787 -0.004060653 0.797380501 0.3883652 -0.07562508 -0.1941524
#> 2018 Q4 -0.2249613 -0.278454025 -1.958205175 -0.4459350 2.16141585 1.2145888
regressorsMean(y, mc=TRUE, ar=1:3, mxreg=x)
#> y mconst ar1 ar2 ar3 Series 1
#> 2017 Q2 0.6164557 1 0.5397906 -0.1958892 -2.0376825 -0.436829977
#> 2017 Q3 0.6165678 1 0.6164557 0.5397906 -0.1958892 0.457462079
#> 2017 Q4 -1.6921015 1 0.6165678 0.6164557 0.5397906 -1.617773765
#> 2018 Q1 0.3687421 1 -1.6921015 0.6165678 0.6164557 0.279627862
#> 2018 Q2 0.9678592 1 0.3687421 -1.6921015 0.6165678 1.877864021
#> 2018 Q3 1.2765787 1 0.9678592 0.3687421 -1.6921015 -0.004060653
#> 2018 Q4 -0.2249613 1 1.2765787 0.9678592 0.3687421 -0.278454025
#> Series 2 Series 3 Series 4 Series 5
#> 2017 Q2 0.904435464 -0.9135660 -0.65801021 -1.5652818
#> 2017 Q3 0.002691661 0.8867490 0.85520221 -0.0776732
#> 2017 Q4 -1.176692158 0.3333700 1.15293623 0.2062940
#> 2018 Q1 -1.318220727 -0.1706396 0.27627456 0.2768725
#> 2018 Q2 -0.592997366 0.8188281 0.14410466 0.8215068
#> 2018 Q3 0.797380501 0.3883652 -0.07562508 -0.1941524
#> 2018 Q4 -1.958205175 -0.4459350 2.16141585 1.2145888
regressorsMean(log(y^2), mc=TRUE, ar=c(2,4))
#> log(y^2) mconst ar2 ar4
#> 2017 Q3 -0.96717392 1 -1.23314796 1.4236263
#> 2017 Q4 1.05194252 1 -0.96753758 -3.2604117
#> 2018 Q1 -1.99531582 1 -0.96717392 -1.2331480
#> 2018 Q2 -0.06533729 1 1.05194252 -0.9675376
#> 2018 Q3 0.48836719 1 -1.99531582 -0.9671739
#> 2018 Q4 -2.98365404 1 -0.06533729 1.0519425
##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 -0.1958892 1.487837832 -0.279072171 -0.6537798 0.64751336 -0.1582940
#> 2017 Q1 0.5397906 -1.667928046 0.813400374 0.3943948 0.35628334 -2.5079178
#> 2017 Q2 0.6164557 -0.436829977 0.904435464 -0.9135660 -0.65801021 -1.5652818
#> 2017 Q3 0.6165678 0.457462079 0.002691661 0.8867490 0.85520221 -0.0776732
#> 2017 Q4 -1.6921015 -1.617773765 -1.176692158 0.3333700 1.15293623 0.2062940
#> 2018 Q1 0.3687421 0.279627862 -1.318220727 -0.1706396 0.27627456 0.2768725
#> 2018 Q2 0.9678592 1.877864021 -0.592997366 0.8188281 0.14410466 0.8215068
#> 2018 Q3 1.2765787 -0.004060653 0.797380501 0.3883652 -0.07562508 -0.1941524
regressorsMean(y, mxreg=x, na.trim=FALSE)
#> y Series 1 Series 2 Series 3 Series 4 Series 5
#> 2016 Q3 NA -0.321892586 0.474911714 -1.8863252 0.23111493 0.2763155
#> 2016 Q4 -0.1958892 1.487837832 -0.279072171 -0.6537798 0.64751336 -0.1582940
#> 2017 Q1 0.5397906 -1.667928046 0.813400374 0.3943948 0.35628334 -2.5079178
#> 2017 Q2 0.6164557 -0.436829977 0.904435464 -0.9135660 -0.65801021 -1.5652818
#> 2017 Q3 0.6165678 0.457462079 0.002691661 0.8867490 0.85520221 -0.0776732
#> 2017 Q4 -1.6921015 -1.617773765 -1.176692158 0.3333700 1.15293623 0.2062940
#> 2018 Q1 0.3687421 0.279627862 -1.318220727 -0.1706396 0.27627456 0.2768725
#> 2018 Q2 0.9678592 1.877864021 -0.592997366 0.8188281 0.14410466 0.8215068
#> 2018 Q3 1.2765787 -0.004060653 0.797380501 0.3883652 -0.07562508 -0.1941524
#> 2018 Q4 -0.2249613 -0.278454025 -1.958205175 NA 2.16141585 1.2145888