tidycmprsk icon indicating copy to clipboard operation
tidycmprsk copied to clipboard

`crr()` function does not work using the `with()` function

Open ABohynDOE opened this issue 1 month ago • 2 comments

To fit a competing risk model with the tidycmprsk package I can use the following syntax

library(tidycmprsk)
#> Warning: package 'tidycmprsk' was built under R version 4.3.2

crr_mod <- crr(Surv(ttdeath, death_cr) ~ age + trt, trial)
#> 11 cases omitted due to missing values

However, if I want to run the model using the with syntax, it does not work

library(tidycmprsk)
#> Warning: package 'tidycmprsk' was built under R version 4.3.2

crr_mod <- with(trial, crr(Surv(ttdeath, death_cr) ~ age))
#> ✖ There was an error evaluating the LHS of the formula.
#> Error: Error in crr.formula(Surv(ttdeath, death_cr) ~ age): argument "data" is missing, with no default

Is this on a normal behavior or is this a bug ?

Context

The reason I might want to use this syntax is if I want to pool estimates from several competing risk models when using multiple imputation. For example, if I impute the 11 missing values in the age column, I can then fit a model for each imputation and combine the results. However, to combine the estimates I need to fit the model using the with syntax.

library(tidycmprsk)
#> Warning: package 'tidycmprsk' was built under R version 4.3.2

imp <- mice::mice(trial)

pooled_crr_mod <- with(trial, crr(Surv(ttdeath, death_cr) ~ age))
#> ✖ There was an error evaluating the LHS of the formula.
#> Error: Error in crr.formula(Surv(ttdeath, death_cr) ~ age): argument "data" is missing, with no default

mice::pool(pooled_crr_mod)
#> Error in eval(expr, envir, enclos): object 'pooled_crr_mod' not found

Created on 2024-05-13 with reprex v2.1.0

If the current behavior of crr() is normal, is there a workaround to use for this context ?

ABohynDOE avatar May 13 '24 14:05 ABohynDOE