ProjectMatrix function

Project Covariance Matrix

Project Covariance Matrix

This function projects a given covariance matrix into the basis provided by an eigentensor decomposition.

ProjectMatrix(matrix, etd)

Arguments

  • matrix: A symmetric covariance matrix for k traits
  • etd: Eigentensor decomposition of m covariance matrices for k traits (obtained from EigenTensorDecomposition)

Returns

Vector of scores of given covariance matrix onto eigentensor basis.

Examples

# this function is useful for projecting posterior samples for a set of # covariance matrices onto the eigentensor decomposition done # on their estimated means data(dentus) dentus.models <- dlply(dentus, .(species), lm, formula = cbind(humerus, ulna, femur, tibia) ~ 1) dentus.matrices <- llply(dentus.models, BayesianCalculateMatrix, samples = 100) dentus.post.vcv <- laply(dentus.matrices, function (L) L $ Ps) dentus.post.vcv <- aperm(dentus.post.vcv, c(3, 4, 1, 2)) dentus.mean.vcv <- aaply(dentus.post.vcv, 3, MeanMatrix) dentus.mean.vcv <- aperm(dentus.mean.vcv, c(2, 3, 1)) dentus.mean.etd <- EigenTensorDecomposition(dentus.mean.vcv) dentus.mean.proj <- data.frame('species' = LETTERS [1:5], dentus.mean.etd $ projection) dentus.post.proj <- adply(dentus.post.vcv, c(3, 4), ProjectMatrix, etd = dentus.mean.etd) colnames(dentus.post.proj) [1:2] <- c('species', 'sample') levels(dentus.post.proj $ species) <- LETTERS[1:5] require(ggplot2) ggplot() + geom_point(aes(x = ET1, y = ET2, color = species), data = dentus.mean.proj, shape = '+', size = 8) + geom_point(aes(x = ET1, y = ET2, color = species), data = dentus.post.proj, shape = '+', size = 3) + theme_bw()

References

Basser P. J., Pajevic S. 2007. Spectral decomposition of a 4th-order covariance tensor: Applications to diffusion tensor MRI. Signal Processing. 87:220-236.

Hine E., Chenoweth S. F., Rundle H. D., Blows M. W. 2009. Characterizing the evolution of genetic variance using genetic covariance tensors. Philosophical transactions of the Royal Society of London. Series B, Biological sciences. 364:1567-78.

See Also

EigenTensorDecomposition, RevertMatrix

Author(s)

Guilherme Garcia, Diogo Melo

  • Maintainer: Diogo Melo
  • License: MIT + file LICENSE
  • Last published: 2023-12-05

Useful links