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

View source: R/groupPCA.r

groupPCAR Documentation

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 example)

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

eigenvalues

Non-zero eigenvalues of the groupmean covariance matrix

groupPCs

PC-axes - i.e. eigenvectors of the groupmean covariance matrix

Variance

table displaying the between-group variance explained by each between group PC - this only reflects the variability of the group means and NOT the variability of the data projected into that space

Scores

Scores of all observation in the PC-space

probs

p-values of pairwise groupdifferences - based on permuation testing

groupdists

Euclidean distances between groups' averages

groupmeans

matrix with rows containing the Groupmeans, or a k x m x groupsize array if the input is a k x m x n landmark array

Grandmean

vector containing the Grand mean, or a matrix if the input is a k x m x n landmark array

CV

Cross-validated scores

groups

grouping Variable

resPCs

PCs orthogonal to the between-group PCs

resPCscores

Scores of the residualPCs

resVar

table displaying the residual variance explained by each residual PC.

Author(s)

Stefan Schlager

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


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

### plot scores
if (require(car)) {
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)
## Not run: 
## visualize shape associated with first between group PC
dims <- dim(proc$mshape)
## calculate matrix containing landmarks of grandmean
grandmean <-gpca$Grandmean
## calculate landmarks from first between-group PC
#                   (+2 and -2 standard deviations)
gpcavis2sd<- restoreShapes(c(-2,2)*sd(gpca$Scores[,1]), gpca$groupPCs[,1], grandmean)
deformGrid3d(gpcavis2sd[,,1], gpcavis2sd[,,2], ngrid = 0,size=0.01)
require(rgl)
## visualize grandmean mesh

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

## End(Not run)



Morpho documentation built on June 22, 2024, 7:19 p.m.