Skip to content

Commit d9eeb1b

Browse files
jinseob2kimclaude
andcommitted
Update competing risk HR calculation to use survival::finegray
- Change from cmprsk::crr() to survival::finegray() + coxph(id = id) - Update DESCRIPTION version to 0.5.21 - Update NEWS.md with changes - Update imports: add survival::finegray, remove cmprsk::crr 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent b0732c6 commit d9eeb1b

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: jskm
22
Title: Kaplan-Meier Plot with 'ggplot2'
3-
Version: 0.5.20
4-
Date: 2025-10-01
3+
Version: 0.5.21
4+
Date: 2025-10-24
55
Authors@R: c(person("Jinseob", "Kim", email = "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-9403-605X")),
66
person("yoonkyoung", "Chun", email = "[email protected]", role = "aut"),
77
person("Zarathu", role = c("cph", "fnd")),

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# jskm 0.5.21
2+
* Update: Change competing risk HR calculation from `cmprsk::crr()` to `survival::finegray()` + `coxph(id = id)`.
3+
14
# jskm 0.5.20
25
* Update: Add `left.nrisk` option to the risktable in `jskm`and `svyjskm`.
36

R/jskm.R

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@
8787
#' @importFrom ggpubr ggarrange
8888
#' @importFrom stats pchisq time as.formula
8989
#' @importFrom patchwork inset_element
90-
#' @importFrom survival survfit survdiff coxph Surv cluster frailty
91-
#' @importFrom cmprsk cuminc crr
90+
#' @importFrom survival survfit survdiff coxph Surv cluster frailty finegray
91+
#' @importFrom cmprsk cuminc
9292
#' @importFrom ggsci scale_color_npg scale_fill_npg scale_color_aaas scale_fill_aaas scale_color_nejm scale_fill_nejm scale_color_lancet scale_fill_lancet scale_color_jama scale_fill_jama scale_color_jco scale_fill_jco scale_color_frontiers scale_fill_frontiers
9393
#' @export
9494

@@ -818,16 +818,25 @@ jskm <- function(sfit,
818818
# w/o Landmark
819819
if (is.null(cut.landmark)) {
820820

821-
# 1) competing risk: Fine-Gray
821+
# 1) competing risk: Fine-Gray using survival::finegray
822822
if (!is.null(status.cmprsk)) {
823-
fg_model <- cmprsk::crr(ftime = data[[time_var]],
824-
fstatus = data[[event_var]],
825-
cov1 = as.matrix(data[[group_var]]))
826-
HR_value <- exp(fg_model$coef[1])
827-
HR_ci_lower <- exp(fg_model$coef[1] - 1.96 * sqrt(fg_model$var[1,1]))
828-
HR_ci_upper <- exp(fg_model$coef[1] + 1.96 * sqrt(fg_model$var[1,1]))
823+
# Get unique ID if not exists
824+
if (!"id" %in% names(data)) {
825+
data$id <- 1:nrow(data)
826+
}
827+
828+
# Create finegray dataset
829+
fg_data <- survival::finegray(as.formula(form), data = data, etype = status.cmprsk)
830+
831+
# Fit Cox model with id
832+
cox_form <- as.formula(paste("Surv(fgstart, fgstop, fgstatus) ~", group_var))
833+
fg_model <- survival::coxph(cox_form, data = fg_data, id = id, weights = fgwt)
834+
835+
HR_value <- summary(fg_model)$coefficients[,"exp(coef)"][1]
836+
HR_ci_lower <- summary(fg_model)$conf.int[1, "lower .95"]
837+
HR_ci_upper <- summary(fg_model)$conf.int[1, "upper .95"]
829838
test_type <- "Fine-Gray Model"
830-
pval <- 2 * (1 - pnorm(abs(fg_model$coef[1] / sqrt(fg_model$var[1,1]))))
839+
pval <- summary(fg_model)$coefficients[, "Pr(>|z|)"][1]
831840

832841

833842
# 2) weights: Weighted cox
@@ -875,7 +884,7 @@ jskm <- function(sfit,
875884
}
876885
# HR text
877886
hr_txt <- ifelse(HR_value < 0.001, "HR < 0.001", paste("HR =", round(HR_value, 2)))
878-
hr_txt <- paste0(hr_txt, " (95% CI: ", round(HR_ci_lower, 2), " ", round(HR_ci_upper, 2), "; P = ", round(pval, 3), ")")
887+
hr_txt <- paste0(hr_txt, " (95% CI: ", round(HR_ci_lower, 2), " ", round(HR_ci_upper, 2), "; P = ", ifelse(pval < 0.001, "<0.001", round(pval, 3)), ")")
879888

880889
if ((hr.testname == T) & !is.null(test_type)) {
881890
hr_txt <- paste0(hr_txt, " (", test_type, ")")

R/svyjskm.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ svyjskm <- function(sfit,
732732

733733
# HR text
734734
hr_text <- paste0("HR = ", hr_value, " (95% CI: ", hr_ci_lower, " - ", hr_ci_upper,
735-
ifelse(hr_pval < 0.001, "; p < 0.001", paste("; p =", hr_pval)), ")")
735+
ifelse(hr_pval < 0.001, "; P < 0.001", paste("; P =", hr_pval)), ")")
736736

737737
# HR placement
738738
if (is.null(hr.coord)) {

0 commit comments

Comments
 (0)