Last active
December 5, 2018 17:54
-
-
Save explodecomputer/5881d4f5c6fdccf31236225ac0ddcd19 to your computer and use it in GitHub Desktop.
comparing_packages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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