Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

as.rsi

Interpret MIC and Disk Values, or Clean Raw R/SI Data


Description

Interpret minimum inhibitory concentration (MIC) values and disk diffusion diameters according to EUCAST or CLSI, or clean up existing R/SI values. This transforms the input to a new class rsi, which is an ordered factor with levels S < I < R. Values that cannot be interpreted will be returned as NA with a warning.

Usage

as.rsi(x, ...)

is.rsi(x)

is.rsi.eligible(x, threshold = 0.05)

## S3 method for class 'mic'
as.rsi(
  x,
  mo = NULL,
  ab = deparse(substitute(x)),
  guideline = "EUCAST",
  uti = FALSE,
  conserve_capped_values = FALSE,
  add_intrinsic_resistance = FALSE,
  reference_data = AMR::rsi_translation,
  ...
)

## S3 method for class 'disk'
as.rsi(
  x,
  mo = NULL,
  ab = deparse(substitute(x)),
  guideline = "EUCAST",
  uti = FALSE,
  add_intrinsic_resistance = FALSE,
  reference_data = AMR::rsi_translation,
  ...
)

## S3 method for class 'data.frame'
as.rsi(
  x,
  ...,
  col_mo = NULL,
  guideline = "EUCAST",
  uti = NULL,
  conserve_capped_values = FALSE,
  add_intrinsic_resistance = FALSE,
  reference_data = AMR::rsi_translation
)

Arguments

x

vector of values (for class mic: an MIC value in mg/L, for class disk: a disk diffusion radius in millimetres)

...

for using on a data.frame: names of columns to apply as.rsi() on (supports tidy selection like AMX:VAN). Otherwise: arguments passed on to methods.

threshold

maximum fraction of invalid antimicrobial interpretations of x, see Examples

mo

any (vector of) text that can be coerced to a valid microorganism code with as.mo(), can be left empty to determine it automatically

ab

any (vector of) text that can be coerced to a valid antimicrobial code with as.ab()

guideline

defaults to the latest included EUCAST guideline, see Details for all options

uti

(Urinary Tract Infection) A vector with logicals (TRUE or FALSE) to specify whether a UTI specific interpretation from the guideline should be chosen. For using as.rsi() on a data.frame, this can also be a column containing logicals or when left blank, the data set will be searched for a 'specimen' and rows containing 'urin' (such as 'urine', 'urina') in that column will be regarded isolates from a UTI. See Examples.

conserve_capped_values

a logical to indicate that MIC values starting with ">" (but not ">=") must always return "R" , and that MIC values starting with "<" (but not "<=") must always return "S"

add_intrinsic_resistance

(only useful when using a EUCAST guideline) a logical to indicate whether intrinsic antibiotic resistance must also be considered for applicable bug-drug combinations, meaning that e.g. ampicillin will always return "R" in Klebsiella species. Determination is based on the intrinsic_resistant data set, that itself is based on 'EUCAST Expert Rules' and 'EUCAST Intrinsic Resistance and Unusual Phenotypes' v3.2 (2020).

reference_data

a data.frame to be used for interpretation, which defaults to the rsi_translation data set. Changing this argument allows for using own interpretation guidelines. This argument must contain a data set that is equal in structure to the rsi_translation data set (same column names and column types). Please note that the guideline argument will be ignored when reference_data is manually set.

col_mo

column name of the IDs of the microorganisms (see as.mo()), defaults to the first column of class mo. Values will be coerced using as.mo().

Details

How it Works

The as.rsi() function works in four ways:

  1. For cleaning raw / untransformed data. The data will be cleaned to only contain values S, I and R and will try its best to determine this with some intelligence. For example, mixed values with R/SI interpretations and MIC values such as "<0.25; S" will be coerced to "S". Combined interpretations for multiple test methods (as seen in laboratory records) such as "S; S" will be coerced to "S", but a value like "S; I" will return NA with a warning that the input is unclear.

  2. For interpreting minimum inhibitory concentration (MIC) values according to EUCAST or CLSI. You must clean your MIC values first using as.mic(), that also gives your columns the new data class mic. Also, be sure to have a column with microorganism names or codes. It will be found automatically, but can be set manually using the mo argument.

    • Using dplyr, R/SI interpretation can be done very easily with either:

      your_data %>% mutate_if(is.mic, as.rsi)         # until dplyr 1.0.0
      your_data %>% mutate(across((is.mic), as.rsi))  # since dplyr 1.0.0
      
    • Operators like "<=" will be stripped before interpretation. When using conserve_capped_values = TRUE, an MIC value of e.g. ">2" will always return "R", even if the breakpoint according to the chosen guideline is ">=4". This is to prevent that capped values from raw laboratory data would not be treated conservatively. The default behaviour (conserve_capped_values = FALSE) considers ">2" to be lower than ">=4" and might in this case return "S" or "I".

  3. For interpreting disk diffusion diameters according to EUCAST or CLSI. You must clean your disk zones first using as.disk(), that also gives your columns the new data class disk. Also, be sure to have a column with microorganism names or codes. It will be found automatically, but can be set manually using the mo argument.

    • Using dplyr, R/SI interpretation can be done very easily with either:

      your_data %>% mutate_if(is.disk, as.rsi)         # until dplyr 1.0.0
      your_data %>% mutate(across((is.disk), as.rsi))  # since dplyr 1.0.0
      
  4. For interpreting a complete data set, with automatic determination of MIC values, disk diffusion diameters, microorganism names or codes, and antimicrobial test results. This is done very simply by running as.rsi(data).

Supported Guidelines

For interpreting MIC values as well as disk diffusion diameters, supported guidelines to be used as input for the guideline argument are: "EUCAST 2021", "EUCAST 2020", "EUCAST 2019", "EUCAST 2018", "EUCAST 2017", "EUCAST 2016", "EUCAST 2015", "EUCAST 2014", "EUCAST 2013", "EUCAST 2012", "EUCAST 2011", "CLSI 2019", "CLSI 2018", "CLSI 2017", "CLSI 2016", "CLSI 2015", "CLSI 2014", "CLSI 2013", "CLSI 2012", "CLSI 2011" and "CLSI 2010".

Simply using "CLSI" or "EUCAST" as input will automatically select the latest version of that guideline. You can set your own data set using the reference_data argument. The guideline argument will then be ignored.

After Interpretation

After using as.rsi(), you can use the eucast_rules() defined by EUCAST to (1) apply inferred susceptibility and resistance based on results of other antimicrobials and (2) apply intrinsic resistance based on taxonomic properties of a microorganism.

Machine-Readable Interpretation Guidelines

The repository of this package contains a machine-readable version of all guidelines. This is a CSV file consisting of 20,486 rows and 10 columns. This file is machine-readable, since it contains one row for every unique combination of the test method (MIC or disk diffusion), the antimicrobial agent and the microorganism. This allows for easy implementation of these rules in laboratory information systems (LIS). Note that it only contains interpretation guidelines for humans - interpretation guidelines from CLSI for animals were removed.

Other

The function is.rsi() detects if the input contains class <rsi>. If the input is a data.frame, it iterates over all columns and returns a logical vector.

The function is.rsi.eligible() returns TRUE when a columns contains at most 5% invalid antimicrobial interpretations (not S and/or I and/or R), and FALSE otherwise. The threshold of 5% can be set with the threshold argument. If the input is a data.frame, it iterates over all columns and returns a logical vector.

Value

Ordered factor with new class <rsi>

Interpretation of R and S/I

In 2019, the European Committee on Antimicrobial Susceptibility Testing (EUCAST) has decided to change the definitions of susceptibility testing categories R and S/I as shown below (https://www.eucast.org/newsiandr/).

  • R = Resistant
    A microorganism is categorised as Resistant when there is a high likelihood of therapeutic failure even when there is increased exposure. Exposure is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection.

  • S = Susceptible
    A microorganism is categorised as Susceptible, standard dosing regimen, when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent.

  • I = Increased exposure, but still susceptible
    A microorganism is categorised as Susceptible, Increased exposure when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection.

This AMR package honours this new insight. Use susceptibility() (equal to proportion_SI()) to determine antimicrobial susceptibility and count_susceptible() (equal to count_SI()) to count susceptible isolates.

Stable Lifecycle


The lifecycle of this function is stable. In a stable function, major changes are unlikely. This means that the unlying code will generally evolve by adding new arguments; removing arguments or changing the meaning of existing arguments will be avoided.

If the unlying code needs breaking changes, they will occur gradually. For example, a argument will be deprecated and first continue to work, but will emit an message informing you of the change. Next, typically after at least one newly released version on CRAN, the message will be transformed to an error.

Reference Data Publicly Available

All reference data sets (about microorganisms, antibiotics, R/SI interpretation, EUCAST rules, etc.) in this AMR package are publicly and freely available. We continually export our data sets to formats for use in R, SPSS, SAS, Stata and Excel. We also supply flat files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please find all download links on our website, which is automatically updated with every code change.

Read more on Our Website!

On our website https://msberends.github.io/AMR/ you can find a comprehensive tutorial about how to conduct AMR data analysis, the complete documentation of all functions and an example analysis using WHONET data. As we would like to better understand the backgrounds and needs of our users, please participate in our survey!

See Also

Examples

summary(example_isolates) # see all R/SI results at a glance

if (require("skimr")) {
  # class <rsi> supported in skim() too:
  skim(example_isolates)
}

# For INTERPRETING disk diffusion and MIC values -----------------------
       
# a whole data set, even with combined MIC values and disk zones
df <- data.frame(microorganism = "Escherichia coli",
                 AMP = as.mic(8),
                 CIP = as.mic(0.256),
                 GEN = as.disk(18),
                 TOB = as.disk(16),
                 NIT = as.mic(32),
                 ERY = "R")
as.rsi(df)

# for single values
as.rsi(x = as.mic(2),
       mo = as.mo("S. pneumoniae"),
       ab = "AMP",
       guideline = "EUCAST")

as.rsi(x = as.disk(18),
       mo = "Strep pneu",  # `mo` will be coerced with as.mo()
       ab = "ampicillin",  # and `ab` with as.ab()
       guideline = "EUCAST")


# the dplyr way
if (require("dplyr")) {
  df %>% mutate_if(is.mic, as.rsi)
  df %>% mutate_if(function(x) is.mic(x) | is.disk(x), as.rsi)
  df %>% mutate(across((is.mic), as.rsi))
  df %>% mutate_at(vars(AMP:TOB), as.rsi)
  df %>% mutate(across(AMP:TOB, as.rsi))
 
  df %>%
    mutate_at(vars(AMP:TOB), as.rsi, mo = .$microorganism)
    
  # to include information about urinary tract infections (UTI)
  data.frame(mo = "E. coli",
             NIT = c("<= 2", 32),
             from_the_bladder = c(TRUE, FALSE)) %>%
    as.rsi(uti = "from_the_bladder")
    
  data.frame(mo = "E. coli",
             NIT = c("<= 2", 32),
             specimen = c("urine", "blood")) %>%
    as.rsi() # automatically determines urine isolates
  
  df %>%
    mutate_at(vars(AMP:NIT), as.rsi, mo = "E. coli", uti = TRUE)  
}

# For CLEANING existing R/SI values ------------------------------------

as.rsi(c("S", "I", "R", "A", "B", "C"))
as.rsi("<= 0.002; S") # will return "S"
rsi_data <- as.rsi(c(rep("S", 474), rep("I", 36), rep("R", 370)))
is.rsi(rsi_data)
plot(rsi_data)    # for percentages
barplot(rsi_data) # for frequencies

# the dplyr way
if (require("dplyr")) {
  example_isolates %>%
    mutate_at(vars(PEN:RIF), as.rsi)
  # same:   
  example_isolates %>%
    as.rsi(PEN:RIF)
 
  # fastest way to transform all columns with already valid AMR results to class `rsi`:
  example_isolates %>%
    mutate_if(is.rsi.eligible, as.rsi)
    
  # note: from dplyr 1.0.0 on, this will be: 
  # example_isolates %>%
  #   mutate(across((is.rsi.eligible), as.rsi))
}

AMR

Antimicrobial Resistance Data Analysis

v1.6.0
GPL-2 | file LICENSE
Authors
Matthijs S. Berends [aut, cre] (<https://orcid.org/0000-0001-7620-1800>), Christian F. Luz [aut, ctb] (<https://orcid.org/0000-0001-5809-5995>), Alexander W. Friedrich [aut, ths] (<https://orcid.org/0000-0003-4881-038X>), Bhanu N. M. Sinha [aut, ths] (<https://orcid.org/0000-0003-1634-0010>), Casper J. Albers [aut, ths] (<https://orcid.org/0000-0002-9213-6743>), Corinna Glasner [aut, ths] (<https://orcid.org/0000-0003-1241-1328>), Judith M. Fonville [ctb], Erwin E. A. Hassing [ctb], Eric H. L. C. M. Hazenberg [ctb], Gwen Knight [ctb], Annick Lenglet [ctb], Bart C. Meijer [ctb], Sofia Ny [ctb], Rogier P. Schade [ctb], Dennis Souverein [ctb], Anthony Underwood [ctb]
Initial release
2021-03-14

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.