* Support for EUCAST Clinical Breakpoints v11.0 (2021), effective in the `eucast_rules()` function and in `as.rsi()` to interpret MIC and disk diffusion values. This is now the default guideline in this package.
@ -34,6 +34,7 @@
@@ -34,6 +34,7 @@
* WHONET code `"PNV"` will now correctly be interpreted as `PHN`, the antibiotic code for phenoxymethylpenicillin ('peni V')
* Fix for verbose output of `mdro(..., verbose = TRUE)` for German guideline (3MGRN and 4MGRN) and Dutch guideline (BRMO, only *P. aeruginosa*)
* `is.rsi.eligible()` now returns `FALSE` immediately if the input does not contain any of the values "R", "S" or "I". This drastically improves speed, also for a lot of other functions that rely on automatic determination of antibiotic columns.
* Functions `get_episode()` and `is_new_episode()` now support less than a day as value for argument `episode_days` (e.g., to include one patient/test per hour)
#' These functions determine which items in a vector can be considered (the start of) a new episode, based on the argument `episode_days`. This can be used to determine clinical episodes for any epidemiological analysis. The [get_episode()] function returns the index number of the episode per group, while the [is_new_episode()] function returns values `TRUE`/`FALSE` to indicate whether an item in a vector is the start of a new episode.
#' @inheritSection lifecycle Stable Lifecycle
#' @param x vector of dates (class `Date` or `POSIXt`)
#' @param episode_days length of the required episode in days, see *Details*
#' @param ... arguments passed on to [as.Date()]
#' @param episode_days required episode length in days, can also be less than a day, see *Details*
#' @param ... arguments passed on to [as.POSIXct()]
#' @details
#' Dates are first sorted from old to new. The oldest date will mark the start of the first episode. After this date, the next date will be marked that is at least `episode_days` days later than the start of the first episode. From that second marked date on, the next date will be marked that is at least `episode_days` days later than the start of the second episode which will be the start of the third episode, and so on. Before the vector is being returned, the original order will be restored.
#'
@ -44,15 +44,20 @@
@@ -44,15 +44,20 @@
#' @export
#' @inheritSection AMR Read more on Our Website!
#' @examples
#' # `example_isolates` is a dataset available in the AMR package.
#' # `example_isolates` is a dataset available in the AMR package.
#' @param include_unknown logical to determine whether 'unknown' microorganisms should be included too, i.e. microbial code `"UNKNOWN"`, which defaults to `FALSE`. For WHONET users, this means that all records with organism code `"con"` (*contamination*) will be excluded at default. Isolates with a microbial ID of `NA` will always be excluded as first isolate.
#' @param ... arguments passed on to [first_isolate()] when using [filter_first_isolate()], or arguments passed on to [key_antibiotics()] when using [filter_first_weighted_isolate()]
#' @details
#' These functions are context-aware when used inside `dplyr` verbs, such as `filter()`, `mutate()` and `summarise()`. This means that then the `x` argument can be left blank, see *Examples*.
#' These functions are context-aware. This means that then the `x` argument can be left blank, see *Examples*.
#'
#' The [first_isolate()] function is a wrapper around the [is_new_episode()] function, but more efficient for data sets containing microorganism codes or names.
#'
@ -96,7 +96,7 @@
@@ -96,7 +96,7 @@
#' **M39 Analysis and Presentation of Cumulative Antimicrobial Susceptibility Test Data, 4th Edition**, 2014, *Clinical and Laboratory Standards Institute (CLSI)*. <https://clsi.org/standards/products/microbiology/documents/m39/>.
#' @inheritSection AMR Read more on Our Website!
#' @examples
#' # `example_isolates` is a dataset available in the AMR package.
#' # `example_isolates` is a dataset available in the AMR package.
#' These function can be used to determine first isolates (see [first_isolate()]). Using key antibiotics to determine first isolates is more reliable than without key antibiotics. These selected isolates can then be called first 'weighted' isolates.
#' @inheritSection lifecycle Stable Lifecycle
#' @param x a [data.frame] with antibiotics columns, like `AMX` or `amox`. Can be left blank when used inside `dplyr` verbs, such as `filter()`, `mutate()` and `summarise()`.
#' @param x a [data.frame] with antibiotics columns, like `AMX` or `amox`. Can be left blank to determine automatically
#' @param y,z character vectors to compare
#' @inheritParams first_isolate
#' @param universal_1,universal_2,universal_3,universal_4,universal_5,universal_6 column names of **broad-spectrum** antibiotics, case-insensitive. See details for which antibiotics will be used at default (which are guessed with [guess_ab_col()]).
@ -36,7 +36,7 @@
@@ -36,7 +36,7 @@
#' @param warnings give a warning about missing antibiotic columns (they will be ignored)
#' @param ... other arguments passed on to functions
#' @details
#' The [key_antibiotics()] function is context-aware when used inside `dplyr` verbs, such as `filter()`, `mutate()` and `summarise()`. This means that then the `x` argument can be left blank, see *Examples*.
#' The [key_antibiotics()] function is context-aware. This means that then the `x` argument can be left blank, see *Examples*.
#'
#' The function [key_antibiotics()] returns a character vector with 12 antibiotic results for every isolate. These isolates can then be compared using [key_antibiotics_equal()], to check if two isolates have generally the same antibiogram. Missing and invalid values are replaced with a dot (`"."`) by [key_antibiotics()] and ignored by [key_antibiotics_equal()].
#'
@ -77,7 +77,7 @@
@@ -77,7 +77,7 @@
#' @seealso [first_isolate()]
#' @inheritSection AMR Read more on Our Website!
#' @examples
#' # `example_isolates` is a dataset available in the AMR package.
#' # `example_isolates` is a dataset available in the AMR package.
#' # See ?example_isolates.
#'
#' # output of the `key_antibiotics()` function could be like this:
#' @param verbose a logical to turn Verbose mode on and off (default is off). In Verbose mode, the function does not return the MDRO results, but instead returns a data set in logbook form with extensive info about which isolates would be MDRO-positive, or why they are not.
#' @inheritSection eucast_rules Antibiotics
#' @details
#' These functions are context-aware when used inside `dplyr` verbs, such as `filter()`, `mutate()` and `summarise()`. This means that then the `x` argument can be left blank, see *Examples*.
#' These functions are context-aware. This means that then the `x` argument can be left blank, see *Examples*.
#'
#' For the `pct_required_classes` argument, values above 1 will be divided by 100. This is to support both fractions (`0.75` or `3/4`) and percentages (`75`).
#'
@ -108,7 +108,7 @@
@@ -108,7 +108,7 @@
#' #> 43 891 1066
#' ```
#'
#' The rules set (the `custom` object in this case) could be exported to a shared file location using [saveRDS()] if you collaborate with multiple users. The custom rules set could then be imported using [readRDS()],
#' The rules set (the `custom` object in this case) could be exported to a shared file location using [saveRDS()] if you collaborate with multiple users. The custom rules set could then be imported using [readRDS()].
#' @inheritSection as.rsi Interpretation of R and S/I
#' @return
#' - CMI 2012 paper - function [mdr_cmi2012()] or [mdro()]:\cr
message_(word_wrap("- Try to use as many valid taxonomic names as possible for your input.",
extra_indent=2),
as_note=FALSE)
message_(word_wrap("- Save the output and use it as input for future calculations, e.g. create a new variable to your data using `as.mo()`. All functions in this package that rely on microorganism codes will automatically use that new column where possible. All `mo_*()` functions also do not require you to set their `x` argument as long as you have the dplyr package installed and you have a column of class <mo>.",
message_(word_wrap("- Save the output and use it as input for future calculations, e.g. create a new variable to your data using `as.mo()`. All functions in this package that rely on microorganism codes will automatically use that new column where possible. All `mo_*()` functions also do not require you to set their `x` argument as long as you have a column of class <mo>.",
extra_indent=2),
as_note=FALSE)
message_(word_wrap("- Use `set_mo_source()` to continually transform your organisation codes to microorganisms codes used by this package, see `?mo_source`.",
#' @param x vector of values (for class [`mic`]: an MIC value in mg/L, for class [`disk`]: a disk diffusion radius in millimetres)
#' @param mo any (vector of) text that can be coerced to a valid microorganism code with [as.mo()], will be determined automatically if the `dplyr` package is installed
#' @param 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
#' @param ab any (vector of) text that can be coerced to a valid antimicrobial code with [as.ab()]
#' @param uti (Urinary Tract Infection) A vector with [logical]s (`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 [logical]s 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*.
<spanclass="version label label-default"data-toggle="tooltip"data-placement="bottom"title="Latest development version">1.5.0</span>
<spanclass="version label label-default"data-toggle="tooltip"data-placement="bottom"title="Latest development version">1.5.0.9010</span>
</span>
</div>
@ -201,15 +201,15 @@
@@ -201,15 +201,15 @@
<p>With the function <code><ahref="../reference/mdro.html">mdro()</a></code>, you can determine which micro-organisms are multi-drug resistant organisms (MDRO).</p>
<divid="type-of-input"class="section level4">
<h4class="hasAnchor">
<ahref="#type-of-input"class="anchor"></a>Type of input</h4>
<divid="type-of-input"class="section level3">
<h3class="hasAnchor">
<ahref="#type-of-input"class="anchor"></a>Type of input</h3>
<p>The <code><ahref="../reference/mdro.html">mdro()</a></code> function takes a data set as input, such as a regular <code>data.frame</code>. It tries to automatically determine the right columns for info about your isolates, like the name of the species and all columns with results of antimicrobial agents. See the help page for more info about how to set the right settings for your data with the command <code><ahref="../reference/mdro.html">?mdro</a></code>.</p>
<p>For WHONET data (and most other data), all settings are automatically set correctly.</p>
<p>The function support multiple guidelines. You can select a guideline with the <code>guideline</code> parameter. Currently supported guidelines are (case-insensitive):</p>
<ul>
<li>
@ -238,16 +238,44 @@
@@ -238,16 +238,44 @@
</li>
</ul>
<p>Please suggest your own (country-specific) guidelines by letting us know: <ahref="https://github.com/msberends/AMR/issues/new"class="uri">https://github.com/msberends/AMR/issues/new</a>.</p>
<p>You can also use your own custom guideline. Custom guidelines can be set with the <code><ahref="../reference/mdro.html">custom_mdro_guideline()</a></code> function. This is of great importance if you have custom rules to determine MDROs in your hospital, e.g., rules that are dependent on ward, state of contact isolation or other variables in your data.</p>
<p>If you are familiar with <code><ahref="https://dplyr.tidyverse.org/reference/case_when.html">case_when()</a></code> of the <code>dplyr</code> package, you will recognise the input method to set your own rules. Rules must be set using what considers to be the ‘formula notation’:</p>
<codeclass="sourceCode R"><spanclass="va">custom</span><spanclass="op"><-</span><spanclass="fu"><ahref="../reference/mdro.html">custom_mdro_guideline</a></span><spanclass="op">(</span><spanclass="va">CIP</span><spanclass="op">==</span><spanclass="st">"R"</span><spanclass="op">&</span><spanclass="va">age</span><spanclass="op">></span><spanclass="fl">60</span><spanclass="op">~</span><spanclass="st">"Elderly Type A"</span>,
<spanclass="va">ERY</span><spanclass="op">==</span><spanclass="st">"R"</span><spanclass="op">&</span><spanclass="va">age</span><spanclass="op">></span><spanclass="fl">60</span><spanclass="op">~</span><spanclass="st">"Elderly Type B"</span><spanclass="op">)</span></code></pre></div>
<p>If a row/an isolate matches the first rule, the value after the first <code><ahref="https://rdrr.io/r/base/tilde.html">~</a></code> (in this case <em>‘Elderly Type A’</em>) will be set as MDRO value. Otherwise, the second rule will be tried and so on. The number of rules is unlimited.</p>
<p>You can print the rules set in the console for an overview. Colours will help reading it if your console supports colours.</p>
<spanclass="co"># Unmatched rows will return NA.</span>
<spanclass="co"># Results will be of class <factor>, with ordered levels: Negative < Elderly Type A < Elderly Type B</span></code></pre></div>
<p>The outcome of the function can be used for the <code>guideline</code> argument in the [mdro()] function:</p>
<p>The rules set (the <code>custom</code> object in this case) could be exported to a shared file location using <code><ahref="https://rdrr.io/r/base/readRDS.html">saveRDS()</a></code> if you collaborate with multiple users. The custom rules set could then be imported using <code><ahref="https://rdrr.io/r/base/readRDS.html">readRDS()</a></code>.</p>
<p>The <code><ahref="../reference/mdro.html">mdro()</a></code> function always returns an ordered <code>factor</code>. For example, the output of the default guideline by Magiorakos <em>et al.</em> returns a <code>factor</code> with levels ‘Negative’, ‘MDR’, ‘XDR’ or ‘PDR’ in that order.</p>
<p>The next example uses the <code>example_isolates</code> data set. This is a data set included with this package and contains 2,000 microbial isolates with their full antibiograms. It reflects reality and can be used to practice AMR analysis. If we test the MDR/XDR/PDR guideline on this data set, we get:</p>
<codeclass="sourceCode R"><spanclass="kw"><ahref="https://rdrr.io/r/base/library.html">library</a></span><spanclass="op">(</span><spanclass="va"><ahref="https://dplyr.tidyverse.org">dplyr</a></span><spanclass="op">)</span><spanclass="co"># to support pipes: %>%</span>
<spanclass="kw"><ahref="https://rdrr.io/r/base/library.html">library</a></span><spanclass="op">(</span><spanclass="va"><ahref="https://github.com/msberends/cleaner">cleaner</a></span><spanclass="op">)</span><spanclass="co"># to create frequency tables</span></code></pre></div>
<spanclass="fu"><ahref="https://rdrr.io/pkg/cleaner/man/freq.html">freq</a></span><spanclass="op">(</span><spanclass="op">)</span><spanclass="co"># show frequency table of the result</span>
GAT <spanclass="op">=</span><spanclass="fu"><ahref="../reference/random.html">random_rsi</a></span><spanclass="op">(</span><spanclass="fl">5000</span><spanclass="op">)</span>,
KAN <spanclass="op">=</span><spanclass="fu"><ahref="../reference/random.html">random_rsi</a></span><spanclass="op">(</span><spanclass="fl">5000</span><spanclass="op">)</span><spanclass="op">)</span></code></pre></div>
<p>Many R users just ask questions on websites like <ahref="https://stackoverflow.com">StackOverflow.com</a>, the largest online community for programmers. At the time of writing, <ahref="https://stackoverflow.com/questions/tagged/r?sort=votes">383,346 R-related questions</a> have already been asked on this platform (that covers questions and answers for any programming language). In my own experience, most questions are answered within a couple of minutes.</p>
<p>Many R users just ask questions on websites like <ahref="https://stackoverflow.com">StackOverflow.com</a>, the largest online community for programmers. At the time of writing, <ahref="https://stackoverflow.com/questions/tagged/r?sort=votes">384,445 R-related questions</a> have already been asked on this platform (that covers questions and answers for any programming language). In my own experience, most questions are answered within a couple of minutes.</p>
</li>
<li>
<p><strong>R understands any data type, including SPSS/SAS/Stata.</strong></p>
<ahref="#last-updated-22-january-2021"class="anchor"></a><small>Last updated: 22 January 2021</small>
<ahref="#last-updated-24-january-2021"class="anchor"></a><small>Last updated: 24 January 2021</small>
</h2>
<divid="new"class="section level3">
<h3class="hasAnchor">
@ -288,6 +288,7 @@
@@ -288,6 +288,7 @@
<li>Fix for verbose output of <code><ahref="../reference/mdro.html">mdro(..., verbose = TRUE)</a></code> for German guideline (3MGRN and 4MGRN) and Dutch guideline (BRMO, only <em>P. aeruginosa</em>)</li>
<li>
<code><ahref="../reference/as.rsi.html">is.rsi.eligible()</a></code> now returns <code>FALSE</code> immediately if the input does not contain any of the values “R”, “S” or “I”. This drastically improves speed, also for a lot of other functions that rely on automatic determination of antibiotic columns.</li>
<li>Functions <code><ahref="../reference/get_episode.html">get_episode()</a></code> and <code><ahref="../reference/get_episode.html">is_new_episode()</a></code> now support less than a day as value for argument <code>episode_days</code> (e.g., to include one patient/test per hour)</li>