### R code from vignette source 'lifetable-sol.rnw'
### Encoding: UTF-8

###################################################
### code chunk number 1: lifetable-sol.rnw:2-7
###################################################
options( width=90,
#        prompt=" ", continue=" ", # Makes it easier for students to
                                   # copy from the final pdf document
         SweaveHooks=list( fig=function()
         par(mar=c(3,3,1,1),mgp=c(3,1,0)/1.6,las=1,bty="n") ) )


###################################################
### code chunk number 2: lifetable-sol.rnw:36-45
###################################################
N <- c(234, 207, 169, 129, 105,  85,  73,  62,  49, 34)
D <- c(24, 27, 31, 17, 7, 6, 5, 3, 2, 4)
L <- c( 3, 11, 9, 7,13, 6, 6, 10, 13, 6)
res <- cbind( N, D, L, N-L/2,
                    D/(N-L/2),
                  1-D/(N-L/2),
          cumprod(1-D/(N-L/2)) )
colnames(res)[4:7] <- c("eff.N","mort","surv","Surv")
round( res, 5 )


###################################################
### code chunk number 3: surv
###################################################
S <- cumprod(1-D/(N-L/2))
plot( 0:10, c(1,S), pch=16, type="b", 
      ylim=0:1, yaxs="i", 
      ylab="Survival", xlab="Time since diagnosis" )


