Skip to content

Instantly share code, notes, and snippets.

@explodecomputer
explodecomputer / socks.r
Last active December 17, 2017 19:47
socks
---
title: The mystery of Nick's unpaired socks
Authors: The Balfour Road consortium
---
## Introduction
Nick has only 16 socks and none of them form a pair. There are several mechanisms that could give rise to his predicament. The most likely follows a scenario approximating the following.
Nick buys a pair of socks, and after some period of time, he loses one of the socks. Nick then buys another pair of socks, and eventually loses one of those too. And so on. If the time to loss of a single sock is Poissonly distributed with $\lambda$ time to event, then the expected amount of time taken to reach a situation with $n$ unpaired socks is simply $n\lambda$.
@explodecomputer
explodecomputer / winners_curse_confounding.r
Created December 15, 2017 17:41
the influence of exposure's winner's curse on the outcome with different amounts of confounding
# no confounder
run <- function(nsnp, nid, ueff, nsim, prop)
{
g <- matrix(rbinom(nsnp * nid, 2, 0.5), nid, nsnp)
vg <- apply(g, 2, var)
conf <- rnorm(nid)
res1 <- array(0, nsim)
res2 <- array(0, nsim)
@explodecomputer
explodecomputer / zscores.Rmd
Created November 22, 2017 18:03
z-score transformations
---
title: Converting Z scores to betas and log(OR)
author: Gibran Hemani, Philip Haycock
date: 22/11/2017
output: html_document
---
Use this formula to convert any effects and SE to the standardised scale:
```{r, echo=FALSE}
@explodecomputer
explodecomputer / linear_to_log.r
Created November 16, 2017 17:19
linear model to logistic
n <- 1000
nsim <- 100
res1 <- rep(0, nsim)
res2 <- rep(0, nsim)
res3 <- rep(0, nsim)
for(i in 1:nsim)
{
@explodecomputer
explodecomputer / setup.sh
Last active October 9, 2020 12:23
vm_setup.sh
#!/bin/bash
set -e
# Create shortcut to documents
echo "Creating shortcut to Documents"
cd /mnt/c/Users
un=`ls -dl */ | awk '{ print $9 }' | sed "s@/@@g" | grep -v Default | grep -v Public | grep -v defaultuser0 | head -n 1`

Using the Linux VM

Your computer's main operating system is Windows, but it has a 'virtual machine' running Linux Ubuntu.

What is a virtual machine? This is basically a simulation of a computer. The software 'VirtualBox' can simulate different operating systems. We're using a virtual machine to provide a Linux environment in which to perform the work required for this unit.

What is Linux Ubuntu? Linux is a basic operating system, but you can add various configurations or collections of software to give it different behaviours etc. These are then released as 'distributions'. There are many different Linux distributions, but Ubuntu is the most popular due to its relative similarity to Windows.

This guide will show you how to log on to the Linux virtual machine.

Setting up the Linux VM

This process should take 15-20 minutes.

Step 1. Install the virtual machine image

There is a file called Genomics Ubuntu VM.ova in the C:\temp folder. Double click it, it will open up VirtualBox and ask if you want to Import the Virtual Appliance. Click Import.

@explodecomputer
explodecomputer / subrealg.r
Created July 21, 2017 17:33
subreddit algebra
load("z_score_matrix.RData")
nom <- colnames(z_score_matrix)
nom <- do.call(rbind, strsplit(nom, split="\\|"))
colnames(z_score_matrix) <- nom[,1]
R <- cor(z_score_matrix, use="pair")^2
findrelsubreddit <- function(cursubs,curops,numret=20, mat=R) {
curvec = 0
# Get the GLGC data
system("wget http://csg.sph.umich.edu/abecasis/public/lipids2013/jointGwasMc_HDL.txt.gz")
# Get 1000 genomes frequencies
system("plink1.90 --bfile /panfs/panasas01/shared/alspac/studies/latest/alspac/genetic/variants/arrays/gwas/imputed/1000genomes/released/2015-10-30/data/derived/filtered/bestguess/maf0.01_info0.8/data_chr01 --freq --out chr1")
# Predict effect sizes and standard errors
@explodecomputer
explodecomputer / assortativemating.
Last active May 4, 2017 15:28
assortative mating
# Sample size
nid <- 2000
# Number of SNPs
nsnp <- 1000
# Variance explained by SNPs
varexp <- 0.8
# Effect sizes of SNPs