{"data":{"slug":"github-aipoch-medical-research-skills-scientific-skills-data-analysis-meta-analysis-bae288e30c61","title":"Conduct Random-Effects Meta-Analysis with Forest and Funnel Plots","summary":"Perform quantitative synthesis of study results with pooled effect sizes, heterogeneity assessment, and publication bias detection. Deliverables include forest plots, funnel plots, and heterogeneity statistics (Q and I\u00b2).","url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-scientific-skills-data-analysis-meta-analysis-bae288e30c61","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-aipoch-medical-research-skills-scientific-skills-data-analysis-meta-analysis-bae288e30c61","markdown_url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-scientific-skills-data-analysis-meta-analysis-bae288e30c61.md","download_url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-scientific-skills-data-analysis-meta-analysis-bae288e30c61\/download","category":{"slug":"data-research","name":"Data & Research"},"editor_note":"Ensure study-level data is provided by the user or from tool results. Use Hedges' g for small-sample correction and log-transform ORs and RRs before pooling. Minimum 5-10 studies are required for reliable funnel plot interpretation.","instructions":"---\nname: meta-analysis\ndescription: Perform quantitative meta-analysis with effect size calculation, forest plots, funnel plots, and heterogeneity assessment. Use when: user asks to combine results from multiple studies, calculate pooled effect sizes, assess publication bias, or create forest\/funnel plots. NOT f...\nlicense: MIT\nauthor: AIPOCH\n---\n> **Source**: [https:\/\/github.com\/aipoch\/medical-research-skills](https:\/\/github.com\/aipoch\/medical-research-skills)\n\n\n# Meta-Analysis\n\nQuantitative synthesis of results from multiple studies. Calculates pooled effect sizes, assesses heterogeneity, detects publication bias, and generates forest and funnel plots.\n\n## When to Use\n\n- \"Combine these study results into a meta-analysis\"\n- \"Calculate the pooled odds ratio from these trials\"\n- \"Create a forest plot of these effect sizes\"\n- \"Test for publication bias with a funnel plot\"\n- \"What's the heterogeneity (I\u00b2) across these studies?\"\n- \"Run a random-effects meta-analysis\"\n\n## When NOT to Use\n\n- Designing a systematic review protocol (use systematic-review)\n- Searching for studies (use literature-search)\n- Single-study statistical analysis (use statsmodels-stats)\n- Narrative literature review (use paper-writing)\n\n## Effect Size Types\n\n| Outcome Type | Effect Size | Formula | Use When |\n|-------------|-------------|---------|----------|\n| Continuous | SMD (Cohen's d \/ Hedges' g) | $(M_1 - M_2) \/ S_p$ | Comparing means across studies with different scales |\n| Continuous | Mean Difference (MD) | $M_1 - M_2$ | Same outcome measure across all studies |\n| Binary | Odds Ratio (OR) | $(a \\times d) \/ (b \\times c)$ | Case-control studies, binary outcomes |\n| Binary | Risk Ratio (RR) | $(a\/(a+b)) \/ (c\/(c+d))$ | Cohort studies, clinical trials |\n| Binary | Risk Difference (RD) | $R_1 - R_2$ | Absolute risk reduction |\n| Time-to-event | Hazard Ratio (HR) | From Cox model | Survival analysis |\n| Correlation | Fisher's z | $0.5 \\ln((1+r)\/(1-r))$ | Correlation studies |\n\n## Core Analysis with Python\n\n### Random-Effects Meta-Analysis\n\n```python\nimport numpy as np\nfrom scipy import stats\n\ndef meta_analysis_random_effects(effects, variances, study_names=None):\n    \"\"\"\n    DerSimonian-Laird random-effects meta-analysis.\n\n    Args:\n        effects: array of effect sizes (log-OR, SMD, etc.)\n        variances: array of within-study variances\n        study_names: optional list of study labels\n\n    Returns:\n        dict with pooled estimate, CI, heterogeneity stats\n    \"\"\"\n    effects = np.array(effects, dtype=float)\n    variances = np.array(variances, dtype=float)\n    k = len(effects)\n\n    # Fixed-effect weights\n    w_fe = 1.0 \/ variances\n    pooled_fe = np.sum(w_fe * effects) \/ np.sum(w_fe)\n\n    # Cochran's Q\n    Q = np.sum(w_fe * (effects - pooled_fe) ** 2)\n    df = k - 1\n    p_heterogeneity = 1 - stats.chi2.cdf(Q, df)\n\n    # tau-squared (DerSimonian-Laird)\n    C = np.sum(w_fe) - np.sum(w_fe ** 2) \/ np.sum(w_fe)\n    tau2 = max(0, (Q - df) \/ C)\n\n    # I-squared\n    I2 = max(0, (Q - df) \/ Q * 100) if Q > 0 else 0\n\n    # Random-effects weights\n    w_re = 1.0 \/ (variances + tau2)\n    pooled_re = np.sum(w_re * effects) \/ np.sum(w_re)\n    se_pooled = np.sqrt(1.0 \/ np.sum(w_re))\n\n    ci_lower = pooled_re - 1.96 * se_pooled\n    ci_upper = pooled_re + 1.96 * se_pooled\n    z = pooled_re \/ se_pooled\n    p_value = 2 * (1 - stats.norm.cdf(abs(z)))\n\n    return {\n        'pooled_effect': pooled_re,\n        'se': se_pooled,\n        'ci_lower': ci_lower,\n        'ci_upper': ci_upper,\n        'z': z,\n        'p_value': p_value,\n        'tau2': tau2,\n        'I2': I2,\n        'Q': Q,\n        'Q_df': df,\n        'Q_p': p_heterogeneity,\n        'k': k,\n        'model': 'DerSimonian-Laird random-effects'\n    }\n```\n\n### Forest Plot\n\n```python\nimport matplotlib.pyplot as plt\nimport matplotlib.patches as mpatches\n\ndef forest_plot(effects, ci_lower, ci_upper, study_names, pooled, pooled_ci,\n                xlabel='Effect Size', title='Forest Plot', output_path='forest_plot.png'):\n    \"\"\"Generate a publication-quality forest plot.\"\"\"\n    k = len(effects)\n    fig, ax = plt.subplots(figsize=(8, max(4, k * 0.4 + 2)))\n\n    y_positions = list(range(k, 0, -1))\n\n    # Individual studies\n    for i, y in enumerate(y_positions):\n        ax.plot(effects[i], y, 'ks', markersize=8)\n        ax.plot([ci_lower[i], ci_upper[i]], [y, y], 'k-', linewidth=1.5)\n\n    # Pooled estimate (diamond)\n    diamond_y = 0\n    diamond_half_h = 0.3\n    diamond = plt.Polygon([\n        [pooled_ci[0], diamond_y],\n        [pooled, diamond_y + diamond_half_h],\n        [pooled_ci[1], diamond_y],\n        [pooled, diamond_y - diamond_half_h]\n    ], closed=True, facecolor='steelblue', edgecolor='black')\n    ax.add_patch(diamond)\n\n    # Reference line at null effect\n    ax.axvline(x=0, color='gray', linestyle='--', linewidth=0.8)\n\n    # Labels\n    yticks = y_positions + [diamond_y]\n    ylabels = study_names + ['Pooled']\n    ax.set_yticks(yticks)\n    ax.set_yticklabels(ylabels)\n    ax.set_xlabel(xlabel)\n    ax.set_title(title)\n    ax.set_ylim(-1, k + 1.5)\n\n    fig.tight_layout()\n    fig.savefig(output_path, dpi=300, bbox_inches='tight')\n    print(f\"Forest plot saved: {output_path}\")\n    return fig\n```\n\n### Funnel Plot (Publication Bias)\n\n```python\ndef funnel_plot(effects, se_values, pooled_effect,\n                xlabel='Effect Size', output_path='funnel_plot.png'):\n    \"\"\"Generate a funnel plot to assess publication bias.\"\"\"\n    fig, ax = plt.subplots(figsize=(6, 5))\n\n    ax.scatter(effects, se_values, c='black', s=30, zorder=3)\n\n    # Pseudo-confidence region\n    se_range = np.linspace(0.001, max(se_values) * 1.1, 100)\n    ci_low = pooled_effect - 1.96 * se_range\n    ci_high = pooled_effect + 1.96 * se_range\n    ax.fill_betweenx(se_range, ci_low, ci_high, alpha=0.1, color='gray')\n    ax.axvline(pooled_effect, color='red', linestyle='--', linewidth=1)\n\n    ax.set_xlabel(xlabel)\n    ax.set_ylabel('Standard Error')\n    ax.set_title('Funnel Plot')\n    ax.invert_yaxis()  # Convention: smaller SE at top\n\n    fig.tight_layout()\n    fig.savefig(output_path, dpi=300, bbox_inches='tight')\n    print(f\"Funnel plot saved: {output_path}\")\n    return fig\n```\n\n## Publication Bias Tests\n\n### Egger's Regression Test\n```python\ndef egger_test(effects, se_values):\n    \"\"\"Egger's test for funnel plot asymmetry.\"\"\"\n    precision = 1.0 \/ np.array(se_values)\n    standardized = np.array(effects) \/ np.array(se_values)\n    slope, intercept, r, p, se = stats.linregress(precision, standardized)\n    return {'intercept': intercept, 'se': se, 'p_value': p,\n            'interpretation': 'Significant asymmetry' if p < 0.10 else 'No significant asymmetry'}\n```\n\n### Begg's Rank Correlation Test\n```python\ndef begg_test(effects, variances):\n    \"\"\"Begg-Mazumdar rank correlation test.\"\"\"\n    standardized = effects \/ np.sqrt(variances)\n    tau, p = stats.kendalltau(standardized, variances)\n    return {'tau': tau, 'p_value': p}\n```\n\n### Trim-and-Fill Method\n- Identifies and imputes missing studies from funnel plot asymmetry\n- Re-estimates the pooled effect including imputed studies\n- Use `statsmodels` or `metafor` (R) for implementation\n\n## Heterogeneity Interpretation\n\n| I\u00b2 Value | Interpretation |\n|----------|---------------|\n| 0-25% | Low heterogeneity |\n| 25-50% | Moderate heterogeneity |\n| 50-75% | Substantial heterogeneity |\n| 75-100% | Considerable heterogeneity |\n\nWhen I\u00b2 > 50%, investigate sources:\n1. **Subgroup analysis**: Split by study design, population, intervention dose\n2. **Meta-regression**: Model effect size as function of study-level covariates\n3. **Sensitivity analysis**: Leave-one-out, exclude high risk-of-bias studies\n\n## Reporting Standards\n\nFollow PRISMA 2020 for reporting meta-analyses. Include:\n1. Number of studies (k) and total participants (N)\n2. Pooled effect size with 95% CI\n3. Heterogeneity: Q statistic (df, p), I\u00b2, tau\u00b2\n4. Model type: fixed-effect vs. random-effects with justification\n5. Publication bias assessment results\n6. Forest plot and funnel plot as figures\n\n## Best Practices\n\n1. Use random-effects model by default (studies rarely share a true common effect)\n2. Always report both Q and I\u00b2 for heterogeneity\n3. Log-transform ORs and RRs before pooling; back-transform for reporting\n4. Use Hedges' g rather than Cohen's d for small-sample correction\n5. Minimum 5-10 studies for reliable funnel plot interpretation\n6. Never fabricate study data or effect sizes\n\n## Zero-Hallucination Rule\n\n- ALL study-level data must come from tool results or user-provided data\n- NEVER generate fictional study names, sample sizes, or effect sizes\n- If insufficient data for meta-analysis, say so explicitly\n\n## Input Validation\n\nThis skill accepts requests that match the documented purpose of `meta-analysis` and include enough context to complete the workflow safely.\n\nDo not continue the workflow when the request is out of scope, missing a critical input, or would require unsupported assumptions. Instead respond:\n\n> `meta-analysis` only handles its documented workflow. Please provide the missing required inputs or switch to a more suitable skill.\n","use_cases":["Combine these study results into a meta-analysis","Calculate the pooled odds ratio from these trials","Create a forest plot of these effect sizes","Test for publication bias with a funnel plot","What's the heterogeneity (I\u00b2) across these studies?","Run a random-effects meta-analysis"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/aipoch\/medical-research-skills\/blob\/686e09dfdb45d9fa1a08664f06bb93769b3c9d91\/scientific-skills\/Data%20Analysis\/meta-analysis\/SKILL.md","source_commit":"686e09dfdb45d9fa1a08664f06bb93769b3c9d91","license":"MIT","version":null,"listing_approved_at":"2026-11-24","created_at":"2026-11-23T11:52:27.000000Z","updated_at":"2026-11-24T07:14:56.000000Z","seo_title":"Conduct Random-Effects Meta-Analysis with Forest and Funnel Plots","seo_description":"Quantitative synthesis of study results with pooled effect sizes, heterogeneity assessment, and publication bias detection.","seo_keywords":["meta-analysis forest plot","random-effects meta-analysis","publication bias funnel plot","pooled effect size calculation","heterogeneity assessment","effect size synthesis"]}}