library(Epi)
data(DMlate)
# A Lexis object for survival
Ldm <- Lexis(entry = list( per = dodm,
age = dodm-dobth,
tfd = 0 ),
exit = list( per = dox ),
exit.status = factor( !is.na(dodth), labels = c("DM","Dead") ),
data = DMlate[sample(1:nrow(DMlate),1000),] )
summary(Ldm, timeScales = TRUE)
# Cut at OAD and Ins times
Mdm <- mcutLexis(Ldm,
wh = c('dooad','doins'),
new.states = c('OAD','Ins'),
seq.states = FALSE,
ties = TRUE)
summary(Mdm$lex.dur)
# restrict to DM state and split
Sdm <- splitLexis(factorize(subset(Mdm, lex.Cst == "DM")),
time.scale = "tfd",
breaks = seq(0,20,1/12))
summary(Sdm)
summary(Relevel(Sdm, c(1, 4, 2, 3)))
boxes(Relevel(Sdm, c(1, 4, 2, 3)),
boxpos = list(x = c(15, 85, 80, 15),
y = c(85, 85, 20, 15)),
scale.R = 100)
# glm models for the cause-specific rates
system.time(
mD <- glm.Lexis(Sdm, ~ Ns(tfd, knots=0:6*2), to = 'Dead') )
system.time(
mO <- glm.Lexis(Sdm, ~ Ns(tfd, knots=0:6*2), to = 'OAD' ) )
system.time(
mI <- glm.Lexis(Sdm, ~ Ns(tfd, knots=0:6*2), to = 'Ins' ) )
# intervals for calculation of predicted rates
int <- 1 / 100
nd <- data.frame(tfd = seq(0, 10, int)) # not the same as the split,
# and totally unrelated to it
# cumulaive risks with confidence intervals
# (too few timepoints, too few simluations)
system.time(
res <- ci.Crisk(list(OAD = mO,
Ins = mI,
Dead = mD),
nd = data.frame(tfd = 0:100 / 10),
nB = 100,
perm = 4:1))
str(res)
Run the code above in your browser using DataLab