Skip to content

Instantly share code, notes, and snippets.

@explodecomputer
Last active August 29, 2015 14:13
Show Gist options
  • Save explodecomputer/ec7cf16f3ee9e9971fe0 to your computer and use it in GitHub Desktop.
Save explodecomputer/ec7cf16f3ee9e9971fe0 to your computer and use it in GitHub Desktop.
Estimate causal effect using two-sample MR
# SNP-disease association - need effect size and standard error, can use log(OR) instead of effect size
y_or <- 1.244
y_upperconf <- 1.375
y_lowerconf <- 1.126
y_eff <- log(y_or)
y_se <- (log(y_upperconf) - log(y_lowerconf)) / (2*1.96)
# Alternative method from Shinn 2000, but uncertain what scale this transforms to
# y_eff <- log(y_or) / 1.81
# y_se <- (log(y_upperconf) - log(y_lowerconf)) / (2*1.96) / 1.81
# SNP-exposure association - effect size and standard error
x_eff <- -1.00
x_se <- 0.06
# Are the effects estimated from the same sample?
sample_overlap <- 0
# Estimate the approx causal log(OR) of disease per unit change of exposure
wald.ratio <- y_eff / x_eff
# Standard error using delta method
ratio.se <- sqrt(y_se^2/x_eff^2 + (y_eff^2/x_eff^4) * x_se^2 - 2 * (y_eff/x_eff^3) * sample_overlap)
wald.ratio
ratio.se
# p-value (assuming sample size 1000?)
pt(wald.ratio / ratio.se, 1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment