data(dentus)
dentus.vcv <- daply (dentus, .(species), function(x) cov(x[,-5]))
dentus.vcv <- aperm(dentus.vcv, c(2, 3, 1))
dentus.etd <- EigenTensorDecomposition(dentus.vcv, TRUE)
# Plot some results
oldpar <- par(mfrow = c(1,2))
plot(dentus.etd $ values, pch = 20, type = 'b', ylab = 'Eigenvalue')
plot(dentus.etd $ projection [, 1:2], pch = 20,
xlab = 'Eigentensor 1', ylab = 'Eigentensor 2')
text(dentus.etd $ projection [, 1:2],
labels = rownames (dentus.etd $ projection), pos = 2)
par(oldpar)
# \donttest{
# we can also deal with posterior samples of covariance matrices using plyr
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))
# this will perform one eigentensor decomposition for each set of posterior samples
dentus.post.etd <- alply(dentus.post.vcv, 4, EigenTensorDecomposition)
# which would allow us to observe the posterior
# distribution of associated eigenvalues, for example
dentus.post.eval <- laply (dentus.post.etd, function (L) L $ values)
boxplot(dentus.post.eval, xlab = 'Index', ylab = 'Value',
main = 'Posterior Eigenvalue Distribution')
# }
Run the code above in your browser using DataLab