knitr::opts_chunk$set(collapse = TRUE, comment = "#>", fig.width = 7, fig.height = 5) library(msma)
The msma package implements sparse and supervised matrix decomposition for
single-block and multiblock multivariable data. The main function is msma().
The analysis is selected by the supplied inputs:
X only: principal component analysis (PCA);X and Y: partial least squares (PLS);Z: optional external supervision variable;X and Y may be matrices or lists of matrices. All blocks must contain the
same observations in the same row order.
dat <- simdata(n = 40, rho = 0.8, Xps = 5, Yps = 4, seed = 1) X <- dat$X[[1]] Y <- dat$Y[[1]] set.seed(1) Z <- rbinom(nrow(X), 1, 0.5) dim(X) dim(Y)
A matrix supplied as X produces a single-block PCA.
fit_pca <- msma(X, comp = 2) fit_pca summary(fit_pca)
The main X-side results are:
wbX: block-level weights or loadings;sbX: block-level scores;cpevX: cumulative percentage of explained variance;avX: adjusted variance attributable to each component.fit_pca$wbX head(fit_pca$sbX[[1]]) fit_pca$cpevX
plot(fit_pca, axes = 1, plottype = "bar", las = 2) plot(fit_pca, v = "score", axes = 1:2, plottype = "scatter")
A positive lambdaX introduces sparsity into the X-side block weights.
fit_spca <- msma(X, comp = 2, lambdaX = 0.10) fit_spca$nzwbX fit_spca$selectXnames
Z supplies external supervision. The strength of supervision on X is
controlled by muX.
fit_sup_pca <- msma( X = X, Z = Z, comp = 2, lambdaX = 0.05, muX = 0.20, intseed = 1 ) fit_sup_pca$predictiv
Supplying both X and Y produces PLS.
fit_pls <- msma(X = X, Y = Y, comp = 2) fit_pls
plot(fit_pls, axes = 1, XY = "XY") plot(fit_pls, axes = 2, XY = "XY")
Sparse and supervised PLS are requested by adding lambdaX, lambdaY, and
optionally Z, muX, and muY.
fit_spls <- msma( X = X, Y = Y, Z = Z, comp = 2, lambdaX = 0.10, lambdaY = 0.10, muX = 0.10, muY = 0.10, intseed = 1 ) fit_spls$nzwbX fit_spls$nzwbY
pred <- predict(fit_pls, newX = X, newY = Y) names(pred)
sessionInfo()
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.