Perform principal components analysis on the samples (columns) from a microarray or proteomics experiment.
1 2 3
Either a data frame or matrix with numeric values or an
A logical value; should the rows of the data matrix be centered first?
A logical value; should the rows of the data matrix be scaled to have standard deviation 1?
A list of colors to represent each level of the
A character string; the plot title
A numeric vector of length two specifying which two principal components should be included in the plot.
Additional graphical parameters for
The main reason for developing the
SamplePCA class is that the
princomp function is very inefficient when the number of
variables (in the microarray setting, genes) far exceeds the number of
observations (in the microarray setting, biological samples). The
princomp function begins by computing the full covariance
matrix, which gets rather large in a study involving tens of thousands
of genes. The
SamplePCA class, by contrast, uses singular
value decomposition (
svd) on the original data matrix to
compute the principal components.
The base functions
screeplot, which produces a barplot of the
percentage of variance explained by each component, and
which produces a scatter plot comparing two selected components
(defaulting to the first two), have been generalized as methods for
SamplePCA class. You can add sample labels to the scatter
plot using either the
identify methods. One
should, however, note that the current implementaiton of these methods
only works when plotting the first two components.
SamplePCA function constructs and returns an object of the
SamplePCA class. We assume that the input data matrix has N
columns (of biological samples) and P rows (of genes).
predict method returns a matrix whose size is the number of
columns in the input by the number of principal components.
Objects should be created using the
SamplePCA function. In the
simplest case, you simply pass in a data matrix and a logical vector,
splitter, assigning classes to the columns, and the constructor
performs principal components analysis on the column. The
splitter is ignored by the constructor and is simply saved to
be used by the plotting routines. If you omit the
then no grouping structure is used in the plots.
If you pass
splitter as a factor instead of a logical vector,
then the plotting routine will distinguish all levels of the factor.
The code is likely to fail, however, if one of the levels of the
factor has zero representatives among the data columns.
As with the class comparison functions (see, for example,
MultiTtest) that are part of OOMPA,
we can also perform PCA on
from the BioConductor libraries. In this case, we pass in an
ExpressionSet object along with a character string containing the
name of a factor to use for splitting the data.
matrix of size NxN, where N is the
number of columns in the input, representing the projections of
the input columns onto the first N principal components.
numeric vector of length N; the
amount of the total variance explained by each principal component.
matrix of size PxN (the same size
as the input matrix) containing each of the first P principal
components as columns.
A logical vector or factor of length N classifying the columns into known groups.
logical value; was the data standardized?
numeric vector of length P; the mean
vector of the input data, which is used for centering by the
numeric vector of length P; the
standard deviation of the input data, which is used for scaling by
An object of class
call that records
how the object was created.
signature(x = SamplePCA, y = missing): Plot the
samples in a two-dimensional principal component space.
signature(object = SamplePCA): Project new
data into the principal component space.
signature(x = SamplePCA): Produce a bar
chart of the variances explained by each principal component.
signature(object = SamplePCA): Write out a
summary of the object.
signature(object = SamplePCA): interactively
identify points in the plot of a
signature(object = SamplePCA): Add sample
identifiers to the scatter plot of a
using the base
Kevin R. Coombes email@example.com
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
showClass("SamplePCA") ## simulate data from three different groups d1 <- matrix(rnorm(100*10, rnorm(100, 0.5)), nrow=100, ncol=10, byrow=FALSE) d2 <- matrix(rnorm(100*10, rnorm(100, 0.5)), nrow=100, ncol=10, byrow=FALSE) d3 <- matrix(rnorm(100*10, rnorm(100, 0.5)), nrow=100, ncol=10, byrow=FALSE) dd <- cbind(d1, d2, d3) kind <- factor(rep(c('red', 'green', 'blue'), each=10)) colnames(dd) <- paste(kind, rep(1:10, 3), sep='') ## perform PCA spc <- SamplePCA(dd, splitter=kind) ## plot the results plot(spc, col=levels(kind)) ## mark the group centers x1 <- predict(spc, matrix(apply(d1, 1, mean), ncol=1)) points(x1, x1, col='red', cex=2) x2 <- predict(spc, matrix(apply(d2, 1, mean), ncol=1)) points(x2, x2, col='green', cex=2) x3 <- predict(spc, matrix(apply(d3, 1, mean), ncol=1)) points(x3, x3, col='blue', cex=2) ## check out the variances screeplot(spc) ## cleanup rm(d1, d2, d3, dd,kind, spc, x1, x2, x3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.