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

as.mic

Transform Input to Minimum Inhibitory Concentrations (MIC)


Description

This ransforms vectors to a new class mic, which treats the input as decimal numbers, while maintaining operators (such as ">=") and only allowing valid MIC values known to the field of (medical) microbiology.

Usage

as.mic(x, na.rm = FALSE)

is.mic(x)

Arguments

x

character or numeric vector

na.rm

a logical indicating whether missing values should be removed

Details

To interpret MIC values as RSI values, use as.rsi() on MIC values. It supports guidelines from EUCAST and CLSI.

This class for MIC values is a quite a special data type: formally it is an ordered factor with valid MIC values as factor levels (to make sure only valid MIC values are retained), but for any mathematical operation it acts as decimal numbers:

x <- random_mic(10)
x
#> Class <mic>
#>  [1] 16     1      8      8      64     >=128  0.0625 32     32     16

is.factor(x)
#> [1] TRUE

x[1] * 2
#> [1] 32

median(x)
#> [1] 26

This makes it possible to maintain operators that often come with MIC values, such ">=" and "<=", even when filtering using numeric values in data analysis, e.g.:

x[x > 4]
#> Class <mic>
#> [1] 16    8     8     64    >=128 32    32    16

df <- data.frame(x, hospital = "A")
subset(df, x > 4) # or with dplyr: df %>% filter(x > 4)
#>        x hospital
#> 1     16        A
#> 5     64        A
#> 6  >=128        A
#> 8     32        A
#> 9     32        A
#> 10    16        A

The following generic functions are implemented for the MIC class: !, !=, %%, %/%, &, *, +, -, /, <, <=, ==, >, >=, ^, |, abs(), acos(), acosh(), all(), any(), asin(), asinh(), atan(), atanh(), ceiling(), cos(), cosh(), cospi(), cummax(), cummin(), cumprod(), cumsum(), digamma(), exp(), expm1(), floor(), gamma(), lgamma(), log(), log1p(), log2(), log10(), max(), mean(), min(), prod(), range(), round(), sign(), signif(), sin(), sinh(), sinpi(), sqrt(), sum(), tan(), tanh(), tanpi(), trigamma() and trunc(). Some functions of the stats package are also implemented: median(), quantile(), mad(), IQR(), fivenum(). Also, boxplot.stats() is supported. Since sd() and var() are non-generic functions, these could not be extended. Use mad() as an alternative, or use e.g. sd(as.numeric(x)) where x is your vector of MIC values.

Value

Ordered factor with additional class mic, that in mathematical operations acts as decimal numbers. Bare in mind that the outcome of any mathematical operation on MICs will return a numeric value.

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.

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

mic_data <- as.mic(c(">=32", "1.0", "1", "1.00", 8, "<=0.128", "8", "16", "16"))
is.mic(mic_data)

# this can also coerce combined MIC/RSI values:
as.mic("<=0.002; S") # will return <=0.002

# mathematical processing treats MICs as numeric values
fivenum(mic_data)
quantile(mic_data)
all(mic_data < 512)

# interpret MIC values
as.rsi(x = as.mic(2),
       mo = as.mo("S. pneumoniae"),
       ab = "AMX",
       guideline = "EUCAST")
as.rsi(x = as.mic(4),
       mo = as.mo("S. pneumoniae"),
       ab = "AMX",
       guideline = "EUCAST")

# plot MIC values, see ?plot
plot(mic_data)
plot(mic_data, mo = "E. coli", ab = "cipro")

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.