{"data":{"slug":"github-aipoch-medical-research-skills-scientific-skills-data-analysis-bio-causal-genomics-pleiotropy-detection-9d0fa2150343","title":"Detect and Correct Horizontal Pleiotropy in Mendelian Randomization","summary":"Detect and correct for horizontal pleiotropy in Mendelian randomization analyses using MR-PRESSO, MR-Egger regression, and Steiger filtering to validate causal inference results. The deliverable includes corrected causal estimates and outlier identification.","url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-scientific-skills-data-analysis-bio-causal-genomics-pleiotropy-detection-9d0fa2150343","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-aipoch-medical-research-skills-scientific-skills-data-analysis-bio-causal-genomics-pleiotropy-detection-9d0fa2150343","markdown_url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-scientific-skills-data-analysis-bio-causal-genomics-pleiotropy-detection-9d0fa2150343.md","download_url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-scientific-skills-data-analysis-bio-causal-genomics-pleiotropy-detection-9d0fa2150343\/download","category":{"slug":"data-research","name":"Data & Research"},"editor_note":"Ensure that the required R packages (MR-PRESSO, TwoSampleMR, MendelianRandomization) are installed and compatible with the versions specified (MR-PRESSO 1.0+, TwoSampleMR 0.5+). Verify that the input data includes columns for beta.exposure, beta.outcome, se.exposure, and se.outcome.","instructions":"---\nname: bio-causal-genomics-pleiotropy-detection\ndescription: Detect and correct for horizontal pleiotropy in Mendelian randomization analyses using MR-PRESSO for outlier removal, MR-Egger regression for directional pleiotropy, and Steiger filtering for variant directionality. Use when validating MR results, detecting pleiotropic instrum...\nlicense: MIT\nauthor: AIPOCH\n---\n> **Source**: [https:\/\/github.com\/aipoch\/medical-research-skills](https:\/\/github.com\/aipoch\/medical-research-skills)\n\n\n## Version Compatibility\n\nReference examples tested with: MR-PRESSO 1.0+, TwoSampleMR 0.5+\n\nBefore using code patterns, verify installed versions match. If versions differ:\n- R: `packageVersion(\"<pkg>\")` then `?function_name` to verify parameters\n\nIf code throws ImportError, AttributeError, or TypeError, introspect the installed\npackage and adapt the example to match the actual API rather than retrying.\n\n# Pleiotropy Detection\n\n**\"Check my MR results for pleiotropic bias\"** \u2192 Detect and correct for horizontal pleiotropy using outlier removal (MR-PRESSO), directional pleiotropy testing (MR-Egger intercept), and variant directionality filtering (Steiger) to validate causal inference results.\n- R: `MRPRESSO::mr_presso()` for global and distortion tests\n- R: `TwoSampleMR::mr_egger_regression()` for Egger intercept test\n\n## Overview\n\nHorizontal pleiotropy violates the exclusion restriction assumption of MR: instruments\naffect the outcome through pathways other than the exposure. Detecting and correcting\nfor pleiotropy is essential for valid causal inference.\n\nTypes of pleiotropy:\n- **Vertical** (mediated): Instrument -> exposure -> outcome (valid, not a problem)\n- **Horizontal** (direct): Instrument -> outcome bypassing exposure (violates MR assumptions)\n- **Balanced**: Pleiotropic effects cancel out (IVW still valid, Egger intercept ~0)\n- **Directional**: Pleiotropic effects are systematic (biases IVW, Egger detects this)\n\n## MR-PRESSO\n\n**Goal:** Detect and remove pleiotropic outlier instruments from an MR analysis.\n\n**Approach:** Run MR-PRESSO to test for global pleiotropy, identify individual outlier SNPs, test whether their removal changes the causal estimate (distortion test), and obtain a corrected estimate.\n\n```r\n# install.packages('remotes')\n# remotes::install_github('rondolab\/MR-PRESSO')\nlibrary(MRPRESSO)\n\n# Input: harmonized data from TwoSampleMR\n# Columns needed: beta.exposure, beta.outcome, se.exposure, se.outcome\npresso_input <- data.frame(\n  bx = dat$beta.exposure,\n  by = dat$beta.outcome,\n  bxse = dat$se.exposure,\n  byse = dat$se.outcome\n)\n\n# --- Run MR-PRESSO ---\n# NbDistribution: Number of simulations for null distribution (minimum 1000)\n# SignifThreshold: P-value threshold for outlier detection (0.05 standard)\npresso_result <- mr_presso(\n  BetaOutcome = 'by', BetaExposure = 'bx',\n  SdOutcome = 'byse', SdExposure = 'bxse',\n  OUTLIERtest = TRUE, DISTORTIONtest = TRUE,\n  data = presso_input,\n  NbDistribution = 5000,\n  SignifThreshold = 0.05\n)\n\n# --- Global test ---\n# Tests whether there is any pleiotropy among instruments\n# Significant p-value: Evidence of horizontal pleiotropy\nglobal_p <- presso_result$`MR-PRESSO results`$`Global Test`$Pvalue\ncat('Global test p-value:', global_p, '\\n')\n\n# --- Outlier test ---\n# Identifies individual pleiotropic SNPs\noutliers <- presso_result$`MR-PRESSO results`$`Outlier Test`\ncat('\\nOutlier test results:\\n')\nprint(outliers)\n\n# Outlier SNPs (p < 0.05)\noutlier_indices <- which(outliers$Pvalue < 0.05)\ncat('Outlier SNPs:', length(outlier_indices), '\\n')\n\n# --- Distortion test ---\n# Tests whether removing outliers significantly changes the causal estimate\n# Significant: Outliers were meaningfully biasing the estimate\ndistortion_p <- presso_result$`MR-PRESSO results`$`Distortion Test`$Pvalue\ncat('Distortion test p-value:', distortion_p, '\\n')\n\n# --- Corrected estimate ---\n# MR estimate after removing outlier SNPs\nmain_results <- presso_result$`Main MR results`\ncat('\\nRaw IVW estimate:', main_results$`Causal Estimate`[1], '\\n')\ncat('Corrected IVW estimate:', main_results$`Causal Estimate`[2], '\\n')\n```\n\n## MR-Egger Diagnostics\n\n**Goal:** Test for directional pleiotropy and obtain a pleiotropy-adjusted causal estimate.\n\n**Approach:** Fit MR-Egger regression where the intercept estimates average pleiotropic bias, and check I-squared for instrument strength under the NOME assumption.\n\n```r\nlibrary(TwoSampleMR)\n\n# MR-Egger regression allows for a non-zero intercept\n# The intercept estimates the average pleiotropic effect\negger <- mr_egger_regression(dat$beta.exposure, dat$beta.outcome,\n                              dat$se.exposure, dat$se.outcome)\n\n# --- Egger intercept ---\n# Significant intercept (p < 0.05): Directional pleiotropy present\n# Non-significant: No evidence (but low power with < 10 SNPs)\ncat('Egger intercept:', round(egger$b_i, 5), '\\n')\ncat('Intercept SE:', round(egger$se_i, 5), '\\n')\ncat('Intercept p-value:', format.pval(egger$pval_i), '\\n')\n\n# --- Egger slope ---\n# Valid causal estimate EVEN with directional pleiotropy (InSIDE assumption)\ncat('\\nEgger causal estimate:', round(egger$b, 4), '\\n')\ncat('Egger SE:', round(egger$se, 4), '\\n')\ncat('Egger p-value:', format.pval(egger$pval), '\\n')\n\n# --- I-squared for Egger ---\n# I^2 measures instrument strength for MR-Egger specifically\n# I^2 > 0.9: Egger estimate reliable\n# I^2 < 0.6: Egger has low power, interpret with caution (NOME violation)\nisq <- Isq(dat$beta.exposure, dat$se.exposure)\ncat('\\nI-squared:', round(isq, 3), '\\n')\nif (isq < 0.9) cat('Warning: I-squared < 0.9; Egger estimate may be unreliable (NOME violation)\\n')\n```\n\n## Steiger Filtering\n\n**Goal:** Verify that instruments act in the correct causal direction (exposure -> outcome, not reverse).\n\n**Approach:** Apply the Steiger test to each instrument, remove those explaining more outcome variance than exposure variance, and re-run MR on filtered instruments.\n\n```r\nlibrary(TwoSampleMR)\n\n# Steiger test: Verify each instrument explains more variance in\n# the exposure than the outcome. Instruments failing this test\n# may act through a reverse causal pathway.\n\nsteiger <- steiger_filtering(dat)\n\n# Keep only correctly oriented instruments\ndat_steiger <- steiger[steiger$steiger_dir == TRUE, ]\ncat('Instruments passing Steiger filter:', nrow(dat_steiger), 'of', nrow(steiger), '\\n')\n\n# Re-run MR with filtered instruments\nresults_steiger <- mr(dat_steiger)\nprint(results_steiger[, c('method', 'nsnp', 'b', 'se', 'pval')])\n\n# Directionality test (aggregate)\ndirection <- directionality_test(dat)\ncat('\\nCorrect causal direction:', direction$correct_causal_direction, '\\n')\ncat('Steiger p-value:', format.pval(direction$steiger_pval), '\\n')\n```\n\n## Additional Sensitivity Methods\n\n```r\nlibrary(TwoSampleMR)\n\n# --- Contamination mixture ---\n# Assumes some instruments are valid, others are not\n# Does not require majority valid assumption\nmr_conmix <- mr(dat, method_list = 'mr_raps')\n\n# --- MR-RAPS ---\n# NOTE: MRAPS CRAN package was archived March 2025.\n# Use the MendelianRandomization package instead, or install from GitHub:\n# remotes::install_github('qingyuanzhao\/mr.raps')\nlibrary(MendelianRandomization)\n\nmr_input <- mr_input(\n  bx = dat$beta.exposure, bxse = dat$se.exposure,\n  by = dat$beta.outcome, byse = dat$se.outcome\n)\n\nraps_result <- mr_raps(mr_input)\ncat('MR-RAPS estimate:', raps_result$Estimate, '\\n')\ncat('MR-RAPS p-value:', raps_result$Pvalue, '\\n')\n\n# --- Multivariable MR ---\n# Controls for pleiotropy by including multiple exposures simultaneously\n# e.g., adjust for BMI when estimating effect of lipids on CHD\nexposure1 <- extract_instruments('ieu-a-300')  # LDL\nexposure2 <- extract_instruments('ieu-a-302')  # HDL\n\n# Combine and perform multivariable MR\n# (See TwoSampleMR vignette for full multivariable workflow)\n```\n\n## Comprehensive Sensitivity Framework\n\n**Goal:** Run a complete battery of MR sensitivity analyses to validate causal findings.\n\n**Approach:** Apply IVW, MR-Egger, weighted median, weighted mode, heterogeneity, Egger intercept, leave-one-out, and MR-PRESSO in a single function and summarize results.\n\n```r\nlibrary(TwoSampleMR)\nlibrary(MRPRESSO)\n\nrun_sensitivity <- function(dat) {\n  results <- list()\n\n  # 1. IVW (primary)\n  results$ivw <- mr(dat, method_list = 'mr_ivw')\n\n  # 2. MR-Egger\n  results$egger <- mr(dat, method_list = 'mr_egger_regression')\n\n  # 3. Weighted median (robust to 50% invalid instruments)\n  results$median <- mr(dat, method_list = 'mr_weighted_median')\n\n  # 4. Weighted mode\n  results$mode <- mr(dat, method_list = 'mr_weighted_mode')\n\n  # 5. Heterogeneity\n  results$het <- mr_heterogeneity(dat)\n\n  # 6. Egger intercept\n  results$pleio <- mr_pleiotropy_test(dat)\n\n  # 7. Leave-one-out\n  results$loo <- mr_leaveoneout(dat)\n\n  # 8. MR-PRESSO\n  presso_input <- data.frame(\n    bx = dat$beta.exposure, by = dat$beta.outcome,\n    bxse = dat$se.exposure, byse = dat$se.outcome\n  )\n  results$presso <- mr_presso(\n    BetaOutcome = 'by', BetaExposure = 'bx',\n    SdOutcome = 'byse', SdExposure = 'bxse',\n    OUTLIERtest = TRUE, DISTORTIONtest = TRUE,\n    data = presso_input, NbDistribution = 5000, SignifThreshold = 0.05\n  )\n\n  results\n}\n\nsummarize_sensitivity <- function(sens) {\n  cat('=== MR Sensitivity Analysis Summary ===\\n\\n')\n\n  # Method comparison\n  all_mr <- rbind(sens$ivw, sens$egger, sens$median, sens$mode)\n  cat('Method comparison:\\n')\n  print(all_mr[, c('method', 'b', 'se', 'pval')])\n\n  # Heterogeneity\n  cat('\\nHeterogeneity (Cochran Q):\\n')\n  cat('  Q p-value (IVW):', sens$het$Q_pval[sens$het$method == 'Inverse variance weighted'], '\\n')\n\n  # Egger intercept\n  cat('\\nEgger intercept:\\n')\n  cat('  Intercept:', sens$pleio$egger_intercept, '\\n')\n  cat('  P-value:', sens$pleio$pval, '\\n')\n\n  # MR-PRESSO global test\n  cat('\\nMR-PRESSO global test p-value:',\n      sens$presso$`MR-PRESSO results`$`Global Test`$Pvalue, '\\n')\n\n  cat('\\n--- Interpretation ---\\n')\n  cat('Consistent estimates across methods: Evidence strengthened\\n')\n  cat('Significant Egger intercept: Directional pleiotropy present\\n')\n  cat('Significant MR-PRESSO global: Horizontal pleiotropy detected\\n')\n  cat('Significant heterogeneity: Instruments may be invalid\\n')\n}\n```\n\n## STROBE-MR Reporting\n\nWhen reporting MR analyses, follow STROBE-MR guidelines:\n\n1. Report all MR methods tested (not just the most significant)\n2. Report heterogeneity Q-statistic and p-value\n3. Report Egger intercept with p-value\n4. Report MR-PRESSO global test and number of outliers removed\n5. Report F-statistics for instrument strength\n6. Report Steiger directionality test\n7. State whether results are consistent across sensitivity analyses\n8. Acknowledge limitations of the MR assumptions\n\n## Related Skills\n\n- mendelian-randomization - Primary MR analysis that pleiotropy tests validate\n- fine-mapping - Identify causal variants at instrument loci\n- population-genetics\/association-testing - GWAS data for MR instruments\n\n## Input Validation\n\nThis skill accepts requests that match the documented purpose of `bio-causal-genomics-pleiotropy-detection` 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> `bio-causal-genomics-pleiotropy-detection` only handles its documented workflow. Please provide the missing required inputs or switch to a more suitable skill.\n","use_cases":["Validate MR results for pleiotropic bias","Detect and correct for horizontal pleiotropy in genetic instruments","Assess directional pleiotropy using MR-Egger regression"],"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\/bio-causal-genomics-pleiotropy-detection\/SKILL.md","source_commit":"686e09dfdb45d9fa1a08664f06bb93769b3c9d91","license":"MIT","version":null,"listing_approved_at":"2026-11-24","created_at":"2026-11-23T11:01:15.000000Z","updated_at":"2026-11-24T07:14:40.000000Z","seo_title":"Detect Horizontal Pleiotropy in Mendelian Randomization","seo_description":"Detect and correct horizontal pleiotropy in Mendelian randomization analyses using MR-PRESSO, MR-Egger, and Steiger filtering for valid causal inference.","seo_keywords":["pleiotropy detection in MR","MR-PRESSO for pleiotropy","MR-Egger regression for pleiotropy","correct horizontal pleiotropy","validate causal inference MR"]}}