dat <- gendata_Fac(n = 300, p = 500)
res <- gsspFactorm(dat$X)
ccorFun(res$hH, dat$H0) # the smallest canonical correlation
## comparison of l2 norm
oldpar <- par(mar = c(5, 5, 2, 2), mfrow = c(1, 2))
plot(rowSums(dat$B0^2), type='o', ylab='l2B', main='True')
l2B <- rowSums(res$sphB^2)
plot(l2B, type='o', main='Est.')
Bind <- ifelse(dat$B0==0, 0, 1)
hBind <- ifelse(res$sphB==0, 0, 1)
## Select good penalty parameters
dat <- gendata_Fac(n = 300, p = 200)
res <- gsspFactorm(dat$X, lambda1=0.04*nrow(dat$X)^(1/4) ,lambda2=1*nrow(dat$X)^(1/4))
ccorFun(res$hH, dat$H0) # the smallest canonical correlation
## comparison of l2 norm
plot(rowSums(dat$B0^2), type='o', ylab='l2B', main='True')
l2B <- rowSums(res$sphB^2)
plot(l2B, type='o', main='Est.')
## comparison of structure of loading matrix
Bind <- ifelse(dat$B0==0, 0, 1)
hBind <- ifelse(res$sphB==0, 0, 1)
par(oldpar)
Run the code above in your browser using DataLab