msberends / AMR

Functions to simplify and standardise antimicrobial resistance (AMR) data analysis and to work with microbial and antimicrobial properties by using evidence-based methods, as described in https://doi.org/10.18637/jss.v104.i03.

Home Page:https://msberends.github.io/AMR/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

First isolate: ICU filtering based on wrong ordering

msberends opened this issue · comments

See:

x <- x[order(x$newvar_row_index), , drop = FALSE]

This is not the case for col_icu:

library(AMR)
library(dplyr)

example_isolates %>% 
  mutate(first = first_isolate(col_icu = ward == "ICU",
                               icu_exclude = TRUE)) %>%
  count(ward, first)
#> Determining first isolates using an episode length of 365 days
#> ℹ Using column 'mo' as input for col_mo.
#> ℹ Using column 'date' as input for col_date.
#> ℹ Using column 'patient' as input for col_patient_id.
#> Basing inclusion on all antimicrobial results, using a points threshold of 2
#> Excluding 646 isolates from ICU.
#> ℹ Excluded 16 isolates with a microbial ID 'UNKNOWN' (in column 'mo')
#> => Found 942 'phenotype-based' first isolates (47.1% of total where a microbial ID was available)
#> # A tibble: 6 × 3
#>   ward       first     n
#>   <chr>      <lgl> <int>
#> 1 Clinical   FALSE   659
#> 2 Clinical   TRUE    575
#> 3 ICU        FALSE   346
#> 4 ICU        TRUE    300
#> 5 Outpatient FALSE    53
#> 6 Outpatient TRUE     67

Should not contain TRUE in ICU group.