Kaplan-Meier Plot with ‘ggplot2’: ‘survfit’ and ‘svykm’ objects from ‘survival’ and ‘survey’ packages.
install.packages("jskm")
## From github: latest version
install.packages("remotes")
::install_github("jinseob2kim/jskm")
remotes
library(jskm)
# Load dataset
library(survival)
data(colon)
<- survfit(Surv(time, status) ~ rx, data = colon)
fit
# Plot the data
jskm(fit)
jskm(fit,
table = T, pval = T, med = T, label.nrisk = "No. at risk", size.label.nrisk = 8,
xlabs = "Time(Day)", ylabs = "Survival", ystratalabs = c("Obs", "Lev", "Lev + 5FU"), ystrataname = "rx",
marks = F, timeby = 365, xlims = c(0, 3000), ylims = c(0.25, 1), showpercent = T
)
jskm(fit, ci = T, cumhaz = T, mark = F, ylab = "Cumulative incidence (%)", surv.scale = "percent", pval = T, pval.size = 6, pval.coord = c(300, 0.7))
jskm(fit, mark = F, surv.scale = "percent", pval = T, table = T, cut.landmark = 500)
jskm(fit, mark = F, surv.scale = "percent", pval = T, table = T, cut.landmark = 500, showpercent = T)
status2
variable: 0 - censoring, 1 - event, 2 -
competing risk
## Make competing risk variable, Not real
$status2 <- colon$status
colon$status2[1:400] <- 2
colon$status2 <- factor(colon$status2)
colon<- survfit(Surv(time, status2) ~ rx, data = colon)
fit2 jskm(fit2, mark = F, surv.scale = "percent", table = T, status.cmprsk = "1")
jskm(fit2, mark = F, surv.scale = "percent", table = T, status.cmprsk = "1", showpercent = T, cut.landmark = 500)
jskm(fit, theme = "jama", cumhaz = T, table = T, mark = F, ylab = "Cumulative incidence (%)", surv.scale = "percent", pval = T, pval.size = 6, pval.coord = c(300, 0.7))
jskm(fit, theme = "nejm", nejm.infigure.ratiow = 0.7, nejm.infigure.ratioh = 0.4, nejm.infigure.ylim = c(0, 0.7), cumhaz = T, table = T, mark = F, ylab = "Cumulative incidence (%)", surv.scale = "percent", pval = T, pval.size = 6, pval.coord = c(300, 0.7))
svykm.object
in survey
packagelibrary(survey)
data(pbc, package = "survival")
$randomized <- with(pbc, !is.na(trt) & trt > 0)
pbc<- glm(randomized ~ age * edema, data = pbc)
biasmodel $randprob <- fitted(biasmodel)
pbc
<- svydesign(id = ~1, prob = ~randprob, strata = ~edema, data = subset(pbc, randomized))
dpbc
<- svykm(Surv(time, status > 0) ~ 1, design = dpbc)
s1 <- svykm(Surv(time, status > 0) ~ sex, design = dpbc)
s2
svyjskm(s1)
svyjskm(s2, pval = T, table = T, design = dpbc)
svyjskm(s2, cumhaz = T, ylab = "Cumulative incidence (%)", surv.scale = "percent", pval = T, design = dpbc, pval.coord = c(300, 0.7), showpercent = T)
If you want to get confidence interval, you should
apply se = T
option to svykm
object.
<- svykm(Surv(time, status > 0) ~ sex, design = dpbc, se = T)
s3 svyjskm(s3)
svyjskm(s3, ci = F)
svyjskm(s3, ci = F, surv.scale = "percent", pval = T, table = T, cut.landmark = 1000, showpercent = T)
svyjskm(s2, theme = "jama", pval = T, table = T, design = dpbc)
svyjskm(s2, theme = "nejm", nejm.infigure.ratiow = 0.45, nejm.infigure.ratioh = 0.4, nejm.infigure.ylim = c(0.2, 1), pval = T, table = T, design = dpbc)