Created
February 3, 2017 11:07
-
-
Save explodecomputer/061df8fbff9a64ccbf4e02833983a121 to your computer and use it in GitHub Desktop.
example of causal effect of all CpGs on outcome
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
# Load libraries | |
library(TwoSampleMR) | |
library(MRInstruments) | |
# Load the ARIES mQTL catalog | |
data(aries_mqtl) | |
# Get the mQTLs from just one time point | |
cpglist <- subset(aries_mqtl, age == "Childhood") | |
# Remove duplicated SNPs | |
cpglist <- subset(cpglist, !duplicated(SNP)) | |
# Convert them into the format required for 2-sample MR | |
exposure_dat <- format_aries_mqtl(cpglist) | |
# Find the id of the outcome of interest | |
ao <- available_outcomes() | |
# e.g. BMI = 2 | |
# Get the CpG SNPs from the outcome | |
# From this point it could be very slow with 40k CpGs - might be better to split it up into smaller chunks | |
out <- extract_outcome_data(ex$SNP, c(2)) | |
# Harmonise the exposure and outcome data | |
dat <- harmonise_data(ex, out) | |
# Perform MR of each CpG on outcome data | |
res <- mr(dat, method_list=c("mr_meta_fixed")) | |
# Save the results | |
save(cpglist, out, dat, res, file="cpg_results.RData") | |
# Q-Q plot | |
library(GenABEL) | |
P <- subset(res, outcome == i)$pval | |
l <- estlambda(P) | |
j <- strsplit(i, split="\\|")[[1]][1] | |
nom <- paste(j, "\n", "number of tests = ", length(P), "\nlambda = ", round(l$estimate, 3), ", se = ", round(l$se, 3), sep="") | |
qq(P, main=nom) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment