Skip to content

Instantly share code, notes, and snippets.

@explodecomputer
Last active December 5, 2018 17:54
Show Gist options
  • Save explodecomputer/5881d4f5c6fdccf31236225ac0ddcd19 to your computer and use it in GitHub Desktop.
Save explodecomputer/5881d4f5c6fdccf31236225ac0ddcd19 to your computer and use it in GitHub Desktop.
comparing_packages
library(TwoSampleMR)
library(RadialMR)
library(MendelianRandomization)
# Read in example data
a <- extract_instruments(2)
b <- extract_outcome_data(a$SNP, 7)
ab <- harmonise_data(a,b)
ab$SNP <- as.character(ab$SNP)
# IVW in TwoSampleMR package
TwoSampleMR::mr(ab, method_list="mr_ivw")
# IVW in MendelianRandomization package
ab2 <- dat_to_MRInput(ab)[[1]]
MendelianRandomization::mr_ivw(ab2)
# IVW in RadialMR package
ab3 <- format_radial(ab$beta.exposure, ab$beta.outcome, ab$se.exposure, ab$se.outcome, ab$SNP)
RadialMR::ivw_radial(ab3, weights=1)
RadialMR::ivw_radial(ab3, weights=2)
RadialMR::ivw_radial(ab3, weights=3)
# Manually do radial regression
w <- 1/ab$se.outcome^2
wr <- ab$beta.outcome / ab$beta.exposure
y <- wr * sqrt(wr)
x <- sqrt(w)
summary(lm(y ~ 0 + x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment