The MCMCglmm
package is well suited to incorporating repeated measures of interspecific data. The following code demonstrates how to account for repeated measures by specifying a random effect for species in the MCMCglmm
function. The pedigree
argument did not work for me, so I use ginverse
to specify the covariance structure of the random effect (i.e., the phylogenetic covariance structure).
# Load packages
library(phytools)
library(MCMCglmm)
# Generate data
phy <- pbtree(n=20)
dat <- fastBM(phy, nsim=12)
dat <- stack(data.frame(t(dat)))
colnames(dat) <- c("values", "species")
# Phylogenetic covariance structure of random effects
phy.inv <- inverseA(phy)$Ainv
# Fit model
fit <- MCMCglmm(values ~ 1, random=~species, data=dat, ginverse=list(species=phy.inv))