Learn R Programming

Morpho (version 2.1)

groupPCA: Perform PCA based of the group means' covariance matrix

Description

Calculate covariance matrix of the groupmeans and project all observations into the eigenspace of this covariance matrix. This displays a low dimensional between group structure of a high dimensional problem.

Usage

groupPCA(dataarray, groups, rounds = 10000, tol = 1e-10, cv = TRUE,
  mc.cores = parallel::detectCores(), weighting = TRUE)

Arguments

dataarray
Either a k x m x n real array, where k is the number of points, m is the number of dimensions, and n is the sample size. Or alternatively a n x m Matrix where n is the numeber of observations and m the number of variables (this can be PC scores for exampl
groups
a character/factor vector containgin grouping variable.
rounds
integer: number of permutations if a permutation test of the euclidean distance between group means is requested.If rounds = 0, no test is performed.
tol
threshold to ignore eigenvalues of the covariance matrix.
cv
logical: requests leaving-one-out crossvalidation
mc.cores
integer: how many cores of the Computer are allowed to be used. Default is use autodetection by using detectCores() from the parallel package. Parallel processing is disabled on Windows due to occasional errors.
weighting
logical:weight between groups covariance matrix according to group sizes.

Value

  • eigenvaluesNon-zero eigenvalues of the groupmean covariance matrix
  • groupPCsPC-axes - i.e. eigenvectors of the groupmean covariance matrix
  • Variancetable displaying the variance explained by eache eigenvalue
  • ScoresScores of all observation in the PC-space
  • probsp-values of pairwise groupdifferences - based on permuation testing
  • groupdistsEuclidean distances between groups' averages
  • groupmeansGroupmeans
  • GrandmeanGrand mean
  • CVCross-validated scores
  • groupsgrouping Variable

References

Mitteroecker P, Bookstein F 2011. Linear Discrimination, Ordination, and the Visualization of Selection Gradients in Modern Morphometrics. Evolutionary Biology 38:100-114.

Boulesteix, A. L. 2005: A note on between-group PCA, International Journal of Pure and Applied Mathematics 19, 359-366.

See Also

CVA

Examples

Run this code
require(car)
data(iris)
vari <- iris[,1:4]
facto <- iris[,5]
pca.1 <-groupPCA(vari,groups=facto,rounds=100,mc.cores=1)

### plot scores
scatterplotMatrix(pca.1$Scores,groups=facto, ellipse=TRUE,
        by.groups=TRUE,var.labels=c("PC1","PC2","PC3"))

## example with shape data
data(boneData)
proc <- procSym(boneLM)
pop_sex <- name2factor(boneLM, which=3:4)
gpca <- groupPCA(proc$orpdata, groups=pop_sex, rounds=0, mc.cores=2)
## visualize shape associated with first between group PC
dims <- dim(proc$mshape)
## calculate matrix containing landmarks of grandmean
grandmean <- matrix(gpca$Grandmean, dims[1], dims[2])
## calculate landmarks from first between-group PC
#                   (+2 and -2 standard deviations)
gpcavis2sd<- showPC(2*sd(gpca$Scores[,1]), gpca$groupPCs, grandmean)
gpcavis2sd.neg<- showPC(-2*sd(gpca$Scores[,1]), gpca$groupPCs, grandmean)
deformGrid3d(gpcavis2sd, gpcavis2sd.neg, ngrid = 0)
require(rgl)
## visualize grandmean mesh

grandm.mesh <- warp.mesh(skull_0144_ch_fe.mesh, boneLM[,,1],grandmean)
wire3d(grandm.mesh, col="white")
spheres3d(grandmean, radius=0.005)

Run the code above in your browser using DataLab