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.
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)
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
Proportion of the variance explained by the first i components.
Mean squared error of the reconstruction using the first i components.
The value of the criterion of the reconstruction, according to what the user specified.
Number of lags chosen.
Vector of intercepts corresponding to f.
Matrix of loadings corresponding to f. Column number \(k\) is the vector of \(k-1\) lag loadings.
Coordinates of the i-th dynamic principal component corresponding to the periods \(1,\dots,T\).
Coordinates of the i-th dynamic principal component corresponding to the periods \(-k+1,\dots,0\). Only for the case \(k>0\), otherwise 0.
The matched call.
Logical. Did the iterations converge?
Integer. Number of iterations.
components
, fitted
, plot
and print
methods are available for this class.
Data matrix. Each column is a different time series.
A string specifying the criterion to be used. Options are 'LOO', 'AIC', 'BIC' and 'BNG'. Default is 'LOO'. See Details below.
Integer. Either 1, 2 or 3. Indicates whether the data should be standardized. Default is 1. See Details below.
Logical. If TRUE compute components until the proportion of explained variance is equal to expl_var, otherwise use num_comp components. Default is TRUE.
A number between 0 and 1. Desired proportion of explained variance (only used if auto_comp==TRUE). Default is 0.9.
Integer. Number of components to be computed (only used if auto_comp==FALSE). Default is 5.
Relative precision. Default is 1e-4.
Integer. Maximum possible number of lags. Default is 10.
Integer. Maximum number of iterations. Default is 500.
Integer. Number of cores to be used for parallel computations. Default is 1.
Logical. Should progress be reported? Default is FALSE.
Daniel Peña, Ezequiel Smucler, Victor Yohai
Suppose the data matrix consists of \(m\) series of length \(T\). Let \(\bold{f}\) be the dynamic principal component defined using \(k\) lags, let \(R\) be the corresponding matrix of residuals and let \(\Sigma = (R^{\prime} R) / T\).
If crit = 'LOO' the number of lags is chosen among \(0,\dots, k_{max}\) as the value \(k\) that minimizes the leave-one-out (LOO) cross-validation mean squared error, given by $$ LOO = \frac{1}{T m}\sum\limits_{i=1}^{m}\sum\limits_{t=1}^{T}\frac{R_{t,i}^{2}}{(1-h_{t,t})^{2}},$$ where \(h_{t,t}\) are the diagonal elements of the hat matrix \(H = F(F^{\prime} F)^{-1} F^{\prime} \), with \(F\) being the \(T \times (k+2)\) matrix with rows \((f_{t-k}, f_{t-k+1}, \dots, f_{t}, 1)\).
If crit = 'AIC' the number of lags is chosen among \(0,\dots, k_{max}\) as the value \(k\) that minimizes the following AIC type criterion $$ AIC = T \log(trace(\Sigma)) + 2 m (k+2) .$$
If crit = 'BIC' the number of lags is chosen among \(0,\dots, k_{max}\) as the value \(k\) that minimizes the following BIC type criterion $$ BIC = T \log(trace(\Sigma)) + m (k+2) \log(T) .$$
If crit = 'BNG' the number of lags is chosen among \(0,\dots, k_{max}\) as the value \(k\) that minimizes the following criterion $$ BNG = \min(T, m) \log(trace(\Sigma)) + (k+1) \log(\min(T, m)).$$ This is an adaptation of a criterion proposed by Bai and Ng (2002).
For problems of relatively small dimension, say \(T \geq m 10\), '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.
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.
gdpc
, plot.gdpc
, plot.gdpcs
, fitted.gdpcs
, components.gdpcs
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
Run the code above in your browser using DataLab