Skip to content

Instantly share code, notes, and snippets.

@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

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.

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.

@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`
@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 / 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 / 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 / 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 / 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?

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")