#### let's prepare data for computing period method survivals
#### in case there are problems with dates, we first
#### convert to fractional years.
library(Epi)
x <- Lexis(data=sire, entry = list(fot=0, per=get.yrs(dg_date), age=dg_age),
exit=list(per=get.yrs(ex_date)), exit.status=status)
x2 <- splitMulti(x, breaks = list(fot=seq(0, 5, by = 3/12), per=c(2008, 2013)))
# equivalently:
x2 <- splitMulti(x, fot=seq(0, 5, by = 3/12), per=c(2008, 2013))
## using dates; note: breaks must be expressed as dates or days!
x <- Lexis(data=sire, entry = list(fot=0, per=dg_date, age=dg_date-bi_date),
exit=list(per=ex_date), exit.status=status)
BL <- list(fot = seq(0, 5, by = 3/12)*365.242199,
per = as.IDate(paste0(c(1980:2014),"-01-01")),
age = c(0,45,85,Inf)*365.242199)
x2 <- splitMulti(x, breaks = BL, verbose=TRUE)
## multistate (healty - sick - dead)
## pretend some observation never got cancer
set.seed(1L)
sire2 <- copy(sire)
sire2$status <- factor(sire2$status, levels = 0:2)
levels(sire2$status) <- c("healthy", "dead", "dead")
not_sick <- sample.int(nrow(sire2), 6000L, replace = FALSE)
sire2[not_sick, ]$dg_date <- NA
sire2[!is.na(dg_date) & status == "healthy", ]$status <- "sick"
xm <- Lexis(data=sire2, entry = list(fot=0, per=get.yrs(bi_date), age=0),
exit=list(per=get.yrs(ex_date)), exit.status=status)
xm2 <- cutLexis(xm, cut = get.yrs(xm$dg_date), timescale = "per", new.state = "sick")
xm2[xm2$lex.id == 6L, ]
xm2 <- splitMulti(xm2, breaks = list(fot = seq(0,150,25)))
xm2[xm2$lex.id == 6L, ]
Run the code above in your browser using DataLab