kmi/0000755000176200001440000000000013473051065011036 5ustar liggesuserskmi/tests/0000755000176200001440000000000013473042746012206 5ustar liggesuserskmi/tests/test.kmi.R0000755000176200001440000001512013301064335014055 0ustar liggesusersrequire(survival) require(kmi) ### test 1 id <- 1:10 time <- 1:10 ev <- c(0, 0, 0, rep(1, 3), rep(2, 4)) data <- data.frame(id, time, ev) aa <- kmi(Surv(time, ev != 0) ~ 1, data, etype = ev) bb <- aa$imputed.data test1 <- lapply(bb, function(x) { x[aa$original.data$id %in% 7:10, ] }) test1 <- do.call(rbind, test1) all(test1[, 1] == 11) all(test1[, 2] == 0) aa <- kmi(Surv(time, ev != 0) ~ 1, data, etype = ev, failcode = 2) bb <- aa$imputed.data test1 <- lapply(bb, function(x) { x[aa$original.data$id %in% 4:6, ] }) test1 <- do.call(rbind, test1) all(test1[, 1] == 11) all(test1[, 2] == 0) aa <- kmi(Surv(time, ev != 0) ~ 1, data, etype = ev, epsilon = 2) bb <- aa$imputed.data test1 <- lapply(bb, function(x) { x[aa$original.data$id %in% 7:10, ] }) test1 <- do.call(rbind, test1) all(test1[, 1] == 12) all(test1[, 2] == 0) aa <- kmi(Surv(time, ev != 0) ~ 1, data, etype = ev, nimp = 13) length(aa$imputed.data) == 13 ### test 2 set.seed(198740) time <- rexp(100) ev <- sample(c(0, 1, 2), 100, replace = TRUE) cov <- rbinom(100, 1, 0.5) dd <- data.frame(time, ev, cov) ## add a test when etype is a factor dd$status <- factor(ifelse(dd$ev == 0, "cens", ifelse(dd$ev == 1, "rel", "dc"))) set.seed(1440293) dat.kmi <- kmi(Surv(time, ev != 0) ~ 1, dd, etype = ev, nimp = 5) set.seed(1440293) dat.kmi.fact <- kmi(Surv(time, status != "cens") ~ 1, dd, etype = status, nimp = 5, failcode = "rel") set.seed(1440293) dat.kmi.mixed1 <- kmi(Surv(time, ev != 0) ~ 1, dd, etype = status, nimp = 5, failcode = "rel") set.seed(1440293) dat.kmi.mixed2 <- kmi(Surv(time, status != "cens") ~ 1, dd, etype = ev, nimp = 5, failcode = 1) fit.kmi <- cox.kmi(Surv(time, ev == 1) ~ cov, dat.kmi) fit.kmi.fact <- cox.kmi(Surv(time, status == "rel") ~ cov, dat.kmi) fit.kmi.mixed1 <- cox.kmi(Surv(time, status == "rel") ~ cov, dat.kmi.mixed1) fit.kmi.mixed2 <- cox.kmi(Surv(time, ev == 1) ~ cov, dat.kmi.mixed2) all.equal(coef(fit.kmi), coef(fit.kmi.fact)) all.equal(coef(fit.kmi), coef(fit.kmi.mixed1)) all.equal(coef(fit.kmi), coef(fit.kmi.mixed2)) all.equal(fit.kmi$variance, fit.kmi.fact$variance) all.equal(fit.kmi$variance, fit.kmi.mixed1$variance) all.equal(fit.kmi$variance, fit.kmi.mixed2$variance) ## fit.kmi ## summary(fit.kmi) ## fit.kmi.fact ## summary(fit.kmi.fact) ## avec bootstrap set.seed(867988) dat.kmib <- kmi(Surv(time, ev != 0) ~ 1, dd, etype = ev, nimp = 5, boot = TRUE, nboot = 5) set.seed(867988) dat.kmib.fact <- kmi(Surv(time, ev != 0) ~ 1, dd, etype = status, nimp = 5, boot = TRUE, nboot = 5, failcode = "rel") fit.kmib <- cox.kmi(Surv(time, ev == 1) ~ cov, dat.kmib) fit.kmib.fact <- cox.kmi(Surv(time, status == "rel") ~ cov, dat.kmib.fact) all.equal(coef(fit.kmib), coef(fit.kmib.fact)) fit.kmib fit.kmib.fact summary(fit.kmib) ### test 4 data(icu.pneu) set.seed(1313) dat <- kmi(Surv(start, stop, status) ~ 1, data = icu.pneu, etype = event, id= id, failcode = 2, nimp = 5) ### add a factor for testing purposes icu.pneu$ev.fact <- factor(ifelse(icu.pneu$event == 3, "disch", "death")) icu.pneu$ev <- icu.pneu$event icu.pneu$ev[icu.pneu$status == 0] <- 0 set.seed(1313) dat2 <- kmi(Surv(start, stop, ev != 0) ~ 1, data = icu.pneu, etype = ev, id= id, failcode = 2, nimp = 5) set.seed(1313) dat3 <- kmi(Surv(start, stop, status) ~ 1, data = icu.pneu, etype = ev.fact, id = id, failcode = "death", nimp = 5) a <- logical(5) for (i in 1:5) a[i] <- all.equal(dat$imputed.data[[i]][, 1], dat2$imputed.data[[i]][, 1]) a fit.kmi <- cox.kmi(Surv(start, stop, event == 2) ~ pneu, dat) fit.kmi2 <- cox.kmi(Surv(start, stop, ev == 2) ~ pneu, dat2) fit.kmi3 <- cox.kmi(Surv(start, stop, ev.fact == "death") ~ pneu, dat3) all.equal(fit.kmi$coefficients, fit.kmi2$coefficients) all.equal(coef(fit.kmi), coef(fit.kmi3)) all.equal(fit.kmi$variance, fit.kmi2$variance) fit.kmi fit.kmi2 fit.kmi3 ## avec bootstrap set.seed(598085) dat <- kmi(Surv(start, stop, status) ~ 1, data = icu.pneu, etype = event, id= id, failcode = 2, nimp = 5, boot = TRUE, nboot = 5) set.seed(598085) dat2 <- kmi(Surv(start, stop, ev != 0) ~ 1, data = icu.pneu, etype = ev, id= id, failcode = 2, nimp = 5, boot = TRUE, nboot = 5) set.seed(598085) dat3 <- kmi(Surv(start, stop, status) ~ 1, data = icu.pneu, etype = ev.fact, id = id, failcode = "death", nimp = 5, boot = TRUE, nboot = 5) a <- logical(5) for (i in 1:5) a[i] <- all.equal(dat$imputed.data[[i]][, 1], dat2$imputed.data[[i]][, 1]) a fit.kmi <- cox.kmi(Surv(start, stop, event == 2) ~ pneu, dat) fit.kmi2 <- cox.kmi(Surv(start, stop, ev == 2) ~ pneu, dat2) fit.kmi3 <- cox.kmi(Surv(start, stop, ev.fact == "death") ~ pneu, dat3) all.equal(fit.kmi$coefficients, fit.kmi2$coefficients) all.equal(coef(fit.kmi), coef(fit.kmi3)) all.equal(fit.kmi$variance, fit.kmi2$variance) fit.kmi fit.kmi2 fit.kmi3 ### with covariates ## classic set.seed(1) dd$juhu <- rnorm(nrow(dd)) set.seed(78223) imp.dd <- kmi(Surv(time, ev != 0) ~ juhu, dd, etype = ev, nimp = 5) set.seed(44889) imp.ddb <- kmi(Surv(time, ev != 0) ~ juhu, dd, nimp = 5, etype = ev, boot = TRUE, nboot = 5) summary(cox.kmi(Surv(time, ev == 1) ~ cov, imp.dd)) summary(cox.kmi(Surv(time, ev == 1) ~ cov, imp.ddb)) ## time-dependent covariates set.seed(9763) imp.dat.c <- kmi(Surv(start, stop, status) ~ age + sex, data = icu.pneu, etype = event, id = id, failcode = 2, nimp = 5) set.seed(19832) imp.dat.cb <- kmi(Surv(start, stop, status) ~ age + sex, data = icu.pneu, etype = event, id = id, failcode = 2, nimp = 5, boot = TRUE, nboot = 5) summary(cox.kmi(Surv(start, stop, event == 2) ~ pneu, imp.dat.c)) summary(cox.kmi(Surv(start, stop, event == 2) ~ pneu, imp.dat.cb)) ## Test ordering of the data set data(icu.pneu) icu.pneu$outcome <- with(icu.pneu, status * event) mydata1 <- icu.pneu[1:2, ] mydata2 <- icu.pneu[3:1421, ] ## page 221 set.seed(453) imp.dat <- kmi(Surv(start, stop, outcome != 0) ~ 1, data = icu.pneu, etype = outcome, id = id, failcode = 2, nimp = 10) ## page 222 kmi.sh.hap <- cox.kmi(Surv(start, stop, outcome == 2) ~ pneu, imp.dat) summary(kmi.sh.hap) newicu.pneu <- as.data.frame(rbind( mydata2, mydata1)) tail(newicu.pneu) set.seed(453) imp.datnew <- kmi(Surv(start, stop, outcome != 0) ~ 1, data = newicu.pneu, etype = outcome, id = id, failcode = 2, nimp = 10) # page 222 kmi.sh.hap <- cox.kmi(Surv(start, stop, outcome == 2) ~ pneu, imp.datnew) summary(kmi.sh.hap) kmi/tests/test.kmi.Rout.save0000644000176200001440000003226513473042625015560 0ustar liggesusers R version 3.6.0 (2019-04-26) -- "Planting of a Tree" Copyright (C) 2019 The R Foundation for Statistical Computing Platform: x86_64-apple-darwin18.5.0 (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > require(survival) Loading required package: survival > require(kmi) Loading required package: kmi > > ### test 1 > > id <- 1:10 > time <- 1:10 > ev <- c(0, 0, 0, rep(1, 3), rep(2, 4)) > data <- data.frame(id, time, ev) > > aa <- kmi(Surv(time, ev != 0) ~ 1, data, etype = ev) > > bb <- aa$imputed.data > test1 <- lapply(bb, function(x) { + x[aa$original.data$id %in% 7:10, ] + }) > test1 <- do.call(rbind, test1) > > all(test1[, 1] == 11) [1] TRUE > all(test1[, 2] == 0) [1] TRUE > > aa <- kmi(Surv(time, ev != 0) ~ 1, data, etype = ev, failcode = 2) > > bb <- aa$imputed.data > test1 <- lapply(bb, function(x) { + x[aa$original.data$id %in% 4:6, ] + }) > test1 <- do.call(rbind, test1) > > all(test1[, 1] == 11) [1] TRUE > all(test1[, 2] == 0) [1] TRUE > > aa <- kmi(Surv(time, ev != 0) ~ 1, data, etype = ev, epsilon = 2) > > bb <- aa$imputed.data > test1 <- lapply(bb, function(x) { + x[aa$original.data$id %in% 7:10, ] + }) > test1 <- do.call(rbind, test1) > > all(test1[, 1] == 12) [1] TRUE > all(test1[, 2] == 0) [1] TRUE > > aa <- kmi(Surv(time, ev != 0) ~ 1, data, etype = ev, nimp = 13) > length(aa$imputed.data) == 13 [1] TRUE > > > ### test 2 > > set.seed(198740) > time <- rexp(100) > ev <- sample(c(0, 1, 2), 100, replace = TRUE) > cov <- rbinom(100, 1, 0.5) > dd <- data.frame(time, ev, cov) > > ## add a test when etype is a factor > dd$status <- factor(ifelse(dd$ev == 0, "cens", ifelse(dd$ev == 1, "rel", "dc"))) > > set.seed(1440293) > dat.kmi <- kmi(Surv(time, ev != 0) ~ 1, dd, etype = ev, nimp = 5) > set.seed(1440293) > dat.kmi.fact <- kmi(Surv(time, status != "cens") ~ 1, dd, etype = status, + nimp = 5, failcode = "rel") > set.seed(1440293) > dat.kmi.mixed1 <- kmi(Surv(time, ev != 0) ~ 1, dd, etype = status, + nimp = 5, failcode = "rel") > set.seed(1440293) > dat.kmi.mixed2 <- kmi(Surv(time, status != "cens") ~ 1, dd, etype = ev, + nimp = 5, failcode = 1) > > > fit.kmi <- cox.kmi(Surv(time, ev == 1) ~ cov, dat.kmi) > fit.kmi.fact <- cox.kmi(Surv(time, status == "rel") ~ cov, dat.kmi) > fit.kmi.mixed1 <- cox.kmi(Surv(time, status == "rel") ~ cov, dat.kmi.mixed1) > fit.kmi.mixed2 <- cox.kmi(Surv(time, ev == 1) ~ cov, dat.kmi.mixed2) > > all.equal(coef(fit.kmi), coef(fit.kmi.fact)) [1] TRUE > all.equal(coef(fit.kmi), coef(fit.kmi.mixed1)) [1] TRUE > all.equal(coef(fit.kmi), coef(fit.kmi.mixed2)) [1] TRUE > all.equal(fit.kmi$variance, fit.kmi.fact$variance) [1] TRUE > all.equal(fit.kmi$variance, fit.kmi.mixed1$variance) [1] TRUE > all.equal(fit.kmi$variance, fit.kmi.mixed2$variance) [1] TRUE > > ## fit.kmi > > ## summary(fit.kmi) > > ## fit.kmi.fact > > ## summary(fit.kmi.fact) > > ## avec bootstrap > > set.seed(867988) > dat.kmib <- kmi(Surv(time, ev != 0) ~ 1, dd, etype = ev, nimp = 5, + boot = TRUE, nboot = 5) > set.seed(867988) > dat.kmib.fact <- kmi(Surv(time, ev != 0) ~ 1, dd, etype = status, nimp = 5, + boot = TRUE, nboot = 5, failcode = "rel") > > fit.kmib <- cox.kmi(Surv(time, ev == 1) ~ cov, dat.kmib) > fit.kmib.fact <- cox.kmi(Surv(time, status == "rel") ~ cov, dat.kmib.fact) > > all.equal(coef(fit.kmib), coef(fit.kmib.fact)) [1] TRUE > > fit.kmib Call: cox.kmi(formula = Surv(time, ev == 1) ~ cov, imp.data = dat.kmib) ***************** Pooled estimates: ***************** coef exp(coef) se(coef) t p cov -0.07328941 0.9293318 0.3126316 -0.2344274 0.8146571 > fit.kmib.fact Call: cox.kmi(formula = Surv(time, status == "rel") ~ cov, imp.data = dat.kmib.fact) ***************** Pooled estimates: ***************** coef exp(coef) se(coef) t p cov -0.07328941 0.9293318 0.3126316 -0.2344274 0.8146571 > > summary(fit.kmib) Call: cox.kmi(formula = Surv(time, ev == 1) ~ cov, imp.data = dat.kmib) ***************** Pooled estimates: ***************** coef exp(coef) se(coef) t Pr(>|t|) cov -0.07329 0.92933 0.31263 -0.234 0.815 exp(coef) exp(-coef) lower .95 upper .95 cov 0.9293 1.076 0.5035 1.715 > > > ### test 4 > > data(icu.pneu) > > set.seed(1313) > dat <- kmi(Surv(start, stop, status) ~ 1, data = icu.pneu, + etype = event, id= id, failcode = 2, nimp = 5) > > ### add a factor for testing purposes > icu.pneu$ev.fact <- factor(ifelse(icu.pneu$event == 3, "disch", "death")) > > icu.pneu$ev <- icu.pneu$event > icu.pneu$ev[icu.pneu$status == 0] <- 0 > > set.seed(1313) > dat2 <- kmi(Surv(start, stop, ev != 0) ~ 1, data = icu.pneu, + etype = ev, id= id, failcode = 2, nimp = 5) > > set.seed(1313) > dat3 <- kmi(Surv(start, stop, status) ~ 1, data = icu.pneu, + etype = ev.fact, id = id, failcode = "death", nimp = 5) > > a <- logical(5) > for (i in 1:5) a[i] <- all.equal(dat$imputed.data[[i]][, 1], dat2$imputed.data[[i]][, 1]) > a [1] TRUE TRUE TRUE TRUE TRUE > > fit.kmi <- cox.kmi(Surv(start, stop, event == 2) ~ pneu, dat) > > fit.kmi2 <- cox.kmi(Surv(start, stop, ev == 2) ~ pneu, dat2) > > fit.kmi3 <- cox.kmi(Surv(start, stop, ev.fact == "death") ~ pneu, dat3) > > all.equal(fit.kmi$coefficients, fit.kmi2$coefficients) [1] TRUE > all.equal(coef(fit.kmi), coef(fit.kmi3)) [1] TRUE > all.equal(fit.kmi$variance, fit.kmi2$variance) [1] TRUE > > fit.kmi Call: cox.kmi(formula = Surv(start, stop, event == 2) ~ pneu, imp.data = dat) ***************** Pooled estimates: ***************** coef exp(coef) se(coef) t p pneu1 1.10382 3.015664 0.2398608 4.60192 4.186147e-06 > > fit.kmi2 Call: cox.kmi(formula = Surv(start, stop, ev == 2) ~ pneu, imp.data = dat2) ***************** Pooled estimates: ***************** coef exp(coef) se(coef) t p pneu1 1.10382 3.015664 0.2398608 4.60192 4.186147e-06 > > fit.kmi3 Call: cox.kmi(formula = Surv(start, stop, ev.fact == "death") ~ pneu, imp.data = dat3) ***************** Pooled estimates: ***************** coef exp(coef) se(coef) t p pneu1 1.10382 3.015664 0.2398608 4.60192 4.186147e-06 > > ## avec bootstrap > > set.seed(598085) > dat <- kmi(Surv(start, stop, status) ~ 1, data = icu.pneu, + etype = event, id= id, failcode = 2, nimp = 5, + boot = TRUE, nboot = 5) > > set.seed(598085) > dat2 <- kmi(Surv(start, stop, ev != 0) ~ 1, data = icu.pneu, + etype = ev, id= id, failcode = 2, nimp = 5, + boot = TRUE, nboot = 5) > > set.seed(598085) > dat3 <- kmi(Surv(start, stop, status) ~ 1, data = icu.pneu, + etype = ev.fact, id = id, failcode = "death", nimp = 5, + boot = TRUE, nboot = 5) > > > a <- logical(5) > for (i in 1:5) a[i] <- all.equal(dat$imputed.data[[i]][, 1], dat2$imputed.data[[i]][, 1]) > a [1] TRUE TRUE TRUE TRUE TRUE > > fit.kmi <- cox.kmi(Surv(start, stop, event == 2) ~ pneu, dat) > > fit.kmi2 <- cox.kmi(Surv(start, stop, ev == 2) ~ pneu, dat2) > > fit.kmi3 <- cox.kmi(Surv(start, stop, ev.fact == "death") ~ pneu, dat3) > > all.equal(fit.kmi$coefficients, fit.kmi2$coefficients) [1] TRUE > all.equal(coef(fit.kmi), coef(fit.kmi3)) [1] TRUE > all.equal(fit.kmi$variance, fit.kmi2$variance) [1] TRUE > > fit.kmi Call: cox.kmi(formula = Surv(start, stop, event == 2) ~ pneu, imp.data = dat) ***************** Pooled estimates: ***************** coef exp(coef) se(coef) t p pneu1 1.104148 3.016652 0.2399367 4.601829 4.188064e-06 > > fit.kmi2 Call: cox.kmi(formula = Surv(start, stop, ev == 2) ~ pneu, imp.data = dat2) ***************** Pooled estimates: ***************** coef exp(coef) se(coef) t p pneu1 1.104148 3.016652 0.2399367 4.601829 4.188064e-06 > > fit.kmi3 Call: cox.kmi(formula = Surv(start, stop, ev.fact == "death") ~ pneu, imp.data = dat3) ***************** Pooled estimates: ***************** coef exp(coef) se(coef) t p pneu1 1.104148 3.016652 0.2399367 4.601829 4.188064e-06 > > ### with covariates > ## classic > set.seed(1) > dd$juhu <- rnorm(nrow(dd)) > > set.seed(78223) > imp.dd <- kmi(Surv(time, ev != 0) ~ juhu, dd, + etype = ev, nimp = 5) > set.seed(44889) > imp.ddb <- kmi(Surv(time, ev != 0) ~ juhu, dd, nimp = 5, + etype = ev, boot = TRUE, nboot = 5) > > summary(cox.kmi(Surv(time, ev == 1) ~ cov, imp.dd)) Call: cox.kmi(formula = Surv(time, ev == 1) ~ cov, imp.data = imp.dd) ***************** Pooled estimates: ***************** coef exp(coef) se(coef) t Pr(>|t|) cov -0.0485 0.9527 0.3155 -0.154 0.878 exp(coef) exp(-coef) lower .95 upper .95 cov 0.9527 1.05 0.5132 1.768 > summary(cox.kmi(Surv(time, ev == 1) ~ cov, imp.ddb)) Call: cox.kmi(formula = Surv(time, ev == 1) ~ cov, imp.data = imp.ddb) ***************** Pooled estimates: ***************** coef exp(coef) se(coef) t Pr(>|t|) cov -0.08706 0.91662 0.31606 -0.275 0.783 exp(coef) exp(-coef) lower .95 upper .95 cov 0.9166 1.091 0.4932 1.704 > > ## time-dependent covariates > set.seed(9763) > imp.dat.c <- kmi(Surv(start, stop, status) ~ age + sex, + data = icu.pneu, etype = event, id = id, + failcode = 2, nimp = 5) > > set.seed(19832) > imp.dat.cb <- kmi(Surv(start, stop, status) ~ age + sex, + data = icu.pneu, etype = event, id = id, + failcode = 2, nimp = 5, boot = TRUE, + nboot = 5) > > summary(cox.kmi(Surv(start, stop, event == 2) ~ pneu, + imp.dat.c)) Call: cox.kmi(formula = Surv(start, stop, event == 2) ~ pneu, imp.data = imp.dat.c) ***************** Pooled estimates: ***************** coef exp(coef) se(coef) t Pr(>|t|) pneu1 1.117 3.055 0.240 4.654 3.25e-06 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 exp(coef) exp(-coef) lower .95 upper .95 pneu1 3.055 0.3273 1.909 4.89 > summary(cox.kmi(Surv(start, stop, event == 2) ~ pneu, + imp.dat.cb)) Call: cox.kmi(formula = Surv(start, stop, event == 2) ~ pneu, imp.data = imp.dat.cb) ***************** Pooled estimates: ***************** coef exp(coef) se(coef) t Pr(>|t|) pneu1 1.1077 3.0274 0.2403 4.609 4.04e-06 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 exp(coef) exp(-coef) lower .95 upper .95 pneu1 3.027 0.3303 1.89 4.849 > > > ## Test ordering of the data set > > data(icu.pneu) > icu.pneu$outcome <- with(icu.pneu, status * event) > > mydata1 <- icu.pneu[1:2, ] > mydata2 <- icu.pneu[3:1421, ] > > ## page 221 > set.seed(453) > imp.dat <- kmi(Surv(start, stop, outcome != 0) ~ 1, + data = icu.pneu, etype = outcome, + id = id, failcode = 2, nimp = 10) > > ## page 222 > kmi.sh.hap <- cox.kmi(Surv(start, stop, outcome == 2) ~ pneu, imp.dat) > summary(kmi.sh.hap) Call: cox.kmi(formula = Surv(start, stop, outcome == 2) ~ pneu, imp.data = imp.dat) ***************** Pooled estimates: ***************** coef exp(coef) se(coef) t Pr(>|t|) pneu1 1.1057 3.0213 0.2399 4.608 4.06e-06 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 exp(coef) exp(-coef) lower .95 upper .95 pneu1 3.021 0.331 1.888 4.835 > > newicu.pneu <- as.data.frame(rbind( mydata2, mydata1)) > tail(newicu.pneu) id start stop status event pneu adm.cens.exit age sex outcome 1418 2020485 0 21 1 3 0 445 69.85106 M 3 1419 2020508 0 49 1 3 0 537 60.23257 M 3 1420 2020634 0 35 1 3 0 555 59.52186 M 3 1421 2020811 0 3 1 3 0 465 73.95806 F 3 1 12 0 3 1 3 0 421 62.53307 F 3 2 41 0 5 1 3 0 545 75.34153 F 3 > > set.seed(453) > imp.datnew <- kmi(Surv(start, stop, outcome != 0) ~ 1, + data = newicu.pneu, etype = outcome, + id = id, failcode = 2, nimp = 10) > > # page 222 > kmi.sh.hap <- cox.kmi(Surv(start, stop, outcome == 2) ~ pneu, imp.datnew) > summary(kmi.sh.hap) Call: cox.kmi(formula = Surv(start, stop, outcome == 2) ~ pneu, imp.data = imp.datnew) ***************** Pooled estimates: ***************** coef exp(coef) se(coef) t Pr(>|t|) pneu1 1.1057 3.0213 0.2399 4.608 4.06e-06 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 exp(coef) exp(-coef) lower .95 upper .95 pneu1 3.021 0.331 1.888 4.835 > > proc.time() user system elapsed 3.496 0.200 3.706 kmi/NAMESPACE0000755000176200001440000000044413301064335012254 0ustar liggesusersimport(survival) importFrom(mitools, MIcombine) importFrom("stats", "formula", "model.extract", "model.matrix", "printCoefmat", "pt", "qt", "update.formula") export(kmi, cox.kmi, summary.cox.kmi) S3method(print, cox.kmi) S3method(summary, cox.kmi) S3method(print, summary.cox.kmi) kmi/data/0000755000176200001440000000000013301064335011741 5ustar liggesuserskmi/data/icu.pneu.rda0000755000176200001440000004717413301064335014177 0ustar liggesusers}TT5G" E# 99"QQ1`5g9]5k\W?]u쾽UUYަe PT(ZPxQODD !#XeV'%G4CD#xD4DOz?6E  vw |ʯB`98ʧe B b!b?\A7E O}="1qq; Thhhh'VD:! t@;||~XAXF oRg0D&!f#Pn5 K{g!aqQD9Mp>*!3!!F#P>EG" ު!ù|pLY[A6t뚉؀؃8%pB4bpg~Oz/CFg8pD`oD/pP r}#^1|# Bdm55{$R+>8s>e@>Q./D( ]E8JD`D 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48QlD`Ph}\~.`HNDvjZEX?D`a =SY2 u|G{ drժE5'h9yiat3 2Yov V>[c+xO\pUKY\M!BA\;%`ڷַvGMҺGRP;,o!%( 8> d-Hw>G!ۙ}'jU\K@.OUA1~/ qۺ۲Nm|C cy_ې, >ŭtEPSGd[~⠙kzk jjj؞o^Z )~$JT4pD%}@iIrf ڥ\u^ v{除?|w|) ]Tۏ,:U~t 39ѕ>fO.?|%=tɪk>+{^s~ڤ7?eҧ>c˟OJ^Kb0?1|ߧ<ȯ/|*?|!/*H>8Ydk.OyɝW\Wt͏7򧂎9)lyu^s_?ʏ/?(hl7^C8*hG-o^$cӼ |ʏ;]k,]芫˷g~+7|>yX|5vyy~l_|g^*eO|ks撕~?D[E}=?7o` 92 Eu!P<|/DSAf!#ؿ:0:H $*685IiT ס\!~a-eOkmi/R/0000755000176200001440000000000013473042746011245 5ustar liggesuserskmi/R/print.cox.kmi.R0000755000176200001440000000215713301064335014067 0ustar liggesusersprint.cox.kmi <- function(x, print.ind = FALSE, ...) { if (!inherits(x, "cox.kmi")) { stop("'x' must an object of class 'kmi'") } if ("coxph.penal" %in% class(x$cox.kmi.fit[[1]])) { stop("Some things to think about before using frailties here") } cat("Call:\n") dput(x$call); cat("\n") coef <- x$coefficients se <- sqrt(diag(x$variance)) tmp <- cbind(coef, exp(coef), se, x$coefficients / sqrt(diag(x$variance)), 2 * pt(abs(x$coefficients / sqrt(diag(x$variance))), df = x$df, lower.tail = FALSE)) dimnames(tmp) <- list(names(coef), c("coef", "exp(coef)", "se(coef)", "t", "p")) cat("*****************\n") cat("Pooled estimates:\n") cat("*****************\n") print(tmp); cat("\n") if (print.ind) { cat("*********************\n") cat("Individual estimates:\n") cat("*********************\n\n") for (i in seq_along(x$individual.fit)) { cat(paste("*** Imputation", i, "***", sep = " ")); cat("\n") print(x$individual.fit[[i]], ...) cat("\n") } } invisible() } kmi/R/print.summary.cox.kmi.R0000755000176200001440000000206513301064335015561 0ustar liggesusersprint.summary.cox.kmi <- function(x, digits = max(getOption("digits") - 3, 3), signif.stars = getOption("show.signif.stars"), print.ind = FALSE, ...) { if (!inherits(x, "summary.cox.kmi")) { stop("'x' must be of class 'kmi'") } cat("Call:\n") dput(x$call) cat("\n") cat("\n") savedig <- options(digits = digits) on.exit(options(savedig)) cat("*****************\n") cat("Pooled estimates:\n") cat("*****************\n") printCoefmat(x$coefficients, digits = digits, signif.stars=signif.stars, ...) cat("\n") print(x$conf.int) cat("\n") if (print.ind) { cat("*********************\n") cat("Individual estimates:\n") cat("*********************\n\n") for (i in seq_along(x$individual.fit)) { cat(paste("*** Imputation", i, "***", sep = " ")); cat("\n") print(x$individual.fit[[i]], digits = max(getOption("digits") - 3, 3), ...) cat("\n") } } invisible() } kmi/R/kmi.tdc.R0000755000176200001440000000741213301064335012714 0ustar liggesusers## This function is used in the presence of time-dependent ## covariates kmi.tdc <- function(y, x, etype, id, failcode, epsilon, bootstrap, nboot) { ## We need to be careful for getting the censoring times. ## The status variable will be 0 before a change of the time-dependent ## covariate status, but that doesn't mean the guy is censored ## We want to get the last row of each individual that contains ## the actual status at the end of the follow-up masque <- rbind(1, apply(as.matrix(id), 2, diff)) masque <- c(masque[-1], 1) ## ysub will contain the data that are of interest to fulfill our purpose ysub <- y[masque != 0, ] ysub[, 1] <- 0 etype.sub <- etype[masque != 0] cens.times <- sort(unique(ysub[, 2][ysub[, 3] == 0])) ind <- which(y[, 3] == 0 | etype == failcode) ## times to impute itimes <- y[-ind, 2] ## the other times otimes <- y[ind, 2] ## covariates cn <- colnames(x) xsub <- x[masque != 0, ,drop = FALSE] xx <- x[-ind, , drop = FALSE] ## let's deal with missing values in a really ugly way, ## i.e., mean imputation if (!is.null(cn)) { if (!all(!is.na(xx))) { warning("Missing values in the variable(s) used for modelling the censoring distribution.\nMean imputation used") mm <- apply(x, 2, mean, na.rm = TRUE) for (i in seq_len(ncol(xx))) { xx[which(is.na(xx[, i])), i] <- mm[i] } } } if (bootstrap) { index <- lapply(seq_len(nboot), function(k) { sample(seq_len(nrow(ysub)), nrow(ysub), replace = TRUE) }) ff <- formula(Surv(ysub[index[[l]], 2], ysub[index[[l]], 3] == 0) ~ 1) if (!is.null(cn)) { g <- array(0, dim = c(length(cens.times), length(itimes), nboot)) ff <- update.formula(ff, paste(". ~", paste(cn, collapse = "+"))) for (l in seq_len(nboot)) { temp <- coxph(ff, as.data.frame(xsub)) tmp <- summary(survfit(temp, as.data.frame(xx))) ordre <- findInterval(cens.times, tmp$time) ordre[ordre == 0] <- NA g[,, l] <- tmp$surv[ordre, ] g[,, l][is.na(g[, , l])] <- 1 } g <- apply(g, c(1, 2), mean) gg <- rbind(1, g) } else { g <- matrix(0, nrow = nboot, ncol = length(cens.times)) for (l in seq_len(nboot)) { tmp <- summary(survfit(Surv(ysub[index[[l]], 2], ysub[index[[l]], 3] == 0) ~ 1)) ordre <- findInterval(cens.times, tmp$time) ordre[ordre == 0] <- NA g[l, ] <- tmp$surv[ordre] g[l, ][is.na(g[l, ])] <- 1 } g <- apply(g, 2, mean) gg <- matrix(rep(c(1, g), length(itimes)), nrow = length(g) + 1) } } else { ff <- formula(Surv(ysub[, 2], ysub[, 3] == 0) ~ 1) if (!is.null(cn)) { ff <- update.formula(ff, paste(". ~", paste(cn, collapse = "+"))) temp <- coxph(ff, as.data.frame(xsub)) g <- summary(survfit(temp, as.data.frame(xx)))$surv gg <- rbind(1, g) } else { g <- summary(survfit(Surv(ysub[, 2], ysub[, 3] == 0) ~ 1))$surv gg <- matrix(rep(c(1, g), length(itimes)), nrow = length(g) + 1) } } a <- FALSE if (y[, 3][which.max(y[, 2])] != 0) { # TRUE if last time is an event cens.times <- c(cens.times, max(y[, 2]) + epsilon) a <- TRUE } list(gg = gg, cens.times = cens.times, itimes = itimes, otimes = otimes, place = ind, a = a) } kmi/R/kmi.R0000755000176200001440000001067213301064335012145 0ustar liggesuserskmi <- function(formula, data, id = NULL, etype, failcode = 1, nimp = 10, epsilon = 1, bootstrap = FALSE, nboot = 10) { if (missing(data)) stop("A data frame in which to interpret the formula must be supplied") if (missing(etype)) stop("'etype' is missing, with no default") Call <- match.call() ## I'll need the name of the etype column in cox.kmi() arg.etype <- deparse(substitute(etype)) if ((mode(Call[[2]]) == 'call' && Call[[2]][[1]] == as.name('Surv')) || inherits(formula, 'Surv')) { stop("'kmi' requires a formula as the first argument") } ## ugly hack: force the setting of na.action to na.pass to get all ## the event times in case of missing values in the covariate. Call$na.action <- as.name("na.pass") ## Try to order the data at this level. We assume that id is ## supplied with counting data. There is a test later on. the_surv_part <- Call[[2]][[2]] if ("id" %in% names(Call)) { col_id <- deparse(substitute(id)) col_start <- as.character(the_surv_part[[2]]) col_stop <- as.character(the_surv_part[[3]]) the_order <- order(data[, col_id], data[, col_start], data[, col_stop]) data <- data[the_order, ] } else { the_order <- seq_len(nrow(data)) } mfnames <- c('formula', 'data', 'na.action', 'id', 'etype') temp <- Call[c(1, match(mfnames, names(Call), nomatch=0))] temp[[1]] <- as.name("model.frame") m <- eval(temp, parent.frame()) n <- nrow(m) Y <- model.extract(m, 'response')[the_order] if (!is.Surv(Y)) stop("Response must be a survival object") id <- model.extract(m, "id")[the_order] etype <- model.extract(m, "etype")[the_order] mt <- attr(m, "terms") X <- model.matrix(mt, m)[the_order, -1, drop = FALSE] ## to get the name of the 'time' column aa <- Call[[2]][[2]] if (attr(Y, "type") %in% c("interval", "interval2", "left")) { stop("kmi can only handle right censored data") } if (attr(Y, "type") == "counting" && !is.null(id)) { info <- c(as.character(aa[[3]])[as.character(aa[[3]]) %in% names(data)], arg.etype) ## deal with etype when it's a fucking factor if (!is.factor(etype)) etype <- factor(etype) levels(etype) <- c(levels(etype), 0) etype[Y[, 3] == 0] <- 0 etype <- etype[, drop = TRUE] ## for right-censored data with time-dependent covariates, i.e., ## several rows per individual toimpute <- kmi.tdc(Y, X, id = id, etype = etype, failcode = failcode, epsilon = epsilon, bootstrap = bootstrap, nboot = nboot) } else { info <- c(as.character(aa[[2]])[as.character(aa[[2]]) %in% names(data)], arg.etype) if (!is.factor(etype)) etype <- factor(etype) levels(etype) <- c(levels(etype), 0) etype[Y[, 2] == 0] <- 0 etype <- etype[, drop = TRUE] ## for classical right-censored data toimpute <- kmi.classic(Y, X, etype = etype, failcode = failcode, epsilon = epsilon, bootstrap = bootstrap, nboot = nboot) } itimes <- toimpute$itimes gg <- toimpute$gg lg <- NROW(gg) cens.times <- toimpute$cens.times tmp <- findInterval(itimes, c(0, cens.times)) if (length(cens.times) == 1) stop("'kmi' can't make imputation based on one censoring time") res <- lapply(seq_len(nimp), function(i) { tt <- double(length(itimes)) for (j in seq_along(itimes)) { spr <- gg[, j] / c(gg[1:tmp[j], j], rep(gg[tmp[j], j], lg - tmp[j])) wp <- -diff(spr) ## if the last time is an event, a == TRUE and we add another probability wp <- if (toimpute$a) c(wp, spr[length(spr)]) else wp tt[j] <- sample(cens.times, 1, replace = TRUE, prob = wp) } newtimes <- c(toimpute$otimes, tt) newevent <- factor(c(levels(etype)[etype][toimpute$place], rep(0, length(tt)))) data.frame(newtimes, newevent) }) ## we need to put the original data in the same order as the imputed times orig.data <- rbind(data[toimpute$place, ], data[-toimpute$place, ]) zzz <- list(imputed.data = res, original.data = orig.data, info = info, call = Call) class(zzz) <- "kmi" zzz } kmi/R/summary.cox.kmi.R0000755000176200001440000000244013301064335014423 0ustar liggesuserssummary.cox.kmi <- function(object, conf.int = 0.95, scale = 1, ...) { if (!inherits(object, "cox.kmi")) { stop("'object' must be of class 'cox.kmi'") } if ("cox.penal" %in% class(object$cox.kmi.fit[[1]])) { stop("Doesn't work yet") } rval <- list() rval$call <- object$call beta <- object$coefficients se.beta <- sqrt(diag(object$var)) tmp <- cbind(beta, exp(beta), se.beta, beta / se.beta, 2 * pt(abs(beta / se.beta), df = object$df, lower.tail = FALSE)) dimnames(tmp) <- list(names(beta), c("coef", "exp(coef)", "se(coef)", "t", "Pr(>|t|)")) rval$coefficients <- tmp z <- -qt((1 + conf.int)/2, object$df, lower.tail = FALSE) tmp <- cbind(exp(beta), exp(-beta), exp(beta - z * se.beta), exp(beta + z * se.beta)) dimnames(tmp) <- list(names(beta), c("exp(coef)", "exp(-coef)", paste("lower .", round(100 * conf.int, 2), sep = ""), paste("upper .", round(100 * conf.int, 2), sep = ""))) rval$conf.int <- tmp tmp <- lapply(object$individual.fit, summary, conf.int = conf.int, scale = scale, ...) rval$individual.fit <- tmp class(rval) <- "summary.cox.kmi" rval } kmi/R/kmi.classic.R0000755000176200001440000000736313301064335013570 0ustar liggesusers### function to get the censoring times and distribution ### from competing risks right-censored data kmi.classic <- function(y, x, etype, failcode, epsilon, bootstrap, nboot) { if (!is.Surv(y)) stop("y must be a Surv object") if (attr(y, "type") != "right") stop("Can only handle right censored data") if (is.null(etype)) stop("Argument 'etype' is missing with no default") ## Depending on how the model is specified (see example(survfit)), ## etype might not be 0 when the observation is censored ## etype[y[, 2] == 0] <- 0 cens.times <- sort(unique(y[, 1][y[, 2] == 0])) ind <- which(y[, 2] == 0 | etype == failcode) ## itimes are the time that need imputation ## otimes don't need imputation itimes <- y[-ind, 1] otimes <- y[ind, 1] cn <- colnames(x) xx <- x[-ind, , drop = FALSE] ## let's deal with missing values in a really ugly way, ## i.e., mean imputation if (!is.null(cn)) { if (!all(!is.na(xx))) { warning("Missing values in the variable(s) used for modelling the censoring distribution.\nMean imputation used") mm <- apply(x, 2, mean, na.rm = TRUE) for (i in seq_len(ncol(xx))) { xx[which(is.na(xx[, i])), i] <- mm[i] } } } if (bootstrap) { # simple bootstrap with remplacement here index <- lapply(seq_len(nboot), function(k) { sample(seq_len(nrow(y)), nrow(y), replace = TRUE) })## might save some time to compute the index within the loop ff <- formula(Surv(y[index[[l]], 1], y[index[[l]], 2] == 0) ~ 1) if (!is.null(cn)) { g <- array(0, dim = c(length(cens.times), length(itimes), nboot)) ff <- update.formula(ff, paste(". ~", paste(cn, collapse = "+"))) for (l in seq_len(nboot)) { temp <- coxph(ff, as.data.frame(x)) tmp <- summary(survfit(temp, as.data.frame(xx))) ordre <- findInterval(cens.times, tmp$time) ordre[ordre == 0] <- NA g[,, l] <- tmp$surv[ordre, ] g[,, l][is.na(g[, , l])] <- 1 } g <- apply(g, c(1, 2), mean) gg <- rbind(1, g) } else { g <- matrix(0, nrow = nboot, ncol = length(cens.times)) for (l in seq_len(nboot)) { tmp <- summary(survfit(Surv(y[index[[l]], 1], y[index[[l]], 2] == 0) ~ 1)) ordre <- findInterval(cens.times, tmp$time) ordre[ordre == 0] <- NA g[l, ] <- tmp$surv[ordre] g[l, ][is.na(g[l, ])] <- 1 } g <- apply(g, 2, mean) gg <- matrix(rep(c(1, g), length(itimes)), nrow = length(g) + 1) } } else { ff <- formula(Surv(y[, 1], y[, 2] == 0) ~ 1) if (!is.null(cn)) { ff <- update.formula(ff, paste(". ~", paste(cn, collapse = "+"))) temp <- coxph(ff, as.data.frame(x)) g <- summary(survfit(temp, as.data.frame(xx)), times = cens.times, extend = TRUE)$surv gg <- rbind(1, g) } else { g <- summary(survfit(Surv(y[, 1], y[, 2] == 0) ~ 1))$surv gg <- matrix(rep(c(1, g), length(itimes)), nrow = length(g) + 1) } } a <- FALSE if (y[, 2][which.max(y[, 1])] != 0) { # will be true if the last time is an event cens.times <- c(cens.times, max(y[, 1]) + epsilon) a <- TRUE } list(gg = gg, cens.times = cens.times, itimes = itimes, otimes = otimes, place = ind, a = a) } kmi/R/cox.kmi.R0000755000176200001440000000160713301064335012733 0ustar liggesuserscox.kmi <- function(formula, imp.data, df.complete = Inf, ...) { if (!inherits(imp.data, "kmi")) { stop("'imp.data' must be of class 'kmi'") } call <- match.call() info <- imp.data$info # that's where we have the column names (time, event) result <- lapply(seq_along(imp.data$imputed.data), function(i) { daten <- imp.data$original.data daten[, info[1]] <- imp.data$imputed.data[[i]][, 1] daten[, info[2]] <- imp.data$imputed.data[[i]][, 2] tmp <- coxph(formula, data = daten, ...) tmp }) res <- MIcombine(result, df.complete = df.complete) ## that's a nice function zzz <- list(coefficients = res$coefficients, variance = res$variance, nimp = res$nimp, df = res$df, call = call, individual.fit = result) class(zzz) <- "cox.kmi" zzz } kmi/MD50000644000176200001440000000170513473051065011351 0ustar liggesusers7217818b0210ed00ff1d479d768fef99 *ChangeLog 3e5a27009a97481e62ad68fa0483dceb *DESCRIPTION ddfcf4daaf5b71cbdbbfdc8cdbc797ed *NAMESPACE 946e6564399cf69089aaf2bdd2ec14cd *R/cox.kmi.R bba387aefcb47431f3aaed0cb0bee241 *R/kmi.R 433e23db8b80c6b899fe5235db056d9f *R/kmi.classic.R bda73c0dc59f972c4a8cb60e02ebd732 *R/kmi.tdc.R 49ed057c81830b95deba5139aaa55d88 *R/print.cox.kmi.R 052b3bd2d78d458f491145cffb2d0667 *R/print.summary.cox.kmi.R f41407106aa9c0c1557deda7b3ee0731 *R/summary.cox.kmi.R 66b2fa917ef690eb2788f500ca7483eb *data/icu.pneu.rda 4cb110a554f1dcfe2c0413ec6e69c751 *man/cox.kmi.Rd c5c3dac6e0a7357e2a9ee6c8b3253016 *man/icu.pneu.Rd 5567989d1b2bfb40f72307f179bc5568 *man/kmi.Rd 81a81bc076ae1286636c4e9ba3cd1121 *man/print.cox.kmi.Rd 70cdcf49e398bb5178b515bac4f4cd26 *man/print.summary.cox.kmi.Rd b65a2d77e1cd4ae8586ec93092a44f01 *man/summary.cox.kmi.Rd 1fc7e0c561de3ac7e7ec2fbd7e68404b *tests/test.kmi.R 90149f54b88923b783b49c30e40dd152 *tests/test.kmi.Rout.save kmi/DESCRIPTION0000755000176200001440000000155713473051065012557 0ustar liggesusersPackage: kmi Version: 0.5.5 Title: Kaplan-Meier Multiple Imputation for the Analysis of Cumulative Incidence Functions in the Competing Risks Setting Author: Arthur Allignol Maintainer: Arthur Allignol Imports: mitools,survival,stats Description: Performs a Kaplan-Meier multiple imputation to recover the missing potential censoring information from competing risks events, so that standard right-censored methods could be applied to the imputed data sets to perform analyses of the cumulative incidence functions (Allignol and Beyersmann, 2010 ). License: GPL (>= 2) URL: https://github.com/aallignol/kmi BugReports: https://github.com/aallignol/kmi/issues NeedsCompilation: no Packaged: 2019-05-27 20:17:42 UTC; arthur Repository: CRAN Date/Publication: 2019-05-27 21:10:13 UTC kmi/ChangeLog0000755000176200001440000000444513301064335012614 0ustar liggesusers2018-05-16 Arthur Allignol * Version number 0.5.4 * bug fix when the data with time-dependent variables are not ordered 2017-09-18 Arthur Allignol * Version number 0.5.3 * Maintainer email address change 2017-01-13 Arthur Allignol * version number 0.5.2 * NAMESPACE and DESCRIPTION: import stats and survival * Examples and tests: require(survival) statements * Rerun of the test file 2013-09-16 Arthur Allignol * DESCRIPTION: update version number; clean import,depends * NAMESPACE: clean the imports 2011-11-28 Arthur Allignol * new version number 0.4 * kmi: new possibility to fit a proportional hazards model to model the censoring distribution. Censoring times are then imputed from the estimated model. 2011-3-5 Arthur Allignol * new version number 0.3-4 * icu.pneu: Add 2 covariates * test: Rerun the test file 2010-5-26 Arthur Allignol * kmi.R: Function works when etype is specified as a factor * test.kmi.R: New tests to check results when etype is specified as a factor 2009-5-25 Arthur Allignol * Argument x in cox.kmi is replaced by imp.data * Slight improvement of the documentation 2009-5-8 Arthur Allignol * A t-test and associated p-value are computed in print.cox.kmi and summary.cox.kmi 2009-5-6 Arthur Allignol * New user interface. Model specification in kmi is now done using formulas and works in a manner comparable to survfit for competing risks data * New internal functions kmi.classic (for right-censored data) and kmi.tdc (for right-censored data with time-dependent covariates) instead of one single kmi function * Individual results pooling in cox.kmi() is now done using MIcombine() from the mitools package. New argument df.complete in cox.kmi * Inclusion of a data set icu. 2009-4-17 Arthur Allignol * Correct computation of the probabilities for the sampling in kmi 2009-3-4 Arthur Allignol * Creation of the package kmi/man/0000755000176200001440000000000013473042746011617 5ustar liggesuserskmi/man/print.cox.kmi.Rd0000755000176200001440000000121413301064335014576 0ustar liggesusers\name{print.cox.kmi} \alias{print.cox.kmi} \title{Print method for cox.kmi objects} \description{ Print method for \code{cox.kmi} objects. } \usage{ \S3method{print}{cox.kmi}(x, print.ind = FALSE, ...) } \arguments{ \item{x}{An object of class \code{cox.kmi}.} \item{print.ind}{A logical specifying whether to print the results of the analyses performed on each imputed data set. By default, only the pooled estimates are printed.} \item{\dots}{Further arguments} } \value{ No value returned } \author{Arthur Allignol, \email{arthur.allignol@gmail.com}} \seealso{\code{\link{cox.kmi}}, \code{\link{summary.cox.kmi}}} \keyword{print} kmi/man/print.summary.cox.kmi.Rd0000755000176200001440000000153713301064335016302 0ustar liggesusers\name{print.summary.cox.kmi} \alias{print.summary.cox.kmi} \title{Print method for summary.cox.kmi objects} \description{ Print method for \code{summary.cox.kmi} objects. } \usage{ \S3method{print}{summary.cox.kmi}(x, digits = max(getOption("digits") - 3, 3), signif.stars = getOption("show.signif.stars"), print.ind = FALSE, ...) } \arguments{ \item{x}{An object of class \code{summary.cox.kmi}.} \item{digits}{Significant digits to print.} \item{signif.stars}{Logical. If TRUE, 'significance stars' are printed for each coefficient.} \item{print.ind}{Logical specifying whether to print a summary of the models fitted on each imputed data set. Default is FALSE} \item{\dots}{Further arguments} } \value{ No value returned } \author{Arthur Allignol, \email{arthur.allignol@gmail.com}} \seealso{\code{\link{summary.cox.kmi}}} \keyword{print}kmi/man/icu.pneu.Rd0000755000176200001440000000353613301064335013632 0ustar liggesusers\name{icu.pneu} \alias{icu.pneu} \docType{data} \title{Hospital acquired penumonia in ICU} \description{ This data set is a random sample drawn from the SIR-3 study that aimed at analysing the effect of nosocomial infections on the length of ICU stay. Patients were included in the study if they had stayed at least 1 day in the unit. The sample includes information to assess the effect of nosocomial pneumonia on the length of stay. The endpoint is either discharge alive from the ICU or dead in the unit. These data are censoring complete as the censoring time is known for all patients. } \usage{data(icu.pneu)} \format{ A data frame with 1421 observations on the following 8 variables. \describe{ \item{\code{id}}{Individual patient id.} \item{\code{start}}{Start of the observation time.} \item{\code{stop}}{Failure time.} \item{\code{status}}{Censoring status. 0 if the observation is censored, 1 otherwise.} \item{\code{event}}{Event type. 2 is death in ICU, 3 is discharge alive} \item{\code{pneu}}{Nosocomial pneumonia indicator.} \item{\code{adm.cens.exit}}{Exit times for patients discharged alive are replaced by their administrative censoring times.} \item{\code{age}}{Age at inclusion} \item{\code{sex}}{Sex. \code{F} for female and \code{M} for male} } } \source{ Beyersmann, J., Gastmeier, P., Grundmann, H., Baerwolff, S., Geffers, C., Behnke, M., Rueden, H., and Schumacher, M. Use of multistate models to assess prolongation of intensive care unit stay due to nosocomial infection. \emph{Infection Control and Hospital Epidemiology}, 27:493-499, 2006. } \references{ Beyersmann, J. and Schumacher, M. (2008). Time-dependent covariates in the proportional hazards model for competing risks. \emph{Biostatistics}, 9:765--776. } \examples{ data(icu.pneu) } \keyword{datasets} kmi/man/summary.cox.kmi.Rd0000755000176200001440000000245713301064335015151 0ustar liggesusers\name{summary.cox.kmi} \alias{summary.cox.kmi} \title{Summary method for cox.kmi objects} \description{ Provides a summary of the fitted model. } \usage{ \S3method{summary}{cox.kmi}(object, conf.int = 0.95, scale = 1, ...) } \arguments{ \item{object}{An object of class \code{cox.kmi}.} \item{conf.int}{Level of the confidence intervals. Default is 0.95} \item{scale}{Vector of scale factors for the coefficients, default to 1. The confidence limits are for the risk change associated with one scale unit.} \item{\dots}{Further arguments} } \value{ An object of class \code{summary.cox.kmi} with the following components: \item{call}{The matched call} \item{coefficients}{A matrix with 5 columns including the regression coefficients, subdistribution hazard ratios, standard-errors, t-statistics and corresponding two-sided p-values.} \item{conf.int}{A matrix with 4 columns that consists of the subdistribution hazard ratios, exp(-coef) and the lower and upper bounds of the confidence interval.} \item{individual.fit}{A list of \code{summary.coxph} objects for each imputed data set} } \author{Arthur Allignol, \email{arthur.allignol@gmail.com}} \seealso{\code{\link{cox.kmi}}, \code{\link{print.summary.cox.kmi}}, \code{\link[survival]{summary.coxph}}} \keyword{methods} kmi/man/kmi.Rd0000755000176200001440000001166713301064335012670 0ustar liggesusers\name{kmi} \alias{kmi} \title{Kaplan-Meier Multiple Imputation for Competing Risks} \description{ The function performs a non parametric multiple imputation that aims at recovering the missing potential censoring times from competing events. } \usage{ kmi(formula, data, id = NULL, etype, failcode = 1, nimp = 10, epsilon = 1, bootstrap = FALSE, nboot = 10) } \arguments{ \item{formula}{A \code{formula} object, that must have a \code{Surv} object on the left of a \code{~} operator. Covariates could be added on the right hand side of the formula. They will be used to model the censoring distribution. See Details.} \item{data}{A data.frame in which to interpret the variables given in the formula, \code{etype} and \code{id}. It is mandatory.} \item{id}{Used to identify individual subjects when one subject can have several rows of data, e.g., with time-dependent covariates. Set to \code{NULL} when there is only one raw of data per subject.} \item{etype}{Variable specifying the type of competing event. When \code{status == 1} in \code{formula}, \code{etype} describes the type of event, otherwise, for censored observation, (\code{status == 0}), the value of \code{etype} is ignored.} \item{failcode}{Indicates the failure cause of interest. Imputation will be performed on the other competing events. Default is 1.} \item{nimp}{Number of multiple imputation. Default is 10.} \item{epsilon}{When the last time is an event, a censoring time equal to \code{max(time) + epsilon} is added. By default, \code{epsilon} is set to 1.} \item{bootstrap}{Logical. Whether to estimate the censoring distribution using bootstrap samples. Default is FALSE.} \item{nboot}{If \code{bootstrap} is set to TRUE, \code{nboot} determines the number of bootstrap samples.} } \details{ It was shown that if censoring times are observed for all individuals, methods for standard right-censored survival data can be used to analyse cumulative incidence functions from competing risks (Fine and Gray 1999). Therefore the idea proposed by Ruan and Gray (2008) is to impute potential censoring times for individuals who have failed from the competing events. The censoring times are imputed from the conditional Kaplan-Meier estimator of the censoring distribution. Estimation of the censoring distribution may be improved through bootstrapping. Estimation might also be improved fitting a model for the censoring distribution. When covariates are given, a proportional hazards model on the hazard of censoring is fit. The censoring times are then imputed from the estimated model. The competing risks model formulation in \code{formula} mimics the one in \code{\link[survival]{survfit}}. } \value{ An object of class \code{kmi} with the following components: \item{imputed.data}{A list of matrices giving the imputed times in the first column and imputed event type in the second column. The event status for imputed times take value 0 (censored).} \item{original.data}{The original data set} \item{info}{Gives the names of the time and event indicator column in the original data set.} \item{call}{The matched call.} } \section{Warning}{ When a proportional hazards model is fit for modelling the censoring distribution, the censoring times are imputed from the imputed model. When there is missing covariate information for the prediction, mean imputation is used. } \note{ This multiple imputation technique does not work for left-truncated data. } \references{Ruan, P.K. and Gray, R.J. (2008). Analyses of cumulative incidence functions via non-parametric multiple imputation. \emph{Statistics in Medicine}, 27(27):5709--5724. Allignol, A. and Beyersmann, J. (2010). Software for fitting nonstandard proportional subdistribution hazards models. \emph{Biostatistics}, doi:10.1093/biostatistics/kxq018 Fine, J.P. and Gray, R.J. (1999). A Proportional Hazards Model for the Subdistribution of a Competing Risk. \emph{Journal of the American Statistical Association}. 94(446):496--509. } \author{Arthur Allignol, \email{arthur.allignol@gmail.com}} \seealso{\code{\link{icu.pneu}}, \code{\link{cox.kmi}}, \code{\link[survival]{Surv}}, \code{\link[survival]{survfit}}} \examples{ data(icu.pneu) if (require(survival)) { dat <- kmi(Surv(start, stop, status) ~ 1, data = icu.pneu, etype = event, id= id, failcode = 2, nimp = 5) ## another way to specify the formula if there is no status ## variable icu.pneu$ev <- icu.pneu$event icu.pneu$ev[icu.pneu$status == 0] <- 0 dat <- kmi(Surv(start, stop, ev != 0) ~ 1, data = icu.pneu, etype = ev, id= id, failcode = 2, nimp = 5) ## with covariates to model the censoring distribution dat.cova <- kmi(Surv(start, stop, status) ~ age + sex, data = icu.pneu, etype = event, id = id, failcode = 2, nimp = 5) } } \keyword{survival}kmi/man/cox.kmi.Rd0000755000176200001440000000500313301064335013443 0ustar liggesusers\name{cox.kmi} \alias{cox.kmi} \title{Cox proportional hazards model applied to imputed data sets} \description{ This function fits Cox proportional hazards models to each imputed data set to estimate the regression coefficients in a proportional subdistribution hazards model, and pools the results. } \usage{ cox.kmi(formula, imp.data, df.complete = Inf, ...) } \arguments{ \item{formula}{A formula object, with the response on the left of a \code{~} operator, and the terms on the right. The response must be a survival object as returned by the \code{\link[survival]{Surv}} function.} \item{imp.data}{An object of class \code{kmi}.} \item{df.complete}{Complete data degrees of freedom.} \item{\dots}{Further arguments for the \code{\link[survival]{coxph}} function.} } \details{ Fits a Cox proportional hazards model on each imputed data set to estimate the regression coefficients in a proportional subdistribution hazards model, and pools the results, using the \code{\link[mitools]{MIcombine}} function of the mitools package. } \value{ An object of class \code{cox.kmi} including the following components: \item{coefficients}{Pooled regression coefficient estimates} \item{variance}{Pooled variance estimate} \item{nimp}{Number of multiple imputations} \item{df}{degrees of freedom} \item{call}{The matched call} \item{individual.fit}{A list of \code{coxph} objects. One for each imputed data set.} } \author{Arthur Allignol, \email{arthur.allignol@gmail.com}} \seealso{\code{\link[survival]{coxph}}, \code{\link[mitools]{MIcombine}}, \code{\link{print.cox.kmi}}, \code{\link{summary.cox.kmi}}} \examples{ data(icu.pneu) if (require(survival)) { set.seed(1313) imp.dat <- kmi(Surv(start, stop, status) ~ 1, data = icu.pneu, etype = event, id = id, failcode = 2, nimp = 5) fit.kmi <- cox.kmi(Surv(start, stop, event == 2) ~ pneu, imp.dat) summary(fit.kmi) ### Now using the censoring-complete data fit <- coxph(Surv(start, adm.cens.exit, event == 2) ~ pneu, icu.pneu) summary(fit) ## estimation of the censoring distribution adjusted on covariates dat.cova <- kmi(Surv(start, stop, status) ~ age + sex, data = icu.pneu, etype = event, id = id, failcode = 2, nimp = 5) fit.kmi2 <- cox.kmi(Surv(start, adm.cens.exit, event == 2) ~ pneu + age, dat.cova) summary(fit.kmi2) } } \keyword{survival} \keyword{models} \keyword{regression}