Skip to content

Instantly share code, notes, and snippets.

View chrissyhroberts's full-sized avatar

Chrissy h Roberts (He/Him) chrissyhroberts

View GitHub Profile
@chrissyhroberts
chrissyhroberts / Media_File_Consent_LSHTM.xml
Created June 22, 2018 11:11
Consent form for use of media files (LSHTM Format) 2018-06-22 | Change public key to your own at base64RsaPublicKey= before use
@chrissyhroberts
chrissyhroberts / MICE_simple
Created June 20, 2018 23:54
Multiple imputation with MICE - very simple version for rough completion of a dataset (useful for things like doing a dirty PCA)
data(cars)
#make some missing values
cars[sample(1:50,size = 10),1]<-NA
cars[sample(1:50,size = 10),2]<-NA
require(mice)
#impute a bunch of data sets
cars.mice<-mice(cars,m=5,maxit=50,meth='pmm',seed=500)
@chrissyhroberts
chrissyhroberts / OR_Wald.R
Created June 16, 2018 20:23
Odds Ratio Wald Test
oddsratioWald.proc <- function(n00, n01, n10, n11, alpha = 0.05)
{
# Compute the odds ratio between two binary variables, x and y,
# as defined by the four numbers nij:
#
alpha<-0.05
# n00 = number of cases where x = 0 and y = 0
n00<-14
@chrissyhroberts
chrissyhroberts / ODKGPS.to.KML
Created May 29, 2018 16:13
R script to draw a KML/KMZ file from GPS data, calibrated to work on data collected with ODK Collect
#R script to make a KML file of GPS data points collected in ODK
library(sp)
library(rgdal)
#make some dummy data
lon<-c(-123.736597,6.263428,147.263399,83.263430,169.263481,7.736540,0.0)
lat<-c(21.04847,-66.04859,42.04850,66.04854,44.04862,50.04865,52.00000)
status<-c(1,1,1,1,2,2,2)
names<-c("Mid_Pacific_Off_Mexico","North_Of_Antarctica","East_Of_Hokkaido","North_Central_Russia","Suiko_Seamount","Bacharach_Germany","Barkaway_UK")
df<-data.frame(lon,lat,status,names)
######################################################
# SETTINGS
#
# You need to install a version of Java that has the Java Cryptography Extensions - see instructions here https://github.com/chrissyhroberts/ODK_TRAINING/blob/master/User_Guide.md
# URL of aggregate server [must include top level directory]
# This script requires one package dependency from package "getPass". This will be installed automatically if you don't have it.
# i.e. "https://test.odk.lshtm.ac.uk/test"
# USER NAME
# i.e. "chrissy"
# DECRYPTION PEM LOCATION : Please enter the full path to the decryption key
@chrissyhroberts
chrissyhroberts / HOTExport
Created May 2, 2018 12:46
Export MBTiles files from Open Street Map via Humanitarian Open Street Map export tool
Setting up ODK collect for use with offline maps
https://export.hotosm.org/
Sign up for an account
Describe the data set in tab 1.
In tab 2 select only “MBTiles”
In tab 3 choose the source “OpenStreetMap” and set zoom range to 1-14
In the map viewer, navigate to your region of interest.
@chrissyhroberts
chrissyhroberts / R_worldmap_political
Last active January 19, 2018 12:06
World map colour by country name
library(rworldmap)
theCountries<-read.table("Countries.txt",header=T,sep="\t")
# These are the ISO3 names of the countries you'd like to plot in red
malMap <- joinCountryData2Map(theCountries, joinCode = "ISO3",
nameJoinColumn = "ISO.ALPHA.3.Code")
# This will join your malDF data.frame to the country map data
library(reshape2)
library(ggplot2)
#make csv file as below
#name,start.date,end.date,WP
#Task 1,1,10,1
#Task 2,2,8,1
#Task 3,12,16,2
#Task 4,22,32,2
#Task 5,18,22,3
@chrissyhroberts
chrissyhroberts / snp_gene_overlaps
Created December 15, 2017 10:34
find overlap between some SNP locations and a list of gene locations
#find overlap between some SNP locations and a list of gene locations
#test SNPs
#df = snps
#chr start stop
#1 1232 1232
#2 12444 12444
#gene positions
@chrissyhroberts
chrissyhroberts / genetic_power_calc_case_control.R
Created October 26, 2017 14:09
Power calculations for genetic case control studies (based on R GAP package)
#power calculations for genetic case control study
#using gap package and pbsize2 command
#citation Jing Hua Zhao (2013). gap: Genetic Analysis Package. R package version 1.1-10.
#define study characteristics
require(gap)
prevalence=0.1
alpha=0.05