Skip to content

Instantly share code, notes, and snippets.

#===================================#
# GWAS Practical #
# iBSC Genomic Medicine #
# Lavinia Paternoster #
# 08/11/2018 #
#===================================#
# Run the GWAS without PCs but using the cleaned genetic data
@explodecomputer
explodecomputer / rscript.r
Last active December 18, 2020 12:38
Submitting multiple R jobs to bluecrystal 3 and 4
# Get the list of arguments passed to R
args <- commandArgs(T)
# Get the first argument, make it numeric because by default it is read as a string
job_id <- as.numeric(args[1])
# Print the argument
message("job number ", job_id)
@explodecomputer
explodecomputer / combinations.r
Last active October 14, 2018 14:36
combinations
n <- 5
a <- combn(c(1:(2*n)), 2)
b <- combn(1:ncol(a), n)
l <- list()
m <- list()
j <- 1
for(i in 1:ncol(b))
{
x <- a[, b[,i]]
if(!any(duplicated(c(x))))
@explodecomputer
explodecomputer / adjrsq.r
Last active October 9, 2018 09:07
Overfitting and adjusted r square
# How does adjusted r-square do with overfitting?
rm(list=ls())
set.seed(101)
library(ggplot2)
library(tidyr)
y <- rnorm(1000)
x <- matrix(rnorm(1000 * 1000), 1000, 1000)
@explodecomputer
explodecomputer / fix.r
Created September 27, 2018 16:18
fix 3
dat_3a$rsq.exposure <- with(dat_3a, 2 * beta.exposure^2 * eaf.exposure * (1-eaf.exposure))
dat_3a$rsq.outcome <- with(dat_3a, 2 * beta.outcome^2 * eaf.outcome * (1-eaf.outcome))
dat_3a$steiger_dir <- dat_3a$rsq.exposure > dat_3a$rsq.outcome
dat_3b$rsq.exposure <- with(dat_3b, 2 * beta.exposure^2 * eaf.exposure * (1-eaf.exposure))
dat_3b$rsq.outcome <- with(dat_3b, 2 * beta.outcome^2 * eaf.outcome * (1-eaf.outcome))
dat_3b$steiger_dir <- dat_3b$rsq.exposure > dat_3b$rsq.outcome
@explodecomputer
explodecomputer / hwe_sim.r
Created July 18, 2018 15:21
HWE simulations
---
title: Calculating HWE
---
Choose a set of parameters. For each allele frequency and sample size, run 100 simulations
```{r}
library(tidyr)
library(ggplot2)
library(dplyr)
@explodecomputer
explodecomputer / ewas_power.r
Last active July 5, 2018 17:36
EWAS power simulations
library(devtools)
install_github("explodecomputer/simulateGP")
library(simulateGP)
library(ggplot2)
param <- rbind(
expand.grid(
ncase=100,
ncontrol=100,
prev=0.001,
randomness <- function(x)
{
a <- (sum(x[-1] != x[-length(x)]) / (length(x)-1) - 0.5) * 2
return(round(a, 2))
}
make_dat <- function()
{
dat <- read.table("~/Desktop/ascii.txt", he=F, sep="\t", stringsAsFactors = FALSE, quote="", comment="")
names(dat) <- c("dec", "hex", "binary", "al")
dat$binary <- gsub("0", ".", dat$binary)
library(dplyr)
library(MeSH.db)
k <- keys(MeSH.db, keytype = "MESHID")
select(MeSH.db, keys = k[1:10], columns = c("MESHID", "MESHTERM"), keytype = "MESHID")
LEU <- select(MeSH.db, keys = "Leukemia", columns = c("MESHID", "MESHTERM", "CATEGORY", "SYNONYM"), keytype = "MESHTERM")
library("MeSH.AOR.db")
@explodecomputer
explodecomputer / causal-methods.md
Last active February 20, 2018 22:17
causal methods for ieu intranet

https://www.bris.ac.uk/integrative-epidemiology/intranet/training/

Causal methods

Introduction

In an epidemiological context, whether stated explicitly or not, we typically are referring to a counterfactual condition. A counterfactual condition is where we suppose that the outcome would not have happened in an alternate reality where all things were identical except for the exposure.

For example, if an individual had body mass index = 23 instead of body mass index = 27, but all else was identical, what would the impact be on their bone mineral density?