diff --git a/404.html b/404.html index a053d175..6d49f63b 100644 --- a/404.html +++ b/404.html @@ -36,7 +36,7 @@ AMR (for R) - 1.8.1.9046 + 1.8.1.9047 + + + + + +
+
+
+ +
+

This function calculates a normalised mean for antimicrobial resistance between multiple observations.

+
+ +
+

Usage

+
mean_amr_distance(x, ...)
+
+# S3 method for default
+mean_amr_distance(x, ...)
+
+# S3 method for mic
+mean_amr_distance(x, ...)
+
+# S3 method for disk
+mean_amr_distance(x, ...)
+
+# S3 method for rsi
+mean_amr_distance(x, combine_SI = TRUE, ...)
+
+# S3 method for data.frame
+mean_amr_distance(x, ..., combine_SI = TRUE)
+
+distance_from_row(mean_distance, row)
+
+ +
+

Arguments

+
x
+

a vector of class rsi, rsi or rsi, or a data.frame containing columns of any of these classes

+ + +
...
+

variables to select (supports tidy selection such as column1:column4 and where(is.mic)), and can thus also be antibiotic selectors

+ + +
combine_SI
+

a logical to indicate whether all values of S and I must be merged into one, so the input only consists of S+I vs. R (susceptible vs. resistant), defaults to TRUE

+ + +
mean_distance
+

the outcome of mean_amr_distance()

+ + +
row
+

an index, such as a row number

+ +
+
+

Details

+

The mean AMR distance is a normalised numeric value to compare AMR test results and can help to identify similar isolates, without comparing antibiograms by hand. For common numeric data this distance is equal to Z scores (the number of standard deviations from the mean).

+

MIC values (see as.mic()) are transformed with log2() first; their distance is calculated as (log2(x) - mean(log2(x))) / sd(log2(x)).

+

R/SI values (see as.rsi()) are transformed using "S" = 1, "I" = 2, and "R" = 3. If combine_SI is TRUE (default), the "I" will be considered to be 1.

+

For data sets, the mean AMR distance will be calculated per variable, after which the mean of all columns will returned per row (using rowMeans()), see Examples.

+

Use distance_from_row() to subtract distances from the distance of one row, see Examples.

+
+
+

Interpretation

+ + +

Isolates with distances less than 0.01 difference from each other should be considered similar. Differences lower than 0.025 should be considered suspicious.

+
+ +
+

Examples

+
x <- random_mic(10)
+x
+#> Class <mic>
+#>  [1] 0.5     4       >=128   <=0.002 0.25    32      0.25    0.025   4      
+#> [10] 0.005  
+mean_amr_distance(x)
+#>  [1]  0.01781163  0.59141290  1.54741502 -1.50524970 -0.17338879  1.16501418
+#>  [7] -0.17338879 -0.80854285  0.59141290 -1.25249649
+
+y <- data.frame(id = LETTERS[1:10],
+                amox = random_mic(10, ab = "amox", mo = "Escherichia coli"),
+                cipr = random_mic(10, ab = "cipr", mo = "Escherichia coli"),
+                gent = random_mic(10, ab = "gent", mo = "Escherichia coli"),
+                tobr = random_mic(10, ab = "tobr", mo = "Escherichia coli"))
+y
+#>    id amox   cipr  gent   tobr
+#> 1   A    8   0.25     1      8
+#> 2   B   32    0.5 <=0.5 <=0.25
+#> 3   C    8 0.0625 <=0.5      8
+#> 4   D   16      1     1      4
+#> 5   E   16  0.125     4      1
+#> 6   F    8      1     1    0.5
+#> 7   G   32 0.0625     1      8
+#> 8   H   16   0.25 <=0.5 <=0.25
+#> 9   I    4   0.25     4      1
+#> 10  J   16 0.0625     2      1
+mean_amr_distance(y)
+#> ℹ Calculating mean AMR distance based on columns "amox", "cipr", "gent",
+#>   "id" and "tobr"
+#> Warning: NAs introduced by coercion
+#>  [1]  0.1021142 -0.0512292 -0.4408420  0.5640747  0.2717444 -0.0723823
+#>  [7]  0.3064119 -0.4761266 -0.0939276 -0.1098375
+y$amr_distance <- mean_amr_distance(y, where(is.mic))
+#> ℹ Calculating mean AMR distance based on columns "amox", "cipr", "gent" and
+#>   "tobr"
+y[order(y$amr_distance), ]
+#>    id amox   cipr  gent   tobr amr_distance
+#> 8   H   16   0.25 <=0.5 <=0.25   -0.4761266
+#> 3   C    8 0.0625 <=0.5      8   -0.4408420
+#> 10  J   16 0.0625     2      1   -0.1098375
+#> 9   I    4   0.25     4      1   -0.0939276
+#> 6   F    8      1     1    0.5   -0.0723823
+#> 2   B   32    0.5 <=0.5 <=0.25   -0.0512292
+#> 1   A    8   0.25     1      8    0.1021142
+#> 5   E   16  0.125     4      1    0.2717444
+#> 7   G   32 0.0625     1      8    0.3064119
+#> 4   D   16      1     1      4    0.5640747
+
+if (require("dplyr")) {
+  y %>% 
+    mutate(amr_distance = mean_amr_distance(., where(is.mic)),
+           check_id_C = distance_from_row(amr_distance, id == "C")) %>% 
+    arrange(check_id_C)
+}
+#> ℹ Calculating mean AMR distance based on columns "amox", "cipr", "gent" and
+#>   "tobr"
+#>    id amox   cipr  gent   tobr amr_distance check_id_C
+#> 1   C    8 0.0625 <=0.5      8   -0.4408420  0.0000000
+#> 2   H   16   0.25 <=0.5 <=0.25   -0.4761266  0.0352847
+#> 3   J   16 0.0625     2      1   -0.1098375  0.3310044
+#> 4   I    4   0.25     4      1   -0.0939276  0.3469144
+#> 5   F    8      1     1    0.5   -0.0723823  0.3684596
+#> 6   B   32    0.5 <=0.5 <=0.25   -0.0512292  0.3896127
+#> 7   A    8   0.25     1      8    0.1021142  0.5429562
+#> 8   E   16  0.125     4      1    0.2717444  0.7125863
+#> 9   G   32 0.0625     1      8    0.3064119  0.7472539
+#> 10  D   16      1     1      4    0.5640747  1.0049167
+if (require("dplyr")) {
+  # support for groups
+  example_isolates %>%
+    filter(mo_genus() == "Enterococcus" & mo_species() != "") %>%
+    select(mo, TCY, carbapenems()) %>%
+    group_by(mo) %>%
+    mutate(d = mean_amr_distance(., where(is.rsi))) %>%
+    arrange(mo, d)
+}
+#> ℹ Using column 'mo' as input for `mo_genus()`
+#> ℹ Using column 'mo' as input for `mo_species()`
+#> ℹ For `carbapenems()` using columns 'IPM' (imipenem) and 'MEM' (meropenem)
+#> ℹ Calculating mean AMR distance based on columns "IPM", "MEM" and "TCY"
+#> # A tibble: 63 × 5
+#> # Groups:   mo [4]
+#>    mo           TCY   IPM   MEM         d
+#>    <mo>         <rsi> <rsi> <rsi>   <dbl>
+#>  1 B_ENTRC_AVIM S     S     NA    NaN    
+#>  2 B_ENTRC_AVIM S     S     NA    NaN    
+#>  3 B_ENTRC_CSSL NA    S     NA     NA    
+#>  4 B_ENTRC_FACM S     S     NA     -2.66 
+#>  5 B_ENTRC_FACM S     R     R      -0.423
+#>  6 B_ENTRC_FACM S     R     R      -0.423
+#>  7 B_ENTRC_FACM NA    R     R       0.224
+#>  8 B_ENTRC_FACM NA    R     R       0.224
+#>  9 B_ENTRC_FACM NA    R     R       0.224
+#> 10 B_ENTRC_FACM NA    R     R       0.224
+#> # … with 53 more rows
+
+
+
+ + +
+ + + + + + + diff --git a/reference/microorganisms.codes.html b/reference/microorganisms.codes.html index 4303b0cc..21acdd26 100644 --- a/reference/microorganisms.codes.html +++ b/reference/microorganisms.codes.html @@ -10,7 +10,7 @@ AMR (for R) - 1.8.1.9046 + 1.8.1.9047