### R code from vignette source 'C:/Bendix/teach/NSCE/2022/pracs/cum-rates-sol.rnw'

###################################################
### code chunk number 1: cum-rates-sol.rnw:26-30
###################################################
RR <- (751/19365.4)/(797/30517.6)
SE <- sqrt( 1/751 + 1/797 )
erf <- exp( 1.96*SE )
round( c( RR, RR/erf, RR*erf ), 4 )


###################################################
### code chunk number 2: cum-rates-sol.rnw:36-47
###################################################
th <- matrix( c(
 0,   5,  572.1,  11, 1536.1,
20,  17, 1974.2,  16, 2449.1,
30,  58, 3489.0,  35, 4228.8,
40, 100, 4502.2,  67, 5822.3,
50, 184, 4433.5, 137, 6647.0,
60, 205, 2998.1, 211, 5780.3,
70, 137, 1134.4, 206, 3113.6,
80,  45,  261.5, 114,  939.8), ncol=5, byrow=TRUE )
colnames(th) <- c("age","D.th","Y.th","D.ct","Y.ct")
th


###################################################
### code chunk number 3: cum-rates-sol.rnw:51-53
###################################################
R.th <- th[,"D.th"]/th[,"Y.th"]
R.ct <- th[,"D.ct"]/th[,"Y.ct"]


###################################################
### code chunk number 4: cum-rates-sol.rnw:58-60
###################################################
ell <- c(20,rep(10,6),NA)
cbind( th[,"age"], ell, R.th, R.ct ) 


###################################################
### code chunk number 5: cum-rates-sol.rnw:66-70
###################################################
C70.th <- sum( (R.th*ell)[1:6] )
C70.ct <- sum( (R.ct*ell)[1:6] )
C80.th <- sum( (R.th*ell)[1:7] )
C80.ct <- sum( (R.ct*ell)[1:7] )


###################################################
### code chunk number 6: cum-rates-sol.rnw:74-76
###################################################
round( rbind( c( C70.th, C70.ct, C70.th/C70.ct ),
              c( C80.th, C80.ct, C80.th/C80.ct ) ), 3 )


###################################################
### code chunk number 7: cum-rates-sol.rnw:80-85
###################################################
Cmat <- rbind( c( C70.th, C70.ct, C70.th/C70.ct ),
               c( C80.th, C80.ct, C80.th/C80.ct ) )
rownames( Cmat ) <- c("cr.70","cr.80")
colnames( Cmat ) <- c("Thorotrast","Controls","Ratio")
round( Cmat, 2 )


###################################################
### code chunk number 8: cum-rates-sol.rnw:102-103
###################################################
cbind( th[,"age"], R.th/R.ct )


