library( Epi )
library( survival )
data( DMlate )
# Lexis object of total follow-up
mL <- Lexis( entry = list(age=dodm-dobth,per=dodm),
exit = list(per=dox),
exit.status = factor(!is.na(dodth),labels=c("Alive","Dead")),
data = DMlate )
# Cut follow-up at start of insulin use
cL <- cutLexis( mL, cut = mL$doins,
timescale = "per",
new.state = "Ins",
precursor.states = "Alive" )
# Split follow-up on age-axis
system.time( sL <- splitLexis( cL, breaks=0:25*4, time.scale="age") )
# ( consider splitMulti from the popEpi package )
summary( sL )
# glm models for rates based on the time-split dataset by insulin and sex
# Proportional hazards model with insulin as time-dependent variable
# - uses the defaul of modeling all transitions from both transient
# states ("Alive" and "Ins") to the absorbing state ("Dead").
mt <- glm.Lexis( sL, ~ sex + lex.Cst + Ns(age,knots=c(15,3:8*10)) )
# prediction of mortality rates from "Alive" with and without PH assumption
nA <- data.frame( age=40:70, sex="M", lex.Cst="Alive" )
nI <- data.frame( age=40:70, sex="M", lex.Cst="Ins" )
matshade( nA$age, cbind( ci.pred(mt,nA),
ci.pred(mt,nI) )*1000, plot=TRUE,
lwd=3, lty=1, log="y", col=c("black","blue","red"),
xlab="Age", ylab="Mortality per 1000 PY" )
# gam models may take some time to run so we leave it out
if (FALSE) {
mt.gam <- gam.Lexis( sL, ~ sex + lex.Cst + s(age), to="Dead",
scale=1000 )
}
# Fit a Cox model for mortality with age as baseline time scale and
# insulin (lex.Cst) as time-dependent covariate
mt.cox <- coxph.Lexis( sL, age ~ sex + lex.Cst, c("Alive","Ins"), "Dead" )
# Pretty much the same results for regression paramters as the glm:
ci.exp( mt , subset="ex" )
# ci.exp( mt.gam, subset="ex" )
ci.exp( mt.cox, subset="ex" )
Run the code above in your browser using DataLab