"ape"
(Paradis et al 2004)
"MCMCglmm"
(Hadfield, 2010a)
Phenotypic data ("data_repeat.txt"
), Data frame containing the phenotypic data (with multiple measurement)
Phylogeny ("phylo.nex"
), Phylogeny file (NEXUS file)
Let's build up on the example from the last section by adding multiple measurements per species:
library(ape) library(MCMCglmm) phylo<-read.nexus("phylo.nex") data<-read.table("data_repeat.txt",header=TRUE) head(data)
## phen cofactor species phylo ## 1 107.42 11.224 sp_1 sp_1 ## 2 109.16 9.806 sp_1 sp_1 ## 3 91.89 10.308 sp_1 sp_1 ## 4 121.54 8.355 sp_1 sp_1 ## 5 105.32 11.855 sp_1 sp_1 ## 6 65.00 4.314 sp_2 sp_2
data$spec_mean_cf<-sapply(split(data$cofactor,data$phylo),mean)[data$phylo]
inv.phylo<-inverseA(phylo,nodes="TIPS",scale=TRUE) prior2<-list(G=list(G1=list(V=1,nu=0.02),G2=list(V=1,nu=0.02)), R=list(V=1,nu=0.02)) model_repeat1<-MCMCglmm(phen~spec_mean_cf,random=~phylo+species, family="gaussian",ginverse=list(phylo=inv.phylo$Ainv), prior=prior2,data=data,nitt=5000000,burnin=1000,thin=500)
summary(model_repeat1)
## ## Iterations = 1001:4999501 ## Thinning interval = 500 ## Sample size = 9998 ## ## DIC: 7187 ## ## G-structure: ~phylo ## ## post.mean l-95% CI u-95% CI eff.samp ## phylo 278 153 403 8804 ## ## ~species ## ## post.mean l-95% CI u-95% CI eff.samp ## species 24.4 8.48 41.7 9444 ## ## R-structure: ~units ## ## post.mean l-95% CI u-95% CI eff.samp ## units 65.8 59.5 72.3 9343 ## ## Location effects: phen ~ spec_mean_cf ## ## post.mean l-95% CI u-95% CI eff.samp pMCMC ## (Intercept) 38.32 23.02 54.50 9998 <1e-04 *** ## spec_mean_cf 5.10 4.89 5.29 9253 <1e-04 *** ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
data$within_spec_cf<-data$cofactor-data$spec_mean_cf
model_repeat2<-MCMCglmm(phen~spec_mean_cf+within_spec_cf, random=~phylo+species,family="gaussian", ginverse=list(phylo=inv.phylo$Ainv),prior=prior2,data=data, nitt=5000000,burnin=1000,thin=500)
summary(model_repeat2)
## ## Iterations = 1001:4999501 ## Thinning interval = 500 ## Sample size = 9998 ## ## DIC: 7189 ## ## G-structure: ~phylo ## ## post.mean l-95% CI u-95% CI eff.samp ## phylo 278 159 409 9998 ## ## ~species ## ## post.mean l-95% CI u-95% CI eff.samp ## species 24.4 8.3 41.7 9998 ## ## R-structure: ~units ## ## post.mean l-95% CI u-95% CI eff.samp ## units 65.8 59.3 72.4 9998 ## ## Location effects: phen ~ spec_mean_cf + within_spec_cf ## ## post.mean l-95% CI u-95% CI eff.samp pMCMC ## (Intercept) 38.3001 22.5414 53.8096 9998 <1e-04 *** ## spec_mean_cf 5.0988 4.8918 5.2982 9998 <1e-04 *** ## within_spec_cf -0.0576 -0.4284 0.3061 9998 0.75 ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
lambda <- model_repeat2$VCV[,'phylo']/ (model_repeat2$VCV[,'phylo']+model_repeat2$VCV[,'species']+ model_repeat2$VCV[,'units'])