Skip to content

Create the covariate-adjusted Kaplan-Meier and cumulative incidence functions

License

Notifications You must be signed in to change notification settings

Lesly1031/AdjKMCIF

Repository files navigation

AdjKMCIF

R-CMD-check License: GPL v3

The goal of AdjKMCIF is to create the covariate-adjusted Kaplan-Meier and cumulative incidence functions.

More specific introduction of the package can be found at https://lesly1031.github.io/AdjKMCIF/

Installation

You can install the development version of AdjKMCIF from GitHub with:

# install.packages("devtools")
devtools::install_github("Lesly1031/AdjKMCIF",dependencies = TRUE)

Adjusted KM examples

library(AdjKMCIF)
library(tidyverse)
library(DT)
library(data.table)
library(KMsurv)

Example data

data(bmt)
bmt$arm <- bmt$group
bmt$arm = factor(as.character(bmt$arm), levels = c("2", "1", "3"))
bmt$z3 = as.character(bmt$z3)
bmt$t2 = bmt$t2 * 12/365.25

Coxph model

result1 = adjusted_KM(data = bmt, time = "t2", status = "d3", group = "arm", covlist = c("z1",
    "z3"), stratified_cox = "No", reference_group = NULL)
adjKM_plot(result1, data = bmt)

Bootstrap results for Cox model

result1_1 = boot_ci_adj_km(boot_n = 100, ci_cut = c(0.025, 0.975), data = bmt, time = "t2",
    status = "d3", group = "arm", covlist = c("z1", "z3"), stratified_cox = "No",
    reference_group = NULL)
adjKM_CI_plot(result1_1, bmt)

Adjusted CIF Examples

Example data

data(bmt)
bmt$arm <- bmt$group
bmt$arm = factor(as.character(bmt$arm), levels = c("2", "1", "3"))
bmt$z3 = as.character(bmt$z3)
bmt$CenCI <- 0
for (ii in 1:137) {
    if (bmt$d3[ii] == 0) {
        bmt$CenCI[ii] = 0
    } else {
        if (bmt$d2[ii] == 1) {
            bmt$CenCI[ii] <- 1
        } else {
            bmt$CenCI[ii] <- 2
        }
    }
}
bmt$t2 = bmt$t2 * 12/365.25

FG model for event = relapse

result1 = adjusted_CIF(data = bmt, time = "t2", status = "CenCI", group = "arm",
    covlist = c("z1", "z3"), event_code = 1, stratified = "No", reference_group = NULL)
table_res1 = spread(result1, class, prob)
head(table_res1)
#>          time           1           2          3
#> 1 0.001079399 0.007337385 0.003216491 0.01206072
#> 2 0.002158798 0.007337385 0.003216491 0.01206072
#> 3 0.010793991 0.007337385 0.003216491 0.01206072
#> 4 0.017270385 0.007337385 0.003216491 0.01206072
#> 5 0.034540771 0.007337385 0.003216491 0.01206072
#> 6 0.037778968 0.007337385 0.003216491 0.01206072

Figure

adjCIF_plot(result1, data = bmt)

Bootstrap results for FG model with event = relapse

result1_boot = boot_ci_adj_cif(boot_n = 100, ci_cut = c(0.025, 0.975), data = bmt, time = "t2",
    status = "CenCI", group = "arm", covlist = c("z1", "z3"), event_code = 1, "No",
    NULL)

Figure

adjCIF_CI_plot(result1_boot, bmt)