# Start the multiblock R package
library(multiblock)
The following single- and two-block methods are available in the multiblock package (function names in parentheses):
The following sections will describe how to format your data for analysis and invoke all methods from the list above.
We use a selection of extracts from the potato data included in the package for the basic data analyses. The data set is stored as a named list of matrices with chemical, rheological, spectral and sensory measurements.
data(potato)
<- potato$Chemical
X <- potato$Sensory[,1,drop=FALSE] y
Since the basic methods cover both single block analysis, supervised and unsupervised analysis, the interfaces for the basic methods vary a bit. Supervised methods use the formula interface and the remaining methods take input as a single matrix or list of matrices. See vignettes for supervised and unsupervised analysis for details.
# Single block
<- pca(X, ncomp = 2)
pot.pca
# Two blocks, supervised
<- pcr(y ~ X, ncomp = 2)
pot.pcr <- plsr(y ~ X, ncomp = 2)
pot.pls
# Two blocks, unsupervised
<- cca(potato[1:2])
pot.cca <- ifa(potato[1:2])
pot.ifa
# Variable linked decomposition
<- gsvd(lapply(potato[3:4], t)) pot.gsvd
Output from all methods include slots called loadings, scores, blockLoadings and blockScores, or a suitable subset of these. An info slot describes which types of (block) loadings/scores are in the output. There may be various extra elements in addition to the common elements, e.g. coefficients, weights etc.
# PCA returns loadings and scores:
names(pot.pca)
#> [1] "loadings" "scores" "Xmeans" "" "PCA" "info" "call"
summary(pot.pca)
#> Principal Component Analysis
#>
#> Score type: Scores
#> Loadings type: Loadings
# GSVD returns block scores and common loadings:
names(pot.gsvd)
#> [1] "loadings" "blockScores" "GSVD" "info" "call"
summary(pot.gsvd)
#> Generalized Singular Value Decomposition
#>
#> Loadings type: Loadings
#> Block scores type: Block scores
Functions for accessing scores and loadings are based on functions from the pls package, but extended with a block parameter to allow extraction of common/global scores/loadings and their block counterparts. The default block is 0, corresponding to the common/global block. Block scores/loadings can be accessed by number or name.
# Global scores plotted with object labels
plot(scores(pot.pca), labels = "names")
# Block loadings for Chemical block with variable labels in scatter format
plot(loadings(pot.cca, "Chemical"), labels = "names", scatter = TRUE)
# Non-existing elements are swapped with existing ones with a warning.
<- scores(pot.cca)
sc #> Warning in scores.multiblock(pot.cca): No global/consensus scores. Returning
#> block 1 scores.