View svygofchisq.R
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)){ |
View proflike.R
llprofci<-function(tpos,fpos,tneg,fneg){ | |
ndis<-tpos+fneg | |
nnot<-tneg+fpos | |
lljoint<-function(a,d){ | |
k<-length(a) |
View polls.Rmd
--- | |
title: "Rogue polls" | |
author: "Thomas Lumley" | |
date: "27/07/2020" | |
output: word_document | |
--- | |
```{r setup, include=FALSE} | |
knitr::opts_chunk$set(echo = TRUE) | |
``` |
View svgam-example.do
use zip-merged.dta | |
svyset SDMVPSU [pw=WTINT2YR], stra(SDMVSTRA) | |
svy: zip malepartners RIDAGEYR i.RIDRETH1 DMDEDUC, infl(RIDAGEYR i.RIDRETH1 DMDEDUC) |
View proflike.R
nnot<-100 | |
ndis<-50 | |
tpr<-0.9 | |
fpr<-0.5 | |
rr<-replicate(100,{ | |
tpos <-rbinom(1,ndis,tpr) | |
fpos<-rbinom(1,nnot,fpr) |
View assoc.R
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)) |
View cars.R
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 |
View multiresponse.Rmd
--- | |
title: "Multiple response" | |
author: "Thomas Lumley" | |
date: "7/23/2019" | |
output: html_document | |
--- | |
```{r setup, include=FALSE} | |
knitr::opts_chunk$set(echo = TRUE) | |
``` |
View svyivreg.R
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) |
View hoffci.R
## 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){ |
NewerOlder