Title: | Dynamic Principal Components for Periodically Correlated Functional Time Series |
---|---|
Description: | Method extends multivariate and functional dynamic principal components to periodically correlated multivariate time series. This package allows you to compute true dynamic principal components in the presence of periodicity. We follow implementation guidelines as described in Kidzinski, Kokoszka and Jouzdani (2017), in Principal component analysis of periodically correlated functional time series <arXiv:1612.00040>. |
Authors: | Lukasz Kidzinski [aut, cre], Neda Jouzdani [aut], Piotr Kokoszka [aut] |
Maintainer: | Lukasz Kidzinski <[email protected]> |
License: | GPL-3 |
Version: | 0.4 |
Built: | 2024-11-17 06:48:58 UTC |
Source: | CRAN |
For a given periodically correlated multivariate process X
eigendecompose it's spectral density
and use an inverse fourier transform to get coefficients of the optimal filters.
pcdpca(X, period = NULL, q = 30, freq = (-1000:1000/1000) * pi)
pcdpca(X, period = NULL, q = 30, freq = (-1000:1000/1000) * pi)
X |
multivariate stationary time series |
period |
period of the periodic time series |
q |
window for spectral density estimation as in |
freq |
frequency grid to estimate on as in |
principal components series
Kidzinski, Kokoszka, Jouzdani Dynamic principal components of periodically correlated functional time series Research report, 2016
## Prepare some process library(fda) library(freqdom) MSE = function(X,Y=0){ sum((X-Y)**2) / nrow(X) } d = 7 n = 100 A = t(t(matrix(rnorm(d*n),ncol=d,nrow=n))*7:1) B = t(t(matrix(rnorm(d*n),ncol=d,nrow=n))*7:1) C = t(t(matrix(rnorm(d*n),ncol=d,nrow=n))*7:1) X = matrix(0,ncol=d,nrow=3*n) X[3*(1:n) - 1,] = A X[3*(1:n) - 2,] = A + B X[3*(1:n) ,] = 2*A - B + C basis = create.fourier.basis(nbasis=7) X.fd = fd(t(Re(X)),basis=basis) plot(X.fd) ## Hold out some datapoints train = 1:(50*3) test = (50*3) : (3*n) ## Static PCA ## PR = prcomp(as.matrix(X[train,])) Y1 = as.matrix(X) %*% PR$rotation Y1[,-1] = 0 Xpca.est = Y1 %*% t(PR$rotation) ## Dynamic PCA ## XI.est = dpca(as.matrix(X[train,]), q=3, freq=pi*(-150:150/150), Ndpc=1) # finds the optimal filter Y.est = freqdom::filter.process(X, XI.est$filters ) Xdpca.est = freqdom::filter.process(Y.est, t(rev(XI.est$filters)) ) # deconvolution ## Periodically correlated PCA ## XI.est.pc = pcdpca(as.matrix(X[train,]), q=3, freq=pi*(-150:150/150),period=3) # finds the optimal filter Y.est.pc = pcdpca.scores(X, XI.est.pc) # applies the filter Y.est.pc[,-1] = 0 # forces the use of only one component Xpcdpca.est = pcdpca.inverse(Y.est.pc, XI.est.pc) # deconvolution ## Results cat("NMSE PCA = ") r0 = MSE(X[test,],Xpca.est[test,]) / MSE(X[test,],0) cat(r0) cat("\nNMSE DPCA = ") r1 = MSE(X[test,],Xdpca.est[test,]) / MSE(X[test,],0) cat(r1) cat("\nNMSE PCDPCA = ") r2 = MSE(X[test,],Xpcdpca.est[test,]) / MSE(X[test,],0) cat(r2) cat("\n")
## Prepare some process library(fda) library(freqdom) MSE = function(X,Y=0){ sum((X-Y)**2) / nrow(X) } d = 7 n = 100 A = t(t(matrix(rnorm(d*n),ncol=d,nrow=n))*7:1) B = t(t(matrix(rnorm(d*n),ncol=d,nrow=n))*7:1) C = t(t(matrix(rnorm(d*n),ncol=d,nrow=n))*7:1) X = matrix(0,ncol=d,nrow=3*n) X[3*(1:n) - 1,] = A X[3*(1:n) - 2,] = A + B X[3*(1:n) ,] = 2*A - B + C basis = create.fourier.basis(nbasis=7) X.fd = fd(t(Re(X)),basis=basis) plot(X.fd) ## Hold out some datapoints train = 1:(50*3) test = (50*3) : (3*n) ## Static PCA ## PR = prcomp(as.matrix(X[train,])) Y1 = as.matrix(X) %*% PR$rotation Y1[,-1] = 0 Xpca.est = Y1 %*% t(PR$rotation) ## Dynamic PCA ## XI.est = dpca(as.matrix(X[train,]), q=3, freq=pi*(-150:150/150), Ndpc=1) # finds the optimal filter Y.est = freqdom::filter.process(X, XI.est$filters ) Xdpca.est = freqdom::filter.process(Y.est, t(rev(XI.est$filters)) ) # deconvolution ## Periodically correlated PCA ## XI.est.pc = pcdpca(as.matrix(X[train,]), q=3, freq=pi*(-150:150/150),period=3) # finds the optimal filter Y.est.pc = pcdpca.scores(X, XI.est.pc) # applies the filter Y.est.pc[,-1] = 0 # forces the use of only one component Xpcdpca.est = pcdpca.inverse(Y.est.pc, XI.est.pc) # deconvolution ## Results cat("NMSE PCA = ") r0 = MSE(X[test,],Xpca.est[test,]) / MSE(X[test,],0) cat(r0) cat("\nNMSE DPCA = ") r1 = MSE(X[test,],Xdpca.est[test,]) / MSE(X[test,],0) cat(r1) cat("\nNMSE PCDPCA = ") r2 = MSE(X[test,],Xpcdpca.est[test,]) / MSE(X[test,],0) cat(r2) cat("\n")
For given scores Y
and dynamic principal components XI
retrive a series from which scores Y
were calculated.
This procedure should be seen as the inverse of pcdpca.scores
.
pcdpca.inverse(Y, XI)
pcdpca.inverse(Y, XI)
Y |
scores process |
XI |
principal components series |
Retrived process X
Kidzinski, Kokoszka, Jouzdani Dynamic principal components of periodically correlated functional time series Research report, 2016
Compute periodically correlated DPCA scores, given the filters XI
pcdpca.scores(X, XI)
pcdpca.scores(X, XI)
X |
multivariate time series |
XI |
series of filters returned from pcdpca |