I have used code below to perform meta-analysis through loop in r
meta_results <- list()
meta_summaries_c <- list()
for (outcom in unique(df$outcom)) {
outcom_data <- df[df$outcom == outcom, ]
meta_result <- metagen(
TE = SMD,
seTE = seTE,
studlab = paste(study),
data = outcom_data,
sm = "SMD",
method.tau = "REML")
meta_results[[stage]] <- meta_result
}
meta_summaries_c[[outcom]] <- summary(meta_result)
print(meta_results)
I want to use my variables and some of outcomes that have more than five study for metaregression
here are my vars and outcoms
variables <- c("var1", "var2", "var3", "var4")
outcomes <- c("outcom1", "outcom2", "outcom3", "outcom4", "outcom5", "outcom6", "outcom7", "outcom8", "outcom9", "outcom10", "outcom11", "outcom12")
Now How can i run a loop through each outcom for each variable to perform metaregression using results of meta_summaries_c?
Perform meta-regression on meta-analysis results :
meta_regression_results <- list()
for (outcom in outcomes) {
if (outcom %in% names(meta_results)) {
meta_result <- meta_results[[outcom]]
outcom_data <- df[df$outcom == outcom, ]
# Loop through each variable for meta-regression
for (var in variables) {
# Perform meta-regression
meta_regression <- metareg(
meta_result,
formula = as.formula(paste(var, "~ 1")),
data = outcom_data
)
# Store results
meta_regression_results[[paste(outcom, var, sep = "_")]] <- meta_regression
}
}
}
# Print meta-regression results
print(meta_regression_results)
This approach ensures you explicitly control the outcomes used in the meta-analysis and meta-regression by specifying them in the outcomes vector.