### copy data into 'dat' and examine data
dat <- dat.moura2021$dat
head(dat)
if (FALSE) {
### load metafor package
library(metafor)
### load ape package
library(ape, warn.conflicts=FALSE)
### calculate r-to-z transformed correlations and corresponding sampling variances
dat <- escalc(measure="ZCOR", ri=ri, ni=ni, data=dat)
### copy tree to 'tree'
tree <- dat.moura2021$tree
### turn tree into an ultrametric one
tree <- compute.brlen(tree)
### compute phylogenetic correlation matrix
A <- vcv(tree, corr=TRUE)
### make copy of the species.id variable
dat$species.id.phy <- dat$species.id
### fit multilevel phylogenetic meta-analytic model
res <- rma.mv(yi, vi,
random = list(~ 1 | study.id, ~ 1 | effect.size.id, ~ 1 | species.id, ~ 1 | species.id.phy),
R=list(species.id.phy=A), data=dat)
res
### examine if spatial and/or temporal pooling of data tends to yield larger correlations
res <- rma.mv(yi, vi,
mods = ~ spatially.pooled * temporally.pooled,
random = list(~ 1 | study.id, ~ 1 | effect.size.id, ~ 1 | species.id, ~ 1 | species.id.phy),
R=list(species.id.phy=A), data=dat)
res
### estimated average correlation without pooling, when pooling spatially,
### when pooling temporally, and when pooling spatially and temporally
predict(res, newmods = rbind(c(0,0,0),c(1,0,0),c(0,1,0),c(1,1,1)), transf=transf.ztor, digits=2)
}
Run the code above in your browser using DataLab