This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use zip-merged.dta | |
svyset SDMVPSU [pw=WTINT2YR], stra(SDMVSTRA) | |
svy: zip malepartners RIDAGEYR i.RIDRETH1 DMDEDUC, infl(RIDAGEYR i.RIDRETH1 DMDEDUC) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nnot<-100 | |
ndis<-50 | |
tpr<-0.9 | |
fpr<-0.5 | |
rr<-replicate(100,{ | |
tpos <-rbinom(1,ndis,tpr) | |
fpos<-rbinom(1,nnot,fpr) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "Multiple response" | |
author: "Thomas Lumley" | |
date: "7/23/2019" | |
output: html_document | |
--- | |
```{r setup, include=FALSE} | |
knitr::opts_chunk$set(echo = TRUE) | |
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(AER) | |
svyivreg<-function(formula, design, ...) UseMethod("svyivreg",design) | |
svyivreg.survey.design<-function(formula, design){ | |
.data<-model.frame(design) | |
.data$.weights<-weights(design,"sampling") | |
model<- ivreg(formula, data=.data, weights=.weights) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## https://doi.org/10.1093/jssam/smz010 | |
make.s<-function(mu, sigma,tau2,alpha){ | |
g<-make.g(alpha) | |
invg<-make.ginv(alpha) | |
function(theta) invg(2*sigma*(theta-mu)/tau2) | |
} | |
make.g<-function(alpha){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## startup | |
library(jsonlite) | |
library(httr) | |
library(knitr) | |
library(kableExtra) | |
options(stringsAsFactors=FALSE) | |
## These two files are part of the static GTFS information | |
routes<-read.csv("./routes.txt") | |
routes$route_id<-substr(as.character(routes$route_id),1,5) ## remove versioning info |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## from: https://www.stats.govt.nz/information-releases/property-transfer-statistics-march-2019-quarter | |
re<-read.table(text= | |
"year quarter citbuy citsell resbuy ressell fornbuy fornsell corpbuy corpsell knowbuy knowsell unkbuy unksell total | |
2017 Mar 23592 23490 2130 1101 621 375 3060 4407 29406 29370 4287 4320 33690 | |
2017 Jun 30414 30678 3063 1512 930 486 4188 5946 38595 38625 450 426 39048 | |
2017 Sep 27123 27021 2703 1458 783 441 3618 5316 34230 34239 126 117 34356 | |
2017 Dec 28632 28125 2862 1491 1038 468 3663 6111 36195 36192 84 87 36279 | |
2018 Mar 25881 25947 2625 1401 1083 501 3255 4998 32841 32847 39 36 32880 | |
2018 Jun 31044 31173 3171 1656 1116 492 4281 6285 39606 39606 21 21 39627 | |
2018 Sep 28284 27684 2982 1557 717 378 3630 5997 35613 35613 21 21 35634 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
withPV<-function(mapping, design, action, ...) UseMethod("withPV",design) | |
withPV.survey.design<-function(mapping, design, action,...){ | |
if(inherits(mapping,"formula")) mapping<-list(mapping) | |
if (!is.list(mapping)) | |
stop("'mapping' must be a list of formulas") | |
if (!all(sapply(mapping, length)==3)) |