metrumresearchgroup / lastdose

Fast computation of [time since] and [amount of] the most-recent dose in a data set
3 stars 2 forks source link

Unexpected TAD output #46

Open graceannobrien opened 2 months ago

graceannobrien commented 2 months ago

lastdose outputs different TAD for records with same DATETIME (rows 22, 23, 24). I would expect all to have TAD ==0 since they occur at same time as dose (row 21), but only one record has TAD == 0.

Example data: temp_tad.csv

> temp_tad[21:24,]
   USUBJID            DATETIME EVID DVID DV ADDL II AMT      TAD     TAFD LDOS
21  hidden 2019-04-16 09:50:00    1    0 99    0  0   0  0.00000 982.9167    0
22  hidden 2019-04-16 09:50:00    0    5 99    0  0  NA  0.00000 982.9167    0
23  hidden 2019-04-16 09:50:00    0    6 99    0  0  NA 22.33333 982.9167    0
24  hidden 2019-04-16 09:50:00    0    4 99    0  0  NA 22.33333 982.9167    0
andersone1 commented 1 month ago

@kylebaron Following up on this - it appears to be an issue, but we wanted to see what you thought.

kylebaron commented 1 month ago

Hey @andersone1 - sorry I didn't see this before. I need to check the code, but guessing that rows 23 and 24 are getting tagged as pre dose (they happen at the same time a the EVID 1 record, but they are getting sorted to happen before record 21 in sort order, so subject to the previous dose). When you sort on DATETIME, the actual order (record order) is random among records with the same value of DATETIME, so that's how it could happen. I thought I had some logic in the code to make sure to put all observations either before or after the dose at the same time to head this off, but will have to take a look. Thanks for reporting. Will look into this.