larmarange / broom.helpers

A set of functions to facilitate manipulation of tibbles produced by broom
https://larmarange.github.io/broom.helpers/
GNU General Public License v3.0
21 stars 8 forks source link

Warning about lengths not being a multiples of one another #268

Closed ddsjoberg closed 3 weeks ago

ddsjoberg commented 3 weeks ago

Hey! I noticed this warning pop up. If you don't have the badnwidth, I can investigate in the next couple of weeks

survival::coxph(survival::Surv(ttdeath, death) ~ age, id = response, data = gtsummary::trial) |> 
  broom.helpers::tidy_plus_plus()
#> Warning in tcm * w/n_obs_per_ind: longer object length is not a multiple of
#> shorter object length
#> Warning in w/n_obs_per_ind: longer object length is not a multiple of shorter
#> object length
#> # A tibble: 1 × 21
#>   term  variable var_label var_class var_type   var_nlevels contrasts
#>   <chr> <chr>    <chr>     <chr>     <chr>            <int> <chr>    
#> 1 age   age      Age       numeric   continuous          NA <NA>     
#> # ℹ 14 more variables: contrasts_type <chr>, reference_row <lgl>, label <chr>,
#> #   n_obs <dbl>, n_ind <dbl>, n_event <dbl>, exposure <dbl>, estimate <dbl>,
#> #   std.error <dbl>, robust.se <dbl>, statistic <dbl>, p.value <dbl>,
#> #   conf.low <dbl>, conf.high <dbl>

Created on 2024-08-21 with reprex v2.1.1

larmarange commented 3 weeks ago

This is due to the fact that there are some missing values in response variable passed to id.

model.frame() properly remove these lines with missing values for the identifier but variable labels are lost in the process. model.frame.default() keep the variable labels but does not take into account the id.

So far, model_get_model_frame.coxph() used model.frame.default() to keep the variable resulting in an error in this specific case. I have updated the function to use instead model.frame(), copying then the variable labels from model.frame.default().

larmarange commented 3 weeks ago

done here #269

let me know if it looks ok for you