Skip to content

Instantly share code, notes, and snippets.

@nelsonauner
Created January 24, 2015 15:42
Show Gist options
  • Save nelsonauner/0e5d623f6f6edabc0bb2 to your computer and use it in GitHub Desktop.
Save nelsonauner/0e5d623f6f6edabc0bb2 to your computer and use it in GitHub Desktop.
mosquitos and beer simulation
# Simulatation inference for the results of "Alcohol ingestion stimulates mosquito attraction" by O Shirai (2002)
# study url: http://www.ncbi.nlm.nih.gov/pubmed/12083361
# this gist based off (excellent) presentation by John Rauser at the Strata + Hadoop 2014 conference
# watch the presentation at https://www.youtube.com/watch?v=5Dnw46eC-0o
library(magrittr) # Ceci n'est pas un pipe
data = "27 21 20 22 21 15 26 12 27 21 31 16 24 19 19 15 23 24 24 19 28 23 19 13 24 22 29 20 20 24 17 18 31 20 20 22 25 28 21 27 21 18 20"
numbers <-
unlist(strsplit(data, split=" ")) %>% as.numeric
iter <- 1000000
# first 18 observations are beer, remaining observations are water
res <- replicate(n=iter, expr = {x = sample(numbers); return(mean(x[1:18])-mean(x[19:43]))})
hist(res,breaks=100,main="histogram of mean differences from resampling, n= 1M",xlab="mean difference")
# does this match a t distribution?
# (you might have to mess with t_scale for a good plot
t_scale <- 65000
lines(x=seq(-4,4,by=.01),
y = dt(seq(-4,4,by=.01),df=39.1)*t_scale,col="red",lwd=5)
# what are the confidence intervals?
sres <- sort(res)
sres[975000]
sres[25000]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment