### R code from vignette source 'Lexis-sol.rnw'
### Encoding: ISO8859-1

###################################################
### code chunk number 1: Lexis-sol.rnw:24-27
###################################################
library( Epi )
data( occup )
occup


###################################################
### code chunk number 2: Lexis-sol.rnw:31-37
###################################################
oL <- Lexis( entry = list( age=AoE, per=DoE ),
              exit = list(          per=DoX ),
      entry.status = factor( rep("W",nrow(occup)) ),
       exit.status = factor( Xst ),
              data = occup )
summary( oL )


###################################################
### code chunk number 3: Lexis-sol.rnw:43-46
###################################################
oL <- splitLexis( oL, time="age", breaks=seq(0,100,5) )
oL <- splitLexis( oL, time="per", breaks=seq(0,100,5)+1900 )
oL[order(oL$lex.id,oL$age),]


###################################################
### code chunk number 4: Lexis-sol.rnw:50-51
###################################################
table( timeBand(oL,"age","left"), timeBand(oL,"per","left"))


###################################################
### code chunk number 5: Lexis-sol.rnw:57-61
###################################################
FU <- with( oL, cbind(lex.Xst=="D",lex.dur) )
colnames(FU) <- c("D","Y")
Age    <- timeBand(oL,"age","left")
Period <- timeBand(oL,"per","left")


###################################################
### code chunk number 6: Lexis-sol.rnw:65-67
###################################################
FUtab <- xtabs( FU ~ Age + Period )
ftable(FUtab,col.vars=2:3)


###################################################
### code chunk number 7: Lexis-sol.rnw:73-79
###################################################
BC <- subset(oL,per-age>1902 & per-age<1912)
FU <- with( BC, cbind(lex.Xst=="D",lex.dur) )
colnames(FU) <- c("D","Y")
Age   <- timeBand(BC,"age","left")
FUctab <- xtabs( FU ~ Age )
FUctab


###################################################
### code chunk number 8: Lexis-sol.rnw:88-89
###################################################
sum(FUctab[,1]/FUctab[,2]*5)


###################################################
### code chunk number 9: Lexis-sol.rnw:104-108
###################################################
p.rates <- data.frame( rate=c(100,200,400), Age=c(40,45,50) )
oL$Age <- timeBand(oL,"age","left")
oL <- merge(oL,p.rates)
oL


###################################################
### code chunk number 10: Lexis-sol.rnw:111-114
###################################################
O <- with( oL, sum( lex.Xst=="D" ) )
E <- with( oL, sum( lex.dur*rate/10^5 ) )
c( O, E, O/E )


