eth-mds / ricu

πŸ₯ ICU data with R πŸ₯
https://eth-mds.github.io/ricu/
GNU General Public License v3.0
33 stars 11 forks source link

Incorrect times when downgrading ID #24

Closed prockenschaub closed 1 year ago

prockenschaub commented 1 year ago

Downgrading the ID from icustay to patient leads to incorrect negative times.

x <- load_concepts('death', 'mimic_demo')
x
#> # A `ts_tbl`: 40 βœ– 3
#> # Id var:     `icustay_id`
#> # Index var:  `index_var` (1 hours)
#>    icustay_id index_var death
#>         <int> <drtn>    <lgl>
#>  1     201006 151 hours TRUE
#>  ...

change_id(x, 'subject_id', 'mimic_demo')[icustay_id == 201006]
#> # An `id_tbl`: 1 βœ– 4
#> # Id var:      `subject_id`
#>   subject_id icustay_id index_var      death
#>        <int>      <int> <drtn>         <lgl>
#> 1      10076     201006 -36212946 mins TRUE

The above should be positive, as it would otherwise imply negative lifetime. I believe the issue is the following substraction in change_id_helper, which works fine for upgrade_id but is incorrect for downgrade_id.

https://github.com/eth-mds/ricu/blob/9e76c074250046da93870063c3b7ed57d274b790/R/data-utils.R#L753

For downgrade_id, this should be an addition.