KrzSubspace | R Documentation |
Calculates the subspace most similar across a set of covariance matrices.
KrzSubspace(cov.matrices, k = NULL)
cov.matrices |
list of covariance matrices |
k |
number of dimensions to be retained in calculating the subspace |
H shared space matrix
k_eVals_H eigen values for shared space matrix, maximum value for each is the number of matrices, representing a fully shared direction
k_eVecs_H eigen vectors of shared space matrix
angles between each population subspace and each eigen vector of shared space matrix
can be used to implement the Bayesian comparison from Aguirre et al. 2014
Aguirre, J. D., E. Hine, K. McGuigan, and M. W. Blows. "Comparing G: multivariate analysis of genetic variation in multiple populations." Heredity 112, no. 1 (2014): 21-29.
data(dentus)
dentus.matrices = dlply(dentus, .(species), function(x) cov(x[-5]))
KrzSubspace(dentus.matrices, k = 2)
## Not run:
# The method in Aguirre et al. 2014 can de implemented using this function as follows:
#Random input data with dimensions traits x traits x populations x MCMCsamples:
cov.matrices = aperm(aaply(1:10, 1, function(x) laply(RandomMatrix(6, 40,
variance = runif(6,1, 10)),
identity)),
c(3, 4, 1, 2))
Hs = alply(cov.matrices, 4, function(x) alply(x, 3)) |> llply(function(x) KrzSubspace(x, 3)$H)
avgH = Reduce("+", Hs)/length(Hs)
avgH.vec <- eigen(avgH)$vectors
MCMC.H.val = laply(Hs, function(mat) diag(t(avgH.vec) %*% mat %*% avgH.vec))
# confidence intervals for variation in shared subspace directions
library(coda)
HPDinterval(as.mcmc(MCMC.H.val))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.