# (1) randomized fictive survival data - right-censored
#
origdata <- data.frame(rbind(
c( 43.01, 55.00, 0),
c( 36.37, 47.17, 0),
c( 33.10, 34.51, 0),
c( 71.00, 81.15, 1),
c( 80.89, 81.91, 1),
c( 67.81, 78.48, 1),
c( 73.98, 76.92, 1),
c( 53.19, 54.80, 1)))
colnames(origdata) <- c("AgeIn", "AgeOut", "Death")
# add of follow-up time (for type = "right" in Surv())
origdata$followuptime <- origdata$AgeOut - origdata$AgeIn
origdata
### use of default survival type "right"
# in Surv()
survival::Surv(time = origdata$followuptime, event = origdata$Death, type = "right")
# for fitdistcens()
Surv2fitdistcens(origdata$followuptime, event = origdata$Death, type = "right")
# use of survival type "interval"
# in Surv()
survival::Surv(time = origdata$followuptime, time2 = origdata$followuptime,
event = origdata$Death, type = "interval")
# for fitdistcens()
Surv2fitdistcens(time = origdata$followuptime, time2 = origdata$followuptime,
event = origdata$Death, type = "interval")
# use of survival type "interval2"
origdata$survivalt1 <- origdata$followuptime
origdata$survivalt2 <- origdata$survivalt1
origdata$survivalt2[1:3] <- Inf
origdata
survival::Surv(time = origdata$survivalt1, time2 = origdata$survivalt2,
type = "interval2")
Surv2fitdistcens(origdata$survivalt1, time2 = origdata$survivalt2,
type = "interval2")
# (2) Other examples with various left, right and interval censored values
#
# with left censored data
(d1 <- data.frame(time = c(2, 5, 3, 7), ind = c(0, 1, 1, 1)))
survival::Surv(time = d1$time, event = d1$ind, type = "left")
Surv2fitdistcens(time = d1$time, event = d1$ind, type = "left")
(d1bis <- data.frame(t1 = c(2, 5, 3, 7), t2 = c(2, 5, 3, 7),
censtype = c(2, 1, 1, 1)))
survival::Surv(time = d1bis$t1, time2 = d1bis$t2,
event = d1bis$censtype, type = "interval")
Surv2fitdistcens(time = d1bis$t1, time2 = d1bis$t2,
event = d1bis$censtype, type = "interval")
# with interval, left and right censored data
(d2 <- data.frame(t1 = c(-Inf, 2, 3, 4, 3, 7), t2 = c(2, 5, 3, 7, 8, Inf)))
survival::Surv(time = d2$t1, time2 = d2$t2, type = "interval2")
Surv2fitdistcens(time = d2$t1, time2 = d2$t2, type = "interval2")
(d2bis <- data.frame(t1 = c(2, 2, 3, 4, 3, 7), t2 = c(2, 5, 3, 7, 8, 7),
censtype = c(2,3,1,3,3,0)))
survival::Surv(time = d2bis$t1, time2 = d2bis$t2,
event = d2bis$censtype, type = "interval")
Surv2fitdistcens(time = d2bis$t1, time2 = d2bis$t2,
event = d2bis$censtype, type = "interval")
Run the code above in your browser using DataLab