cran / tidycmprsk

:exclamation: This is a read-only mirror of the CRAN R package repository. tidycmprsk — Competing Risks Estimation. Homepage: https://mskcc-epi-bio.github.io/tidycmprsk/, https://github.com/MSKCC-Epi-Bio/tidycmprsk Report bugs for this package: https://github.com/MSKCC-Epi-Bio/tidycmprsk/issues
2 stars 1 forks source link

Unexpected outputs using `add_global_p()` with `crr()` #1

Closed fdehrich closed 1 year ago

fdehrich commented 1 year ago

Hello,

Re-posting this issue from {gtsummary} since it was identified as a better fit for {tidycmprsk}.

When using add_global_p() with crr(), I noticed that, in some cases, releveling a 4-level categorical variable (keeping the reference category the same) causes the global p-value to change. More broadly, in these instances, the global p-value appears to consistently match the individual p-value corresponding to the third level for some reason.

I was able to recreate this issue using the tidycmprsk::trial dataset (I had to add some extra variables and used the death variable as a predictor which doesn't make sense, but helped me recreate for some reason). Below, the global p-value for new_categorical changes from >0.9 to 0.2 when the variable is releveled (but keeping A as the reference category).

Thank you!

  library(tidycmprsk)

# Update trial data to include additional variables
trial_updated =
  trial %>% 
  dplyr::mutate(
    new_binary = sample(c(0, 1), 
                        replace = TRUE, 
                        size = nrow(trial)),
    new_categorical = sample(c("A", "B", "C", "D"), 
                             replace = TRUE, 
                             size = nrow(trial))
  )

# Generate table
crr(Surv(ttdeath, death_cr) ~ ., 
    failcode = "death from cancer",
    cencode = "censor",
    trial_updated) %>%
  gtsummary::tbl_regression(exp = TRUE) %>%
  gtsummary::add_global_p(keep = TRUE) %>% 
  gtsummary::as_kable()
#> 27 cases omitted due to missing values
Characteristic HR 95% CI p-value
Chemotherapy Treatment 0.7
Drug A
Drug B 1.31 0.70, 2.45 0.4
Age 1.00 0.98, 1.03 0.5
Marker Level (ng/mL) 1.14 0.78, 1.67 0.5
T Stage 0.12
T1
T2 0.67 0.23, 1.96 0.5
T3 2.03 0.83, 4.92 0.12
T4 0.93 0.37, 2.37 0.9
Grade 0.5
I
II 1.80 0.82, 3.95 0.14
III 1.14 0.59, 2.21 0.7
Tumor Response 1.08 0.49, 2.37 \<0.001
Patient Died 110,310 65,336, 186,241 0.3
new_binary 1.49 0.73, 3.07 0.2
new_categorical >0.9
A
B 1.72 0.72, 4.06 0.2
C 1.06 0.38, 2.96 >0.9
D 1.83 0.72, 4.64 0.2

# Relevel `new_categorical` variable
trial_updated = 
  trial_updated %>% 
  dplyr::mutate(
    new_categorical = forcats::fct_relevel(
      new_categorical,
      "A", "C", "B", "D"
    )
  )

# Regenerate table
crr(Surv(ttdeath, death_cr) ~ ., 
    failcode = "death from cancer",
    cencode = "censor",
    trial_updated) %>%
  gtsummary::tbl_regression(exp = TRUE) %>%
  gtsummary::add_global_p(keep = TRUE) %>% 
  gtsummary::as_kable()
#> 27 cases omitted due to missing values
Characteristic HR 95% CI p-value
Chemotherapy Treatment 0.7
Drug A
Drug B 1.31 0.70, 2.45 0.4
Age 1.00 0.98, 1.03 0.5
Marker Level (ng/mL) 1.14 0.78, 1.67 0.5
T Stage 0.12
T1
T2 0.67 0.23, 1.96 0.5
T3 2.03 0.83, 4.92 0.12
T4 0.93 0.37, 2.37 0.9
Grade 0.5
I
II 1.80 0.82, 3.95 0.14
III 1.14 0.59, 2.21 0.7
Tumor Response 1.08 0.49, 2.37 \<0.001
Patient Died 110,310 65,336, 186,241 0.3
new_binary 1.49 0.73, 3.07 >0.9
new_categorical 0.2
A
C 1.06 0.38, 2.96 >0.9
B 1.72 0.72, 4.06 0.2
D 1.83 0.72, 4.64 0.2

Created on 2023-04-25 with reprex v2.0.2

gaborcsardi commented 1 year ago

Hi, this is a read only mirror of CRAN, please see the package authors in the DESCRIPTION file. Look for Maintainer, BugReports and URL. Thanks!

fdehrich commented 1 year ago

Sorry about that! Just posted there now