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 / polynomial_fits.R
Created October 11, 2017 15:08
Polynomial fits : Run a set of polynomial mode (order 1-4) on some x vs y data.
#Run a set of polynomial models on some x vs y data.
#create a data set x and y
x<-1:1100
y<-sqrt(x^6+x/x^4)+x/x^x
#Define function to run models
polyfit<-function(x,order,raw=TRUE)
{
fit<-lm(y~poly(x,order,raw=raw))
@chrissyhroberts
chrissyhroberts / Platemap_96
Created October 12, 2017 15:44
#draws a 96 cell grid and adds some data to the cells : useful for drawing plate maps for 96 well laboratory plates
#draws a 96 cell grid in R and adds some data to the cells : useful for drawing plate maps for 96 well laboratory plates
title="PLATE X"
values<-paste(c("A","B","C"),1:3,sep="\n")
verticals<-c(rep(7.5,12),rep(6.5,12),rep(5.5,12),rep(4.5,12),rep(3.5,12),rep(2.5,12),rep(1.5,12),rep(0.5,12))
h2<-rep(seq(0.5,11.5,1),8)
#draw the grid
plot(c(0,12),c(0,8),pch=0,col="white",axes=FALSE,xlab="",ylab="")
abline(v=c(0:12))
require(season)
# use glm model in the first part, date can be full date or month (1-12),
res = cosinor(response~exposures+exposures2+exposures3, date=month, data=df,family=binomial(link='cloglog'),type = "monthly",cycles = 1)
summary(res)
plot(res)
@chrissyhroberts
chrissyhroberts / Diagnostic_evaluation_Power_Calculations.R
Created October 26, 2017 14:07
A power calculator for determining how many specimens you need to include in a population based diagnostic evaluation
#For the findings of the proposed study of diagnostic accuracy to be robust, we require a minimum number of infected and uninfected cases. The total number of samples required to accurately evaluate the diagnostic devices can be calculated4 using the formula
#p the expected sensitivity of the novel diagnostic
p<-0.99
# po is the minimum acceptable level of sensitivity
#pick one of these or use your own value(s)
po<-0.98
@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
@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
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 / 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
@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.
######################################################
# 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