auto.gdpc {gdpc} | R Documentation |
Automatic Fitting of Generalized Dynamic Principal Components
Description
Computes Generalized Dynamic Principal Components. The number of components can be supplied by the user or chosen automatically so that a given proportion of variance is explained. The number of lags is chosen automatically using one of the following criteria: Leave-one-out cross-validation, an AIC type criterion, a BIC type criterion or a criterion based on a proposal of Bai and Ng (2002). See Peña, Smucler and Yohai (2020) for more details.
Usage
auto.gdpc(Z, crit = 'LOO', normalize = 1, auto_comp = TRUE, expl_var = 0.9,
num_comp = 5, tol = 1e-4, k_max = 10,
niter_max = 500, ncores = 1, verbose = FALSE)
Arguments
Z |
Data matrix. Each column is a different time series. |
crit |
A string specifying the criterion to be used. Options are 'LOO', 'AIC', 'BIC' and 'BNG'. Default is 'LOO'. See Details below. |
normalize |
Integer. Either 1, 2 or 3. Indicates whether the data should be standardized. Default is 1. See Details below. |
auto_comp |
Logical. If TRUE compute components until the proportion of explained variance is equal to expl_var, otherwise use num_comp components. Default is TRUE. |
expl_var |
A number between 0 and 1. Desired proportion of explained variance (only used if auto_comp==TRUE). Default is 0.9. |
num_comp |
Integer. Number of components to be computed (only used if auto_comp==FALSE). Default is 5. |
tol |
Relative precision. Default is 1e-4. |
k_max |
Integer. Maximum possible number of lags. Default is 10. |
niter_max |
Integer. Maximum number of iterations. Default is 500. |
ncores |
Integer. Number of cores to be used for parallel computations. Default is 1. |
verbose |
Logical. Should progress be reported? Default is FALSE. |
Details
Suppose the data matrix consists of series of length
.
Let
be the dynamic principal component defined using
lags, let
be the corresponding matrix of residuals and let
.
If crit = 'LOO' the number of lags is chosen among as the value
that minimizes the leave-one-out (LOO) cross-validation mean squared error, given by
where are the diagonal elements of the hat matrix
, with
being the
matrix with rows
.
If crit = 'AIC' the number of lags is chosen among as the value
that minimizes the following AIC type criterion
If crit = 'BIC' the number of lags is chosen among as the value
that minimizes the following BIC type criterion
If crit = 'BNG' the number of lags is chosen among as the value
that minimizes the following criterion
This is an adaptation of a criterion proposed by Bai and Ng (2002).
For problems of relatively small dimension, say , 'AIC' can can give better results than the
default 'LOO'.
If normalize = 1, the data is analyzed in the original units, without mean and variance standarization. If normalize = 2, the data is standardized to zero mean and unit variance before computing the principal components, but the intercepts and loadings are those needed to reconstruct the original series. If normalize = 3 the data are standardized as in normalize = 2, but the intercepts and the loadings are those needed to reconstruct the standardized series. Default is normalize = 1.
Value
An object of class gdpcs
, that is, a list of length equal to the number of computed components. The i-th entry of this list is an object of class gdpc
, that is, a list with entries
expart |
Proportion of the variance explained by the first i components. |
mse |
Mean squared error of the reconstruction using the first i components. |
crit |
The value of the criterion of the reconstruction, according to what the user specified. |
k |
Number of lags chosen. |
alpha |
Vector of intercepts corresponding to f. |
beta |
Matrix of loadings corresponding to f. Column number |
f |
Coordinates of the i-th dynamic principal component corresponding to the periods |
initial_f |
Coordinates of the i-th dynamic principal component corresponding to the periods |
call |
The matched call. |
conv |
Logical. Did the iterations converge? |
niter |
Integer. Number of iterations. |
components
, fitted
, plot
and print
methods are available for this class.
Author(s)
Daniel Peña, Ezequiel Smucler, Victor Yohai
References
Bai J. and Ng S. (2002). “Determining the Number of Factors in Approximate Factor Models.” Econometrica, 70(1), 191–221.
Peña D., Smucler E. and Yohai V.J. (2020). “gdpc: An R Package for Generalized Dynamic Principal Components.” Journal of Statistical Software, 92(2), 1-23.
See Also
gdpc
, plot.gdpc
, plot.gdpcs
, fitted.gdpcs
, components.gdpcs
Examples
T <- 200 #length of series
m <- 200 #number of series
set.seed(1234)
f <- rnorm(T + 1)
x <- matrix(0, T, m)
u <- matrix(rnorm(T * m), T, m)
for (i in 1:m) {
x[, i] <- 10 * sin(2 * pi * (i/m)) * f[1:T] + 10 * cos(2 * pi * (i/m)) * f[2:(T + 1)] + u[, i]
}
#Choose number of lags using the LOO criterion.
#k_max=3 to keep computation time low
autofit <- auto.gdpc(x, k_max = 3)
autofit
fit_val <- fitted(autofit, 1) #Get fitted values
resid <- x - fit_val #Residuals
plot(autofit, which_comp = 1) #Plot component