## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", eval = FALSE)

## -----------------------------------------------------------------------------
# library("msPCA")
# Sigma <- cor(datasets::mtcars)
# 
# ks_grid <- seq(2, 10, by = 1)
# trade_off <- sapply(ks_grid, function(k) {
#   set.seed(42)
#   res <- mspca(Sigma, r = 3, ks = rep(k, 3), verbose = FALSE)
#   fraction_variance_explained(Sigma, res$x_best)
# })
# plot(ks_grid, trade_off, type = "b",
#      xlab = "sparsity budget k", ylab = "fraction of variance explained")

## ----eval = FALSE-------------------------------------------------------------
# res <- mspca(Sigma, r = 3, ks = rep(5, 3), feasibilityConstraintType = 1, verbose = FALSE)
# summary(res)                            # zero-correlation violations, as fitted
# res$nonredundancy$orthogonality         # how far the same solution is from orthogonal

