pca(object, method, nPcs = 2, scale = c("none", "pareto", "vector", "uv"), center = TRUE, completeObs = TRUE, subset = NULL, cv = c("none", "q2"), ...)
ExpressionSet
in which case the transposed expression
matrix is used. Can also be a data frame in which case all
numberic variables are used to fit the PCA.listPcaMethods()
. Can be left missing in which case the
svd
PCA is chosen for data wihout missing values and
nipalsPca
for data with missing valuesprep
.prep
.completeObs
slot on the
resulting pcaRes
object containing the original data with
but with all NAs replaced with the estimates.pcaRes
object.
nipalsPca
.
bpca
.
ppca
.
svdImpute
.
Scaling and centering is part of the PCA model and handled by
prep
.
Troyanskaya O. and Cantor M. and Sherlock G. and Brown P. and Hastie T. and Tibshirani R. and Botstein D. and Altman RB. - Missing value estimation methods for DNA microarrays. Bioinformatics. 2001 Jun;17(6):520-5.
prcomp
, princomp
,
nipalsPca
, svdPca
data(iris)
## Usually some kind of scaling is appropriate
pcIr <- pca(iris, method="svd", nPcs=2)
pcIr <- pca(iris, method="nipals", nPcs=3, cv="q2")
## Get a short summary on the calculated model
summary(pcIr)
plot(pcIr)
## Scores and loadings plot
slplot(pcIr, sl=as.character(iris[,5]))
## use an expressionset and ggplot
data(sample.ExpressionSet)
pc <- pca(sample.ExpressionSet)
df <- merge(scores(pc), pData(sample.ExpressionSet), by=0)
library(ggplot2)
ggplot(df, aes(PC1, PC2, shape=sex, color=type)) +
geom_point() +
xlab(paste("PC1", pc@R2[1] * 100, "% of variance")) +
ylab(paste("PC2", pc@R2[2] * 100, "% of variance"))
Run the code above in your browser using DataLab