pkgs_available <-
requireNamespace("metafor", quietly = TRUE) &
requireNamespace("robumeta", quietly = TRUE)
if (pkgs_available) {
library(metafor)
data(oswald2013, package = "robumeta")
dat <- escalc(data = oswald2013, measure = "ZCOR", ri = R, ni = N)
subset_ids <- unique(dat$Study)[1:20]
dat <- subset(dat, Study %in% subset_ids)
# make a patterned correlation matrix
p_levels <- levels(dat$Crit.Cat)
r_pattern <- 0.7^as.matrix(dist(1:length(p_levels)))
diag(r_pattern) <- seq(0.75, 0.95, length.out = 6)
rownames(r_pattern) <- colnames(r_pattern) <- p_levels
# impute the covariance matrix using patterned correlations
V_list <- pattern_covariance_matrix(vi = dat$vi,
cluster = dat$Study,
pattern_level = dat$Crit.Cat,
r_pattern = r_pattern,
smooth_vi = TRUE)
# fit a model using imputed covariance matrix
MVFE <- rma.mv(yi ~ 0 + Crit.Cat, V = V_list,
random = ~ Crit.Cat | Study,
data = dat)
conf_int(MVFE, vcov = "CR2")
}
Run the code above in your browser using DataLab