Skip to content

Instantly share code, notes, and snippets.

View tslumley's full-sized avatar
😐

Thomas Lumley tslumley

😐
View GitHub Profile
@tslumley
tslumley / multiresponse.Rmd
Created July 23, 2019 04:00
Some ideas towards a multiple-response class
---
title: "Multiple response"
author: "Thomas Lumley"
date: "7/23/2019"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
@tslumley
tslumley / cars.R
Last active November 6, 2019 02:02
Glyph maps for NZ District Health Boards
d<-strsplit("Northland
No Motor Vehicle 3792 4077
One Motor Vehicle 20229 22161
Two Motor Vehicles 19578 20652
Three or More Motor Vehicles 7398 7407
Waitemata
No Motor Vehicle 8871 8658
One Motor Vehicle 54753 57492
Two Motor Vehicles 66411 72768
Three or More Motor Vehicles 29757 33219
@tslumley
tslumley / assoc.R
Last active November 10, 2019 02:58
Associative transformation of ggplot
setClass("ggthing", representation(content="call"))
setClass("ggthings",representation(contents="list"))
bracket<-function(e1) NULL
setGeneric("bracket")
setMethod("bracket",c("ggthing"),
function(e1){
new("ggthings",contents=list(e1@content))
@tslumley
tslumley / proflike.R
Created July 7, 2020 01:22
Profile likelihood for 'balanced accuracy'
nnot<-100
ndis<-50
tpr<-0.9
fpr<-0.5
rr<-replicate(100,{
tpos <-rbinom(1,ndis,tpr)
fpos<-rbinom(1,nnot,fpr)
@tslumley
tslumley / svgam-example.do
Created July 20, 2020 03:55
Examples for svy VGAMs
use zip-merged.dta
svyset SDMVPSU [pw=WTINT2YR], stra(SDMVSTRA)
svy: zip malepartners RIDAGEYR i.RIDRETH1 DMDEDUC, infl(RIDAGEYR i.RIDRETH1 DMDEDUC)
@tslumley
tslumley / polls.Rmd
Created July 27, 2020 02:17
Rmarkdown for 'rogue polls' post
---
title: "Rogue polls"
author: "Thomas Lumley"
date: "27/07/2020"
output: word_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
@tslumley
tslumley / proflike.R
Created August 5, 2020 06:02
Conditional profile likelihood for balanced accuracy
llprofci<-function(tpos,fpos,tneg,fneg){
ndis<-tpos+fneg
nnot<-tneg+fpos
lljoint<-function(a,d){
k<-length(a)
@tslumley
tslumley / svygofchisq.R
Created October 21, 2020 00:14
Chisquared goodness of fit test
svygofchisq<-function(formula, p, design,...){
means<-svytotal(formula, design,...)
rval<-chisq.test(means,p=p)
nm<-names(coef(means))
ncat<-length(coef(means))
means<-svycontrast(means, list(N=rep(1,ncat)), add=TRUE)
pN<-split(cbind(p,0*diag(p)), paste0("p_",nm))
names(pN)<-paste0("p_",nm)
means<-svycontrast(means, pN,add=TRUE)
for(i in 1:length(nm)){
@tslumley
tslumley / ma.R
Created May 23, 2021 02:25
Compute proportion vaccinated for MA
library(dplyr)
library(rlang)
ma<-read.csv("~/Downloads/weekly-covid-19-municipality-vaccination-report-5-20-2021 (1)/Age - municipality-Table 1.csv",skip=1)
ma %>%
mutate(pop = as.numeric(gsub(",","",Population)), vax=as.numeric(gsub(",","",Fully.vaccinated.individuals))) -> ma_all
ma_all %>%
filter(Age.Group %in% c("65-74 Years","75+ Years")) %>%
select(County,Town,Age.Group,pop,vax) %>%
group_by(County,Town) %>%
@tslumley
tslumley / DHB-vax.R
Last active July 24, 2021 04:55
Hexbins of NZ Covid vaccination
library(rvest)
library(dplyr)
library(DHBins)
a<-read_html("https://www.health.govt.nz/our-work/diseases-and-conditions/covid-19-novel-coronavirus/covid-19-data-and-statistics/covid-19-vaccine-data")
a %>%
html_node("body") %>%
xml2::xml_find_all("//table") %>% nth(n=3) %>%html_text() ->b
gsub("\t"""strsplit(b"\n")[[1]]fixed=TRUE)->d