Skip to content

Instantly share code, notes, and snippets.

View tslumley's full-sized avatar
😐

Thomas Lumley tslumley

😐
View GitHub Profile
@tslumley
tslumley / zip.Rmd
Created May 26, 2015 01:31
Zero-Inflated Poisson with complex surveys
---
title: "Zero-inflated Poisson from complex samples"
author: "Thomas Lumley"
date: "18 May 2015"
output: html_document
---
The Zero-Inflated Poisson model is a model for count data with excess zeros. The response distribution is a mixture of a point mass at zero and a Poisson distribution: if $Z$ is Bernoulli with probability $1-p_0$ and $P$ is Poisson with mean $\lambda$ then
$$Y=Z+(1-Z)P$$
is zero-inflated Poisson. The ZIP is a latent-class model; we can have $Y=0$ either because $Z=0$ or because $P=0$. That's natural in some ecological examples: if you didn't see any moose it could be because the area is moose-free (it's downtown Montréal) or because you just randomly didn't see any.
@tslumley
tslumley / README.md
Created March 29, 2015 21:49
Data from paper helicopter optimisation, George Box style

Data from two replicates of a 2^{5-1} fractional factorial experiment on paper helicopters

We used the helicopter template from the R SixSigma package. Our experimental factors were body height, wing length, paper type, paper size (A4 vs A5), and paperclip or not. The paperclip and size are interesting because they have a big effect on how the flight looks, but not a big effect on the flight time.

The experiments were performed at the Science Street Fair hosted by the Auckland Museum of Transportation and Technology (MOTAT), March 29, 2015. Replicate 1 was done in the morning; replicate 2 in the afternoon. The drop height was approximately 2.2m. Times are in seconds.

@tslumley
tslumley / hexmap.R
Created March 11, 2015 21:29
An exercise in transparency: unedited ugly scripts used in making electoral hexmaps.
fogmap=
" '..','..','..','..','..','..','..','..','..','..','..','..','..',
'..','69','..','..','..','..','..','35','63','..','..','..','..',
'..','..','67','..','..','..','..','..','45','..','..','..','..',
'..','..','65','71','..','..','..','15','11','33','..','..','..',
'..','..','68','66','..','..','..','..','55','34','..','..','..',
'..','70','..','..','..','..','..','53','01','49','..','..','..',
'..','..','..','..','..','..','..','21','27','12','26','38','..',
'..','..','..','..','..','..','..','31','28','24','03','..','..',
@tslumley
tslumley / Readme.md
Last active August 29, 2015 14:16
Electorate candidate donations, all parties, 2014

Election donations, New Zealand, 2014.

@tslumley
tslumley / moe
Created August 21, 2014 23:53
Margin of error in polls, based on actual percentage and allowing for design effects
moe = function(pct, N=1000, deff=c(1,2)){
p.L = function(x, n) {
ifelse (x == 0,0,qbeta(0.025, x, n - x + 1))
}
p.U = function(x, n) {
ifelse(x == n,1,qbeta(0.975, x + 1, n - x))
}
N = rep(N,length(pct))
lower = function(pct,deff){