Description Usage Arguments Details Value Author(s) References See Also Examples
Performs a principal components analysis on the given data matrix that can contain missing values. If data are complete 'pca' uses Singular Value Decomposition, if there are some missing values, it uses the NIPALS algorithm.
1 2 3 4 5 6 7 8 9 10 |
X |
a numeric matrix (or data frame) which provides the data for the principal components analysis. It can contain missing values. |
ncomp |
integer, if data is complete |
center |
a logical value indicating whether the variables should be shifted to be zero centered.
Alternately, a vector of length equal the number of columns of |
scale |
a logical value indicating whether the variables should be scaled to have
unit variance before the analysis takes place. The default is |
max.iter |
integer, the maximum number of iterations in the NIPALS algorithm. |
tol |
a positive real, the tolerance used in the NIPALS algorithm. |
logratio |
one of ('none','CLR','ILR'). Specifies the log ratio transformation to deal with compositional values that may arise from specific normalisation in sequencing data. Default to 'none' |
ilr.offset |
When logratio is set to 'ILR', an offset must be input to avoid infinite value after the logratio transform, default to 0.001. |
V |
Matrix used in the logratio transformation id provided. |
multilevel |
sample information for multilevel decomposition for repeated measurements. |
The calculation is done either by a singular value decomposition of the (possibly centered and scaled)
data matrix, if the data is complete or by using the NIPALS algorithm if there is data missing. Unlike
princomp
, the print method for these objects prints the results in a nice format and the
plot
method produces a bar plot of the percentage of variance explaned by the principal
components (PCs).
When using NIPALS (missing values), we make the assumption that the first (min(ncol(X),
nrow(X)
)
principal components will account for 100 % of the explained variance.
Note that scale= TRUE
cannot be used if there are zero or constant (for center = TRUE
) variables.
Components are omitted if their standard deviations are less than or equal to comp.tol
times
the standard deviation of the first component. With the default null setting, no components are omitted.
Other settings for comp.tol
could be comp.tol = sqrt(.Machine$double.eps)
,
which would omit essentially constant components, or comp.tol = 0
.
According to Filzmoser et al., a ILR log ratio transformation is more appropriate for PCA with compositional data. Both CLR and ILR are valid.
Logratio transform and multilevel analysis are performed sequentially as internal pre-processing step, through logratio.transfo
and withinVariation
respectively.
Logratio can only be applied if the data do not contain any 0 value (for count data, we thus advise the normalise raw data with a 1 offset). For ILR transformation and additional offset might be needed.
pca
returns a list with class "pca"
and "prcomp"
containing the following components:
ncomp |
the number of principal components used. |
sdev |
the eigenvalues of the covariance/correlation matrix, though the calculation is actually done with the singular values of the data matrix or by using NIPALS. |
rotation |
the matrix of variable loadings (i.e., a matrix whose columns contain the eigenvectors). |
loadings |
same as 'rotation' to keep the mixOmics spirit |
x |
the value of the rotated data (the centred (and scaled if requested) data multiplied by the rotation/loadings matrix), also called the principal components. |
variates |
same as 'x' to keep the mixOmics spirit |
center, scale |
the centering and scaling used, or |
explained_variance |
explained variance from the multivariate model, used for plotIndiv |
Florian Rohart, Kim-Anh Lê Cao, Ignacio González
On log ratio transformations: Filzmoser, P., Hron, K., Reimann, C.: Principal component analysis for compositional data with outliers. Environmetrics 20(6), 621-632 (2009) Lê Cao K.-A., Costello ME, Lakis VA, Bartolo, F,Chua XY, Brazeilles R, Rondeau P. MixMC: Multivariate insights into Microbial Communities. PLoS ONE, 11(8): e0160169 (2016). On multilevel decomposition: Westerhuis, J.A., van Velzen, E.J., Hoefsloot, H.C., Smilde, A.K.: Multivariate paired data analysis: multilevel plsda versus oplsda. Metabolomics 6(1), 119-128 (2010) Liquet, B., Lê Cao, K.-A., Hocini, H., Thiebaut, R.: A novel approach for biomarker selection and the integration of repeated measures experiments from two assays. BMC bioinformatics 13(1), 325 (2012)
nipals
, prcomp
, biplot
,
plotIndiv
, plotVar
and http://www.mixOmics.org for more details.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | # example with missing values where NIPALS is applied
# --------------------------------
data(multidrug)
pca.res <- pca(multidrug$ABC.trans, ncomp = 4, scale = TRUE)
plot(pca.res)
print(pca.res)
biplot(pca.res, xlabs = multidrug$cell.line$Class, cex = 0.7)
# samples representation
plotIndiv(pca.res, ind.names = multidrug$cell.line$Class,
group = as.numeric(as.factor(multidrug$cell.line$Class)))
## Not run:
plotIndiv(pca.res, cex = 0.2,
col = as.numeric(as.factor(multidrug$cell.line$Class)),style="3d")
## End(Not run)
# variable representation
plotVar(pca.res)
## Not run:
plotVar(pca.res, rad.in = 0.5, cex = 0.5,style="3d")
## End(Not run)
# example with multilevel decomposition and CLR log ratio transformation (ILR longer to run)
# ----------------
## Not run:
data("diverse.16S")
pca.res = pca(X = diverse.16S$data.TSS, ncomp = 5,
logratio = 'CLR', multilevel = diverse.16S$sample)
plot(pca.res)
plotIndiv(pca.res, ind.names = FALSE, group = diverse.16S$bodysite, title = '16S diverse data',
legend = TRUE)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.