Learn R Programming

bootSVD (version 0.1)

getMomentsAndMomentCI: Calculate bootstrap moments and moment-based confidence intervals for the PCs.

Description

Let $K$ be the number of PCs of interest, let $B$ be the number of bootstrap samples, and let $p$ be the number of measurements per subject, also known as the dimension of the sample. In general, we use $k$ to refer to the principal component (PC) index, where $k=1,2,...K$, and use $b$ to refer to the bootstrap index, where $b=1,2,...B$.

Usage

getMomentsAndMomentCI(AsByB, V, K = dim(AsByB[[1]])[2], talk = FALSE)

Arguments

AsByB
a list of the bootstrap PC matrices for each bootstrap sample. This list should be indexed by $b$, with the $b^{th}$ element containing the results from the $b^{th}$ bootstrap sample.
V
a ($p$ by $n$) containing the coordinate vectors for the matrices within the AsByB list, where $n$ is sample size and $p$ is sample dimension. Generally for bootstrap PCA, AsByB should contain the PCs for the bootstrap sc
K
the number of leading PCs for which moments and confidence intervals should be obtained.
talk
setting to TRUE will cause the function to print its progress in calculating the bootstrap variance for each PC.

Value

  • a list containing
  • EVsa list containing element-wise bootstrap means for each of the K fitted PCs, indexed by k.
  • varVsa list containing element-wise bootstrap variances for each of the K fitted PCs, indexed by k.
  • sdVsa list containing element-wise bootstrap standard errors for each of the K fitted PCs, indexed by k.
  • momentCIa list of ($p$ by $2$) matrices, indexed by k, where momentCI[[k]][j,] is the pointwise moment-based CI for the $j^{th}$ element of the $k^{th}$ PC.

Examples

Run this code
#use small n, small B for a quick illustration
set.seed(0)
Y<-simEEG(n=100, centered=TRUE, wide=TRUE)
svdY<-fastSVD(Y)
V<-svdY$v #right singular vectors of the wide matrix Y
DUt<- tcrossprod(diag(svdY$d),svdY$u)
bInds<-genBootIndeces(B=200,n=dim(DUt)[2])
bootSVD_LD_output<-bootSVD_LD(DUt=DUt,bInds=bInds,K=3,talk=TRUE)

AsByB<-bootSVD_LD_output$As
moments<-getMomentsAndMomentCI(AsByB,V,talk=TRUE)
plot(V[,1],type='l',ylim=c(-.1,.1),main='Original PC1, with CI in blue')
matlines(moments$momentCI[[1]],col='blue',lty=1)

#Can also use this function to get moments for low dimensional
#vectors A^b[,k], by setting V to the identity matrix.
moments_A<- getMomentsAndMomentCI(As=AsByB,V=diag(nrow(AsByB[[1]])))

Run the code above in your browser using DataLab