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
counts<-c(173,291,320,407,311,292,341,321,188) | |
times<-c(as.numeric(as.Date("2013-12-31")-as.Date("2013-4-1")),365,365,366,365,365,365,366,as.numeric(as.Date("2021-7-19")-as.Date("2021-1-1"))) | |
barplot(counts*365/times,width=times,col="royalblue",names=2013:2021,ylab="Assaults, scaled to /year",bg="white") | |
plot(2013:2021,counts*365/times,ylim=c(200,450),pch=19,col="royalblue",xlab="year",ylab="Assaults, scaled to /year",bg="white") | |
segments(2013:2021,(sqrt(counts)-1)^2*365/times, y1=(sqrt(counts)+1)^2*365/times,lty=3) | |
## from https://fyi.org.nz/request/16238/response/61990/attach/3/Kelly%20P%20IR%2001%2021%2023344%20Final%20Response.pdf |
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
pop<-matrix(0,102,102) | |
## uniform | |
vax<-matrix(rbinom(102*102,1,.83),102,102) | |
## vertical stripes | |
vax<-matrix(rep(c(0,1,1,1,1,1,1,0,1,1,1,1),length=102*102),102,102) | |
## high-risk square | |
#vax<-matrix(rbinom(102*102,1,.9),102,102); vax[1:41,1:42]<-rbinom(41*42,1,.5) |
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
expit<-function(eta) exp(eta)/(1+exp(eta)) | |
logit<-function(p) log(p/(1-p)) | |
one.sim<-function(beta, N=1000){ | |
pop<-data.frame(x=rnorm(50000)) | |
pop$y<-with(pop,rbinom(50000,1,expit(beta*x-3-beta))) | |
rval<-replicate(N,{ | |
cases<-which(pop$y==1) | |
controls<-sample(which(pop$y==0),length(cases)) |
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
Calendar year and month | Total | 00 to 04 | 05 to 09 | 10 to 14 | 15 to 19 | 20 to 24 | 25 to 29 | 30 to 34 | 35 to 39 | 40 to 44 | 45 to 49 | 50 to 54 | 55 to 59 | 60 to 64 | 65 to 69 | 70 to 74 | 75 to 79 | 80 to 84 | 85+ | year | month | date | ||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | 201701 | 801 | NA | 2 | 25 | 169 | 150 | 92 | 59 | 48 | 68 | 49 | 44 | 40 | 19 | 15 | 8 | 3 | 5 | 5 | 2017 | 1 | 2017-01-28 | |
2 | 201702 | 828 | NA | NA | 44 | 203 | 139 | 89 | 53 | 54 | 56 | 74 | 46 | 19 | 18 | 11 | 11 | 2 | 1 | 8 | 2017 | 2 | 2017-02-28 | |
3 | 201703 | 880 | NA | NA | 38 | 216 | 153 | 81 | 63 | 64 | 70 | 62 | 45 | 37 | 22 | 8 | 7 | 9 | 2 | 3 | 2017 | 3 | 2017-03-28 | |
4 | 201704 | 790 | NA | 2 | 40 | 182 | 162 | 96 | 69 | 33 | 45 | 38 | 51 | 24 | 22 | 9 | 8 | 1 | 4 | 4 | 2017 | 4 | 2017-04-28 | |
5 | 201705 | 915 | NA | 1 | 48 | 222 | 182 | 105 | 56 | 57 | 58 | 65 | 43 | 22 | 24 | 10 | 6 | 9 | 3 | 4 | 2017 | 5 | 2017-05-28 | |
6 | 201706 | 828 | NA | NA | 46 | 212 | 151 | 85 | 62 | 54 | 55 | 54 | 38 | 26 | 15 | 13 | 6 | 3 | 1 | 7 | 2017 | 6 | 2017-06-28 | |
7 | 201707 | 830 | NA | NA | 30 | 189 | 148 | 99 | 60 | 63 | 53 | 65 | 45 | 33 | 18 | 11 | 7 | 4 | 1 | 4 | 2017 | 7 | 2017-07-28 | |
8 | 201708 | 905 | NA | 1 | 64 | 233 | 151 | 103 | 64 | 55 | 51 | 67 | 35 | 29 | 25 | 14 | 4 | 2 | 3 | 4 | 2017 | 8 | 2017-08-28 | |
9 | 201709 | 868 | NA | NA | 35 | 231 | 143 | 98 | 80 | 55 | 56 | 54 | 48 | 22 | 15 | 13 | 10 | 4 | 1 | 3 | 2017 | 9 | 2017-09-28 |
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
Based on the `rimu` package, the start of an implementation of 'mr' objects using Hadley's `vctrs` package, so they can be used in tibbles. |
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
lagged<-function(x,lag=1){ | |
if (lag==0) return(x) | |
n<-length(x) | |
c(rep(NA,lag),x[-( (n-lag+1):n)]) | |
} | |
pdlweights<-function(lag,degree,tiedown=c(F,F)){ | |
if (any(tiedown)) stop("Tiedown not working") | |
contr.poly(lag,contrasts=F)[,tiedown[1]+(1:degree)] |
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
mo day cancels | |
11 2 1806 | |
11 1 1846 | |
10 31 1887 | |
10 30 1276 | |
10 29 914 | |
10 28 1828 | |
10 27 1672 | |
10 26 1686 | |
10 25 1845 |
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
olr_brant_test<-function(formula, design,test=c("brant-original","omnidirectional-Wald")){ | |
test<-match.arg(test) | |
m1<-svyolr(formula, design = design) | |
K<-length(m1$lev) | |
P<-length(m1$coef) | |
get_infl<-function(k,formula,design){ | |
y<-formula[[2]] | |
formula[[2]]<-bquote(I(as.numeric(.(y))>.(k))) | |
mk<-svyglm(formula, design, family=quasibinomial, influence=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
Documentation | |
X: matrix of predictors (including the intercept) | |
y: matrix of outcomes | |
kinship: the kinship matrix (with 1s on the diagonal, not 2s) | |
pwt_mat: matrix of pairwise sampling weights (ie, reciprocal of pairwise sampling probabilities) | |
Output: | |
1. genetic variance divided by residual variance | |
2. residual variance |
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
void tille_incprob(double a[], int *pn, int *plen){ | |
double a_sum=0; | |
int i,n,len,l,l1; | |
n=*pn; | |
len=*plen; | |
for(i=0;i<len; i++){ | |
a_sum+=a[i]; | |
} |