Skip to content

Instantly share code, notes, and snippets.

@explodecomputer
explodecomputer / cpg_outcome_scan.R
Created February 3, 2017 11:07
example of causal effect of all CpGs on outcome
# 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")
@explodecomputer
explodecomputer / sratti_power.R
Created February 1, 2017 17:09
s.ratti gwas power calculations
library(pwr)
library(ggplot2)
# calculate the minumum r2 that could be detected
r2 <- pwr.r.test(n=c(100,200), power=0.8, sig.level=0.05/100000)$r^2
#
dat <- expand.grid(
@explodecomputer
explodecomputer / simulate_sib_pairs.R
Last active February 9, 2017 11:24
simulate sib pairs
library(ggplot2)
library(reshape2)
makePhen <- function(effs, indep, vy=1, vx=rep(1, length(effs)))
{
if(is.null(dim(indep))) indep <- cbind(indep)
stopifnot(ncol(indep) == length(effs))
stopifnot(length(vx) == length(effs))
cors <- effs * vx / sqrt(vx) / sqrt(vy)
stopifnot(sum(cors^2) <= 1)
@explodecomputer
explodecomputer / simtools.r
Last active February 8, 2017 23:59
simulation tools
fastAssoc <- function(y, x)
{
index <- is.finite(y) & is.finite(x)
n <- sum(index)
y <- y[index]
x <- x[index]
vx <- var(x)
vy <- var(y)
bhat <- cov(y, x) / vx
@explodecomputer
explodecomputer / rg_pcs.Rmd
Last active January 11, 2017 12:07
Genetic correlations of phenotypic principal components
---
title: Simulations of estimating genetic correlations on phenotypic principal components
author: Gibran Hemani
date: "`r Sys.Date()`"
output:
pdf_document:
keep_tex: true
---
**To reproduce this analysis, code is available here:** [ https://gist.github.com/617a64134f74b3ee8eaba704b8949284 ]()
@explodecomputer
explodecomputer / gwas_meta_analysis.md
Created December 1, 2016 09:41
meta analysis chapter

Introduction

  • History and objectives of GWAS, inc motivation from heritability studies
  • Missing heritability and genetic architecture
  • Motivation for meta analysis
    • Data sharing problems
    • Comparison of meta vs mega analysis here?

Importance of imputation

@explodecomputer
explodecomputer / example.txt
Created November 18, 2016 15:51
example for tom
example code to share
@explodecomputer
explodecomputer / risk.R
Created November 17, 2016 21:14
risk, liability, heritability, prevalence
library(pROC)
library(ggplot2)
library(dplyr)
library(tidyr)
make_geno <- function(nid, nsnp, maf)
{
return(matrix(rbinom(nid * nsnp, 2, maf), nid, nsnp))
}
@explodecomputer
explodecomputer / test.txt
Created November 7, 2016 21:12
test.txt
lsls
@explodecomputer
explodecomputer / untitled
Created November 7, 2016 21:10
test atom
lsls