library(ICtest)
# matrix-variate example
n <- 200
sig <- 0.6
Z <- rbind(sqrt(0.7)*rt(n,df=5)*sqrt(3/5),
sqrt(0.3)*runif(n,-sqrt(3),sqrt(3)),
sqrt(0.3)*(rchisq(n,df=3)-3)/sqrt(6),
sqrt(0.9)*(rexp(n)-1),
sqrt(0.1)*rlogis(n,0,sqrt(3)/pi),
sqrt(0.5)*(rbeta(n,2,2)-0.5)*sqrt(20)
)
dim(Z) <- c(3, 2, n)
U1 <- rorth(12)[,1:3]
U2 <- rorth(8)[,1:2]
U <- list(U1=U1, U2=U2)
Y <- tensorTransform2(Z,U,1:2)
EPS <- array(rnorm(12*8*n, mean=0, sd=sig), dim=c(12,8,n))
X <- Y + EPS
TEST <- tPCAaug(X)
# Dimension should be 3 and 2 and (close to) sigma2 0.36
TEST
# Noise variance in i-th mode is equal to Sigma2 multiplied by the product
# of number of colums of all modes except i-th one
TEST$Sigma2*c(8,12)
# This is returned as
TEST$AllSigHat2
# higher order tensor example
Z2 <- rnorm(n*3*2*4*10)
dim(Z2) <- c(3,2,4,10,n)
U2.1 <- rorth(12)[ ,1:3]
U2.2 <- rorth(8)[ ,1:2]
U2.3 <- rorth(5)[ ,1:4]
U2.4 <- rorth(20)[ ,1:10]
U2 <- list(U1 = U2.1, U2 = U2.2, U3 = U2.3, U4 = U2.4)
Y2 <- tensorTransform2(Z2, U2, 1:4)
EPS2 <- array(rnorm(12*8*5*20*n, mean=0, sd=sig), dim=c(12, 8, 5, 20, n))
X2 <- Y2 + EPS2
TEST2 <- tPCAaug(X2, noise = "quantile", alpha =0.3)
TEST2
Run the code above in your browser using DataLab