### R code from vignette source 'cohort-sol.rnw'
### Encoding: ISO8859-1

###################################################
### code chunk number 1: cohort-sol.rnw:33-43
###################################################
t <- 1
r <- 150/100000
rr <- 2
G <- factor( c("ctr","X") )
N <- c(8000,2000)
Y <- N * t
E <- Y * c(1,rr) * r
D <- rpois( 2, E )
# and print the results nicely
data.frame( G, N, Y, E, D )


###################################################
### code chunk number 2: cohort-sol.rnw:47-51
###################################################
rates <- D/Y
RR <- rates[2]/rates[1]
erf <- exp(1.96 * sqrt(sum(1/D)) )
round( c( RR, RR/erf, RR*erf, erf ), 3 )


###################################################
### code chunk number 3: cohort-sol.rnw:59-73
###################################################
t <- 3
r <- 150/100000
rr <- 2
G <- factor( c("ctr","X") )
N <- c(8000,2000)
Y <- N * t
E <- Y * c(1,rr) * r
D <- rpois( 2, E )
# and print the results nicely
data.frame( G, N, Y, E, D )
rates <- D/Y
RR <- rates[2]/rates[1]
erf <- exp(1.96 * sqrt(sum(1/D)) )
round( c( RR, RR/erf, RR*erf, erf ), 3 )


###################################################
### code chunk number 4: cohort-sol.rnw:82-96
###################################################
t <- 1
r <- 150/100000
rr <- 2
G <- factor( c("ctr","X") )
N <- c(6000,4000)
Y <- N * t
E <- Y * c(1,rr) * r
D <- rpois( 2, E )
# and print the results nicely
data.frame( G, N, Y, E, D )
rates <- D/Y
RR <- rates[2]/rates[1]
erf <- exp(1.96 * sqrt(sum(1/D)) )
round( c( RR, RR/erf, RR*erf, erf ), 3 )


###################################################
### code chunk number 5: cohort-sol.rnw:109-122
###################################################
sim <- function( t, N )
{
r <- 150/100000
rr <- 2
G <- factor( c("ctr","X") )
Y <- N * t
E <- Y * c(1,rr) * r
D <- rpois( 2, E )
rates <- D/Y
RR <- rates[2]/rates[1]
erf <- exp(1.96 * sqrt(sum(1/D)) )
c( RR, RR/erf, RR*erf, erf )
}


###################################################
### code chunk number 6: cohort-sol.rnw:126-127
###################################################
sim( t=1, N=c(8000,2000) )


###################################################
### code chunk number 7: cohort-sol.rnw:129-134
###################################################
rbind(
sim( t=1, N=c(8000,2000) ),
sim( t=2, N=c(8000,2000) ),
sim( t=3, N=c(8000,2000) ),
sim( t=4, N=c(8000,2000) ) )


###################################################
### code chunk number 8: cohort-sol.rnw:139-144
###################################################
rbind(
sim( t=2, N=c(8000,2000) ),
sim( t=2, N=c(7000,3000) ),
sim( t=2, N=c(6000,4000) ),
sim( t=2, N=c(5000,5000) ) )


