用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/brycewang-stanford/Auto-Empirical-Research-Skills --skill mediation-meta-analyst命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
Route empirical-research requests through the Auto-Empirical Research Skills catalog when this whole repository is installed as one skill in Codex, CodeBuddy, Claude Code, or another IDE. Use to choose and load the right vendored AERS skill for causal inference, econometrics, replication, data acquisition, manuscript writing, peer review and referee responses, citation checking, de-AIGC editing, or full empirical-paper workflows without reading the entire repository at once.
中英双语学术降 AIGC / bilingual academic de-AIGC skill. Removes AI-generated writing signatures from empirical papers in economics, management, and the social sciences — in both English and Chinese. Covers Turnitin AI, GPTZero, Originality.ai on the English side and 知网 AMLC, 万方, 维普 on the Chinese side. Uses a six-step loop (intake → audit → claim-evidence check → differentiated rewrite → five-dimension self-score → cold-reader recheck) with two pattern libraries (22 English + 17 Chinese patterns), section-by-section strategies for empirical papers, and hard protections that keep every number, coefficient, and citation intact.
Use when a research task needs reproducible Kaggle discovery, metadata inspection, bounded public-data downloads, competition or kernel discovery, model discovery, or an explicitly approved Kaggle write/delete operation through the official CLI.
基于 SOC 职业分类
正在显示 SKILL.md
| name | mediation-meta-analyst |
| description | Meta-analysis frameworks and methods for mediation studies |
Methods for synthesizing mediation effects across multiple studies
Use this skill when working on: meta-analysis of indirect effects, cross-study effect aggregation, heterogeneity assessment in mediation, individual participant data (IPD) meta-analysis, or systematic reviews of mediation studies.
| Challenge | Description | Solution Approach |
|---|---|---|
| Non-normal effects | Product $ab$ is not normally distributed | Use appropriate pooling methods |
| Correlated paths | $a$ and $b$ may be correlated | Model correlation structure |
| Heterogeneity | Effects vary across studies | Random effects models |
| Missing information | Studies report different statistics | Imputation or subset analysis |
| Publication bias | Small studies with null effects unpublished | Sensitivity analysis |
| Measure | Formula | Use Case |
|---|---|---|
| Unstandardized $ab$ | $a \times b$ | Same scales across studies |
| Partially standardized | $a \times b / SD_Y$ | Standardize by outcome only |
| Fully standardized | $a' \times b'$ (standardized coefficients) | Different scales |
| $R^2_{med}$ | Proportion of effect mediated | Bounded measure |
When assuming homogeneous true effects, the pooled estimate is:
$$\hat{\theta}_{FE} = \frac{\sum_i w_i \hat{\theta}_i}{\sum_i w_i}, \quad w_i = \frac{1}{\text{SE}_i^2}$$
This pooled estimate uses inverse-variance weights to optimally combine study-specific estimates.
When true effects vary across studies, the pooled estimate incorporates between-study variance:
$$\hat{\theta}_{RE} = \frac{\sum_i w_i^* \hat{\theta}_i}{\sum_i w_i^}, \quad w_i^ = \frac{1}{\text{SE}_i^2 + \hat{\tau}^2}$$
where $\hat{\tau}^2$ is the between-study variance (tau-squared). The pooled estimate under random effects provides a more generalizable result when heterogeneity is present.
Key statistics for assessing heterogeneity:
| Statistic | Formula | Interpretation |
|---|---|---|
| Q statistic | $Q = \sum_i w_i(\hat{\theta}_i - \hat{\theta})^2$ | Test for heterogeneity |
| I-squared ($I^2$) | $I^2 = \max(0, \frac{Q - (k-1)}{Q})$ | % variance due to heterogeneity |
| tau-squared ($\tau^2$) | Between-study variance | Absolute heterogeneity |
| H-squared | $H^2 = Q/(k-1)$ | Relative excess variance |
The I-squared statistic ranges from 0-100%: <25% indicates low heterogeneity, 25-75% moderate, and >75% high heterogeneity. The tau-squared provides the absolute magnitude of between-study variance.
#' Meta-Analysis of Indirect Effects
#'
#' @param effects Vector of indirect effect estimates
#' @param se Vector of standard errors
#' @param study_names Optional study identifiers
#' @param method "FE" for fixed effects, "RE" for random effects
#' @return Meta-analysis results
meta_indirect <- function(effects, se, study_names = NULL,
method = c("RE", "FE")) {
method <- match.arg(method)
k <- length(effects)
if (is.null(study_names)) {
study_names <- paste0("Study ", 1:k)
}
w_fe 1 se
theta_fe w_fe effects w_fe
Q w_fe effects theta_fe
df k
I2 Q df Q
w_fe w_fe w_fe
tau2 Q df
method
weights w_fe
pooled theta_fe
se_pooled w_fe
weights 1 se tau2
pooled weights effects weights
se_pooled weights
ci pooled se_pooled
p_het 1 pchisqQ df
pooled_effect pooled
se se_pooled
ci ci
z pooled se_pooled
p_value pnormpooled se_pooled
heterogeneity
Q Q
df df
p p_het
I2 I2
tau2 tau2
study_data data.frame
study study_names
effect effects
se se
weight weights weights
method method
When studies report both $a$ and $b$ paths:
$$\begin{pmatrix} \hat{a} \ \hat{b} \end{pmatrix} \sim N\left(\begin{pmatrix} a \ b \end{pmatrix}, \Sigma\right)$$
Stage 1: Extract path coefficients from each study Stage 2: Pool using multivariate random effects
#' Multivariate Meta-Analysis of Mediation Paths
#'
#' @param a_effects Vector of a path estimates
#' @param b_effects Vector of b path estimates
#' @param a_se Standard errors for a
#' @param b_se Standard errors for b
#' @param ab_cor Correlation between a and b estimates (often assumed 0)
#' @return Multivariate meta-analysis results
multivariate_meta_mediation <- function(a_effects, b_effects,
a_se, b_se, ab_cor = 0) {
library(metafor)
k <- length(a_effects)
# Construct variance-covariance matrices for each study
V_list <- lapply(1:k, function(i) {
cov_ab <- ab_cor * a_se[i] * b_se[i
matrixa_sei cov_ab cov_ab b_sei
yi rbinda_effects b_effects
vi unlistlapplyV_list as.vector
V bldiagV_list
effect_type k
study_id k each
fit rma.mvyi yi V V
mods effect_type
random effect_type study_id
struct
data data.frameyi effect_type study_id
pooled_a coeffit
pooled_b coeffit
vcov_pooled vcovfit
indirect pooled_a pooled_b
grad pooled_b pooled_a
se_indirect tgrad vcov_pooled grad
pooled_a pooled_a
pooled_b pooled_b
pooled_indirect indirect
se_indirect se_indirect
ci_indirect indirect se_indirect
model_fit fit
Pool all data and fit single model with study-level random effects:
#' IPD Meta-Analysis for Mediation
#'
#' @param data Combined dataset with study indicator
#' @param study_var Name of study variable
#' @param treatment Name of treatment variable
#' @param mediator Name of mediator variable
#' @param outcome Name of outcome variable
#' @return IPD meta-analysis results
ipd_meta_mediation <- function(data, study_var, treatment, mediator, outcome) {
library(lme4)
# Mediator model with random slopes
m_formula <- as.formula(paste(
mediator, "~", treatment, "+ (1 +", treatment, "|", study_var, ")"
))
m_model <- lmer(m_formula, data = data)
# Outcome model with random slopes
y_formula as.formulapaste
outcome treatment mediator
treatment mediator study_var
y_model lmery_formula data data
a fixefm_modeltreatment
b fixefy_modelmediator
c_prime fixefy_modeltreatment
indirect a b
boot_indirect replicate
boot_idx samplenrowdata replace
boot_data databoot_idx
m_boot tryCatch
lmerm_formula data boot_data
error e
y_boot tryCatch
lmery_formula data boot_data
error e
m_boot y_boot
fixefm_boottreatment fixefy_bootmediator
boot_indirect boot_indirectboot_indirect
pooled_a a
pooled_b b
pooled_c_prime c_prime
pooled_indirect indirect
pooled_total indirect c_prime
se_indirect sdboot_indirect
ci_indirect quantileboot_indirect
n_studies uniquedatastudy_var
n_total nrowdata
m_model m_model
y_model y_model
Estimate effects within each study, then pool:
#' Two-Stage IPD Meta-Analysis
#'
#' @param data Combined dataset
#' @param study_var Study identifier
#' @return Two-stage meta-analysis results
two_stage_ipd <- function(data, study_var, treatment, mediator, outcome) {
studies <- unique(data[[study_var]])
k <- length(studies)
# Stage 1: Study-specific estimates
study_results <- lapply(studies, function(s) {
study_data <- data[data[[study_var]] == s, ]
# Fit models
m_model <- lm(as.formula(paste(mediator, "~", treatment) data study_data
y_model lmas.formulapasteoutcome treatment mediator
data study_data
a coefm_modeltreatment
b coefy_modelmediator
se_a vcovm_modeltreatment treatment
se_b vcovy_modelmediator mediator
se_indirect a se_b b se_a
data.frame
study s
n nrowstudy_data
a a
b b
indirect a b
se_a se_a
se_b se_b
se_indirect se_indirect
study_df do.callrbind study_results
meta_result meta_indirect
effects study_dfindirect
se study_dfse_indirect
study_names study_dfstudy
method
stage1 study_df
stage2 meta_result
pooled_indirect meta_resultpooled_effect
ci meta_resultci
I2 meta_resultheterogeneityI2
| Method | Description | Limitation |
|---|---|---|
| Funnel plot | SE vs effect plot | Visual, subjective |
| Egger's test | Regression of effect on SE | Low power |
| Trim-and-fill | Impute missing studies | Assumes specific mechanism |
| PET-PEESE | Conditional regression | Requires assumptions |
| Selection models | Model publication process | Complex, sensitive |
#' Publication Bias Assessment for Mediation Meta-Analysis
#'
#' @param effects Indirect effect estimates
#' @param se Standard errors
#' @return Publication bias diagnostics
publication_bias_mediation <- function(effects, se) {
library(metafor)
# Fit random effects model
res <- rma(yi = effects, sei = se, method = "REML")
# Funnel plot data
funnel_data <- data.frame(
effect = effects,
se = se,
precision = 1/se
)
# Egger's test
egger <- regtest(res, model = "lm")
# Trim and fill
tf <- trimfill(res)
# PET-PEESE (if significant, use PEESE; otherwise PET)
pet <- lmeffects se weights se
peese lmeffects Ise weights se
pet_est coefpet
peese_est coefpeese
coefsummarypet
adjusted_estimate peese_est
method_used
adjusted_estimate pet_est
method_used
original_estimate coefres
egger_test
z eggerzval
p eggerpval
interpretation ifelseeggerpval
trim_fill
original_k resk
imputed_k tfk0
adjusted_estimate coeftf
adjusted_ci tfci.lb tfci.ub
pet_peese
pet_estimate pet_est
peese_estimate peese_est
method_used method_used
adjusted_estimate adjusted_estimate
funnel_data funnel_data
Test whether study-level characteristics explain heterogeneity:
#' Meta-Regression for Mediation Effects
#'
#' @param effects Indirect effect estimates
#' @param se Standard errors
#' @param moderators Data frame of moderator variables
#' @return Meta-regression results
meta_regression_mediation <- function(effects, se, moderators) {
library(metafor)
# Build formula from moderator names
mod_formula <- as.formula(paste("~", paste(names(moderators), collapse = " + ")))
# Fit mixed-effects meta-regression
res <- rma(yi = effects, sei = se,
mods = mod_formula,
data = moderators,
method = "REML")
# R^2 analog
res_null rmayi effects sei se method
R2 res_nulltau2 restau2 res_nulltau2
QE_test
QE resQE
df resk resp
p resQEp
coefficients coefsummaryres
tau2_residual restau2
I2_residual resI2
R2 R2
residual_heterogeneity QE_test
model res
#' Subgroup Analysis for Mediation Meta-Analysis
#'
#' @param effects Indirect effect estimates
#' @param se Standard errors
#' @param subgroup Factor variable defining subgroups
#' @return Subgroup analysis results
subgroup_analysis <- function(effects, se, subgroup) {
groups <- unique(subgroup)
# Within-group estimates
group_results <- lapply(groups, function(g) {
idx <- subgroup == g
meta_indirect(effects[idx], se[idx], method = "RE")
})
names(group_results) <- groups
# Extract pooled estimates
group_effects <- sapply(group_results, x xpooled_effect
group_se sapplygroup_results x xse
group_k sapplygroup_results x xstudy_dataeffect
overall meta_indirecteffects se method
Q_total overallheterogeneityQ
Q_within sapplygroup_results x xheterogeneityQ
Q_between Q_total Q_within
df_between groups
p_between 1 pchisqQ_between df_between
subgroup_estimates data.frame
subgroup groups
k group_k
effect group_effects
se group_se
ci_lower group_effects group_se
ci_upper group_effects group_se
test_for_differences
Q_between Q_between
df df_between
p p_between
interpretation ifelsep_between
group_results group_results
#' Create Forest Plot for Mediation Meta-Analysis
#'
#' @param meta_result Result from meta_indirect()
#' @return ggplot2 forest plot
forest_plot_mediation <- function(meta_result) {
library(ggplot2)
df <- meta_result$study_data
df$ci_lower <- df$effect - 1.96 * df$se
df$ci_upper <- df$effect + 1.96 * df$se
# Add pooled estimate
pooled <- data.frame(
study = "Pooled",
effect = meta_result$pooled_effect,
se = meta_result$se,
weight = NA,
ci_lower = meta_result$ci[1],
ci_upper = meta_result$ci[
df rbinddf pooled
dfstudy factordfstudy levels revdfstudy
ggplotdf aesx effect y study
geom_vlinexintercept linetype color
geom_pointaessize weight
geom_errorbarhaesxmin ci_lower xmax ci_upper height
geom_pointdata dfdfstudy
shape size color
labs
x
y
title
subtitle sprintf
meta_resultheterogeneityI2
meta_resultheterogeneitytau2
theme_minimal
themelegend.position
Version: 1.0.0 Created: 2025-12-09 Domain: Meta-analysis of mediation effects Applications: Systematic reviews, research synthesis, evidence aggregation