count.Rd
These functions can be used to count resistant/susceptible microbial isolates. All functions support quasiquotation with pipes, can be used in dplyr
s summarise
and support grouped variables, see Examples.
count_R
and count_IR
can be used to count resistant isolates, count_S
and count_SI
can be used to count susceptible isolates.
count_R(..., also_single_tested = FALSE) count_IR(..., also_single_tested = FALSE) count_I(..., also_single_tested = FALSE) count_SI(..., also_single_tested = FALSE) count_S(..., also_single_tested = FALSE) count_all(...) n_rsi(...) count_df(data, translate_ab = getOption("get_antibiotic_names", "official"), combine_IR = FALSE)
... | one or more vectors (or columns) with antibiotic interpretations. They will be transformed internally with |
---|---|
also_single_tested | a logical to indicate whether (in combination therapies) also observations should be included where not all antibiotics were tested, but at least one of the tested antibiotics contains a target interpretation (e.g. S in case of |
data | a |
translate_ab | a column name of the |
combine_IR | a logical to indicate whether all values of I and R must be merged into one, so the output only consists of S vs. IR (susceptible vs. non-susceptible) |
Wickham H. Tidy Data. The Journal of Statistical Software, vol. 59, 2014. http://vita.had.co.nz/papers/tidy-data.html
Integer
These functions are meant to count isolates. Use the portion_*
functions to calculate microbial resistance.
n_rsi
is an alias of count_all
. They can be used to count all available isolates, i.e. where all input antibiotics have an available result (S, I or R). Their use is equal to n_distinct
. Their function is equal to count_S(...) + count_IR(...)
.
count_df
takes any variable from data
that has an "rsi"
class (created with as.rsi
) and counts the amounts of R, I and S. The resulting tidy data (see Source) data.frame
will have three rows (S/I/R) and a column for each variable with class "rsi"
.
portion_*
to calculate microbial resistance and susceptibility.
# septic_patients is a data set available in the AMR package. It is true, genuine data. ?septic_patients#># Count resistant isolates count_R(septic_patients$amox)#> [1] 683count_IR(septic_patients$amox)#> [1] 686# Or susceptible isolates count_S(septic_patients$amox)#> [1] 486count_SI(septic_patients$amox)#> [1] 489# Count all available isolates count_all(septic_patients$amox)#> [1] 1172n_rsi(septic_patients$amox)#> [1] 1172# Since n_rsi counts available isolates, you can # calculate back to count e.g. non-susceptible isolates. # This results in the same: count_IR(septic_patients$amox)#> [1] 686#> [1] 686library(dplyr) septic_patients %>% group_by(hospital_id) %>% summarise(R = count_R(cipr), I = count_I(cipr), S = count_S(cipr), n1 = count_all(cipr), # the actual total; sum of all three n2 = n_rsi(cipr), # same - analogous to n_distinct total = n()) # NOT the amount of tested isolates!#> # A tibble: 4 x 7 #> hospital_id R I S n1 n2 total #> <fct> <int> <int> <int> <int> <int> <int> #> 1 A 26 3 178 207 207 321 #> 2 B 85 35 379 499 499 663 #> 3 C 41 22 139 202 202 254 #> 4 D 76 9 416 501 501 762# Count co-resistance between amoxicillin/clav acid and gentamicin, # so we can see that combination therapy does a lot more than mono therapy. # Please mind that `portion_S` calculates percentages right away instead. count_S(septic_patients$amcl) # S = 1057 (67.1%)#> [1] 1291count_all(septic_patients$amcl) # n = 1576#> [1] 1828count_S(septic_patients$gent) # S = 1372 (74.0%)#> [1] 1372count_all(septic_patients$gent) # n = 1855#> [1] 1855#> [1] 1609#> [1] 1747# Get portions S/I/R immediately of all rsi columns septic_patients %>% select(amox, cipr) %>% count_df(translate = FALSE)#> Interpretation Antibiotic Value #> 1 S amox 486 #> 2 I amox 3 #> 3 R amox 683 #> 4 S cipr 1112 #> 5 I cipr 69 #> 6 R cipr 228# It also supports grouping variables septic_patients %>% select(hospital_id, amox, cipr) %>% group_by(hospital_id) %>% count_df(translate = FALSE)#> # A tibble: 24 x 4 #> Interpretation hospital_id Antibiotic Value #> <ord> <fct> <chr> <int> #> 1 S A amox 63 #> 2 S B amox 141 #> 3 S C amox 59 #> 4 S D amox 223 #> 5 I A amox 0 #> 6 I B amox 1 #> 7 I C amox 0 #> 8 I D amox 2 #> 9 R A amox 87 #> 10 R B amox 231 #> # ... with 14 more rows