Skip to content

Instantly share code, notes, and snippets.

View pitakakariki's full-sized avatar

Peter Green pitakakariki

View GitHub Profile
@pitakakariki
pitakakariki / polls.r
Last active August 4, 2016 09:28
Code to generate an interactive SVG graph of NZ general election polling.
###
##
## --- New Zealand General Election Polling ---
##
## Plots polling data scraped from Wikipedia.
##
## - GAM -
##
## The smoothed curves are calculated using a generalised additive model (GAM). The
## smoothing parameter is estimated using cross-validation. This means that the curves
@pitakakariki
pitakakariki / gsi.R
Created July 25, 2012 02:11 — forked from dwinter/gsi.R
calculate gsi in R
#calculate Cummings et al (2008) _gsi_ - a meaure of the exlusivity of a
#predefiend group of leaves in a phylogenetic tree
#example
#
# tr <- rtree(10)
# grp <- paste("t", 1:5, sep="")
# gsi(tr, grp)
@pitakakariki
pitakakariki / quote_test.r
Created October 18, 2012 04:44
Possible syntax highlighting bug.
x <- "\"Hello!\""
x <- '"Hello!"'
@pitakakariki
pitakakariki / gist:4195637ba88af198f01b
Last active September 23, 2015 05:14
Flag Referendum PRNG
f <- function(v=1000000, x=9, y=1) list(x=x, y=y, z=(v + 1000*(v %% 10)) %% 30323)
g <- function(x, y, z, rc) {
x <- (171 * x) %% 30269
y <- (172 * y) %% 30307
z <- (170 * z) %% 30323
rc <- ((10000 * x) %/% 30269) + ((10000 * y) %/% 30307) + ((10000 * x) %/% 30323)
@pitakakariki
pitakakariki / gist:0804719b45c50251db44
Created November 11, 2015 03:00
BSA Decision 2015-051
BSA
W Under The Broadcastin Act 1989
BROADCASTING STANDARDS Aumqmrv Between PETER GREEN
TE MANA WHANONGA KAIPAHO
Complainant
And MEDIAWORKS TV LTD
Broadcaster
Before
Peter Radich, Chair
Leigh Pearson
Decision No. 2015-087
Under The Broadcasting Act 1989
Between PETER GREEN
Complainant
And MEDIAWORKS RADIO LTD
Broadcaster
Before
Peter Radich, Chair
Te Raumawhitu Kupenga
Paula Rose
###
##
## --- New Zealand General Election Polling ---
##
## Plots polling data scraped from Wikipedia.
##
## - GAM -
##
## The smoothed curves are calculated using a generalised additive model (GAM). The
## smoothing parameter is estimated using cross-validation. This means that the curves
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
X <- data.frame(g=c('a', 'a', 'a', 'b', 'b', 'b'), x=c(1:3, 1:3), y=c(3,0,1,4,0,0))
ggplot(X, aes(x, y, fill=g)) + geom_col(pos='dodge')
ggplot(subset(X, y!=0), aes(x, y, fill=g)) + geom_col(pos='dodge')