(v0.7.1.9070) na.rm for age(), age_groups()

This commit is contained in:
dr. M.S. (Matthijs) Berends 2019-09-02 15:17:41 +02:00
parent c7be72f0ce
commit 06b6266366
19 changed files with 120 additions and 87 deletions

View File

@ -1,6 +1,6 @@
Package: AMR
Version: 0.7.1.9069
Date: 2019-09-01
Version: 0.7.1.9070
Date: 2019-09-02
Title: Antimicrobial Resistance Analysis
Authors@R: c(
person(role = c("aut", "cre"),

View File

@ -1,5 +1,5 @@
# AMR 0.7.1.9069
<small>Last updated: 01-Sep-2019</small>
# AMR 0.7.1.9070
<small>Last updated: 02-Sep-2019</small>
### Breaking
* Determination of first isolates now **excludes** all 'unknown' microorganisms at default, i.e. microbial code `"UNKNOWN"`. They can be included with the new parameter `include_unknown`:
@ -97,6 +97,7 @@
* Speed improvement for `guess_ab_col()` which is now 30 times faster for antibiotic abbreviations
* Improved `filter_ab_class()` to be more reliable and to support 5th generation cephalosporins
* Function `availability()` now uses `portion_R()` instead of `portion_IR()`, to comply with EUCAST insights
* Functions `age()` and `age_groups()` now have a `na.rm` parameter to remove empty values
#### Other
* Added Prof Dr Casper Albers as doctoral advisor and Dr Bart Meijer, Dr Dennis Souverein and Annick Lenglet as contributors

22
R/age.R
View File

@ -25,8 +25,9 @@
#' @param x date(s), will be coerced with \code{\link{as.POSIXlt}}
#' @param reference reference date(s) (defaults to today), will be coerced with \code{\link{as.POSIXlt}} and cannot be lower than \code{x}
#' @param exact a logical to indicate whether age calculation should be exact, i.e. with decimals. It divides the number of days of \href{https://en.wikipedia.org/wiki/Year-to-date}{year-to-date} (YTD) of \code{x} by the number of days in a year of \code{reference} (either 365 or 366).
#' @param na.rm a logical to indicate whether missing values should be removed
#' @return An integer (no decimals) if \code{exact = FALSE}, a double (with decimals) otherwise
#' @seealso \code{\link{age_groups}} to split age into age groups
#' @seealso To split ages into groups, use the \code{\link{age_groups}} function.
#' @importFrom dplyr if_else
#' @inheritSection AMR Read more on our website!
#' @export
@ -39,7 +40,7 @@
#' df$age_exact <- age(df$birth_date, exact = TRUE)
#'
#' df
age <- function(x, reference = Sys.Date(), exact = FALSE) {
age <- function(x, reference = Sys.Date(), exact = FALSE, na.rm = FALSE) {
if (length(x) != length(reference)) {
if (length(reference) == 1) {
reference <- rep(reference, length(x))
@ -79,6 +80,10 @@ age <- function(x, reference = Sys.Date(), exact = FALSE) {
if (any(ages > 120, na.rm = TRUE)) {
warning("Some ages are above 120.")
}
if (isTRUE(na.rm)) {
ages <- ages[!is.na(ages)]
}
ages
}
@ -88,6 +93,7 @@ age <- function(x, reference = Sys.Date(), exact = FALSE) {
#' Split ages into age groups defined by the \code{split} parameter. This allows for easier demographic (antimicrobial resistance) analysis.
#' @param x age, e.g. calculated with \code{\link{age}}
#' @param split_at values to split \code{x} at, defaults to age groups 0-11, 12-24, 25-54, 55-74 and 75+. See Details.
#' @param na.rm a logical to indicate whether missing values should be removed
#' @details To split ages, the input can be:
#' \itemize{
#' \item{A numeric vector. A vector of e.g. \code{c(10, 20)} will split on 0-9, 10-19 and 20+. A value of only \code{50} will split on 0-49 and 50+.
@ -102,7 +108,7 @@ age <- function(x, reference = Sys.Date(), exact = FALSE) {
#' }
#' @keywords age_group age
#' @return Ordered \code{\link{factor}}
#' @seealso \code{\link{age}} to determine ages based on one or more reference dates
#' @seealso To determine ages, based on one or more reference dates, use the \code{\link{age}} function.
#' @export
#' @inheritSection AMR Read more on our website!
#' @examples
@ -135,7 +141,7 @@ age <- function(x, reference = Sys.Date(), exact = FALSE) {
#' group_by(age_group = age_groups(age)) %>%
#' select(age_group, CIP) %>%
#' ggplot_rsi(x = "age_group")
age_groups <- function(x, split_at = c(12, 25, 55, 75)) {
age_groups <- function(x, split_at = c(12, 25, 55, 75), na.rm = FALSE) {
if (!is.numeric(x)) {
stop("`x` and must be numeric, not a ", paste0(class(x), collapse = "/"), ".")
}
@ -174,5 +180,11 @@ age_groups <- function(x, split_at = c(12, 25, 55, 75)) {
# last category
labs[length(labs)] <- paste0(split_at[length(split_at)], "+")
factor(labs[y], levels = labs, ordered = TRUE)
agegroups <- factor(labs[y], levels = labs, ordered = TRUE)
if (isTRUE(na.rm)) {
agegroups <- agegroups[!is.na(agegroups)]
}
agegroups
}

View File

@ -78,7 +78,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9069</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9070</span>
</span>
</div>

View File

@ -40,7 +40,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9069</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9070</span>
</span>
</div>
@ -185,7 +185,7 @@
<h1>Benchmarks</h1>
<h4 class="author">Matthijs S. Berends</h4>
<h4 class="date">01 September 2019</h4>
<h4 class="date">02 September 2019</h4>
<div class="hidden name"><code>benchmarks.Rmd</code></div>
@ -220,35 +220,35 @@
<a class="sourceLine" id="cb2-17" data-line-number="17"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/print">print</a></span>(S.aureus, <span class="dt">unit =</span> <span class="st">"ms"</span>, <span class="dt">signif =</span> <span class="dv">2</span>)</a>
<a class="sourceLine" id="cb2-18" data-line-number="18"><span class="co"># Unit: milliseconds</span></a>
<a class="sourceLine" id="cb2-19" data-line-number="19"><span class="co"># expr min lq mean median uq</span></a>
<a class="sourceLine" id="cb2-20" data-line-number="20"><span class="co"># as.mo("sau") 8.6 8.9 12.0 9.6 10.0</span></a>
<a class="sourceLine" id="cb2-21" data-line-number="21"><span class="co"># as.mo("stau") 33.0 33.0 39.0 34.0 50.0</span></a>
<a class="sourceLine" id="cb2-22" data-line-number="22"><span class="co"># as.mo("STAU") 33.0 33.0 40.0 35.0 49.0</span></a>
<a class="sourceLine" id="cb2-23" data-line-number="23"><span class="co"># as.mo("staaur") 9.0 9.2 11.0 9.6 9.8</span></a>
<a class="sourceLine" id="cb2-24" data-line-number="24"><span class="co"># as.mo("STAAUR") 8.8 9.2 11.0 9.6 9.9</span></a>
<a class="sourceLine" id="cb2-25" data-line-number="25"><span class="co"># as.mo("S. aureus") 23.0 25.0 29.0 26.0 27.0</span></a>
<a class="sourceLine" id="cb2-26" data-line-number="26"><span class="co"># as.mo("S aureus") 24.0 24.0 26.0 25.0 25.0</span></a>
<a class="sourceLine" id="cb2-27" data-line-number="27"><span class="co"># as.mo("Staphylococcus aureus") 4.0 4.2 4.4 4.2 4.6</span></a>
<a class="sourceLine" id="cb2-28" data-line-number="28"><span class="co"># as.mo("Staphylococcus aureus (MRSA)") 1500.0 1500.0 1600.0 1600.0 1700.0</span></a>
<a class="sourceLine" id="cb2-29" data-line-number="29"><span class="co"># as.mo("Sthafilokkockus aaureuz") 530.0 540.0 550.0 550.0 560.0</span></a>
<a class="sourceLine" id="cb2-30" data-line-number="30"><span class="co"># as.mo("MRSA") 8.2 8.7 12.0 9.1 9.5</span></a>
<a class="sourceLine" id="cb2-31" data-line-number="31"><span class="co"># as.mo("VISA") 19.0 20.0 35.0 21.0 37.0</span></a>
<a class="sourceLine" id="cb2-32" data-line-number="32"><span class="co"># as.mo("VRSA") 19.0 19.0 23.0 20.0 21.0</span></a>
<a class="sourceLine" id="cb2-33" data-line-number="33"><span class="co"># as.mo(22242419) 18.0 19.0 20.0 19.0 20.0</span></a>
<a class="sourceLine" id="cb2-20" data-line-number="20"><span class="co"># as.mo("sau") 8.4 8.8 11.0 9.1 9.9</span></a>
<a class="sourceLine" id="cb2-21" data-line-number="21"><span class="co"># as.mo("stau") 32.0 33.0 37.0 34.0 35.0</span></a>
<a class="sourceLine" id="cb2-22" data-line-number="22"><span class="co"># as.mo("STAU") 32.0 33.0 40.0 34.0 52.0</span></a>
<a class="sourceLine" id="cb2-23" data-line-number="23"><span class="co"># as.mo("staaur") 9.1 9.2 9.4 9.3 9.4</span></a>
<a class="sourceLine" id="cb2-24" data-line-number="24"><span class="co"># as.mo("STAAUR") 8.6 9.1 11.0 9.3 9.7</span></a>
<a class="sourceLine" id="cb2-25" data-line-number="25"><span class="co"># as.mo("S. aureus") 24.0 25.0 33.0 26.0 45.0</span></a>
<a class="sourceLine" id="cb2-26" data-line-number="26"><span class="co"># as.mo("S aureus") 24.0 25.0 27.0 25.0 26.0</span></a>
<a class="sourceLine" id="cb2-27" data-line-number="27"><span class="co"># as.mo("Staphylococcus aureus") 4.0 4.1 4.5 4.3 4.6</span></a>
<a class="sourceLine" id="cb2-28" data-line-number="28"><span class="co"># as.mo("Staphylococcus aureus (MRSA)") 1500.0 1600.0 1700.0 1700.0 1700.0</span></a>
<a class="sourceLine" id="cb2-29" data-line-number="29"><span class="co"># as.mo("Sthafilokkockus aaureuz") 550.0 550.0 560.0 560.0 580.0</span></a>
<a class="sourceLine" id="cb2-30" data-line-number="30"><span class="co"># as.mo("MRSA") 8.7 9.0 9.4 9.2 10.0</span></a>
<a class="sourceLine" id="cb2-31" data-line-number="31"><span class="co"># as.mo("VISA") 19.0 20.0 26.0 21.0 37.0</span></a>
<a class="sourceLine" id="cb2-32" data-line-number="32"><span class="co"># as.mo("VRSA") 19.0 19.0 20.0 20.0 20.0</span></a>
<a class="sourceLine" id="cb2-33" data-line-number="33"><span class="co"># as.mo(22242419) 18.0 18.0 24.0 20.0 21.0</span></a>
<a class="sourceLine" id="cb2-34" data-line-number="34"><span class="co"># max neval</span></a>
<a class="sourceLine" id="cb2-35" data-line-number="35"><span class="co"># 25.0 10</span></a>
<a class="sourceLine" id="cb2-36" data-line-number="36"><span class="co"># 52.0 10</span></a>
<a class="sourceLine" id="cb2-37" data-line-number="37"><span class="co"># 53.0 10</span></a>
<a class="sourceLine" id="cb2-38" data-line-number="38"><span class="co"># 29.0 10</span></a>
<a class="sourceLine" id="cb2-39" data-line-number="39"><span class="co"># 28.0 10</span></a>
<a class="sourceLine" id="cb2-40" data-line-number="40"><span class="co"># 50.0 10</span></a>
<a class="sourceLine" id="cb2-41" data-line-number="41"><span class="co"># 40.0 10</span></a>
<a class="sourceLine" id="cb2-42" data-line-number="42"><span class="co"># 5.2 10</span></a>
<a class="sourceLine" id="cb2-35" data-line-number="35"><span class="co"># 27.0 10</span></a>
<a class="sourceLine" id="cb2-36" data-line-number="36"><span class="co"># 61.0 10</span></a>
<a class="sourceLine" id="cb2-37" data-line-number="37"><span class="co"># 58.0 10</span></a>
<a class="sourceLine" id="cb2-38" data-line-number="38"><span class="co"># 10.0 10</span></a>
<a class="sourceLine" id="cb2-39" data-line-number="39"><span class="co"># 26.0 10</span></a>
<a class="sourceLine" id="cb2-40" data-line-number="40"><span class="co"># 48.0 10</span></a>
<a class="sourceLine" id="cb2-41" data-line-number="41"><span class="co"># 42.0 10</span></a>
<a class="sourceLine" id="cb2-42" data-line-number="42"><span class="co"># 5.9 10</span></a>
<a class="sourceLine" id="cb2-43" data-line-number="43"><span class="co"># 1700.0 10</span></a>
<a class="sourceLine" id="cb2-44" data-line-number="44"><span class="co"># 580.0 10</span></a>
<a class="sourceLine" id="cb2-45" data-line-number="45"><span class="co"># 36.0 10</span></a>
<a class="sourceLine" id="cb2-46" data-line-number="46"><span class="co"># 110.0 10</span></a>
<a class="sourceLine" id="cb2-47" data-line-number="47"><span class="co"># 35.0 10</span></a>
<a class="sourceLine" id="cb2-48" data-line-number="48"><span class="co"># 34.0 10</span></a></code></pre></div>
<a class="sourceLine" id="cb2-44" data-line-number="44"><span class="co"># 590.0 10</span></a>
<a class="sourceLine" id="cb2-45" data-line-number="45"><span class="co"># 10.0 10</span></a>
<a class="sourceLine" id="cb2-46" data-line-number="46"><span class="co"># 41.0 10</span></a>
<a class="sourceLine" id="cb2-47" data-line-number="47"><span class="co"># 21.0 10</span></a>
<a class="sourceLine" id="cb2-48" data-line-number="48"><span class="co"># 45.0 10</span></a></code></pre></div>
<p><img src="benchmarks_files/figure-html/unnamed-chunk-4-1.png" width="1125"></p>
<p>In the table above, all measurements are shown in milliseconds (thousands of seconds). A value of 5 milliseconds means it can determine 200 input values per second. It case of 100 milliseconds, this is only 10 input values per second. The second input is the only one that has to be looked up thoroughly. All the others are known codes (the first one is a WHONET code) or common laboratory codes, or common full organism names like the last one. Full organism names are always preferred.</p>
<p>To achieve this speed, the <code>as.mo</code> function also takes into account the prevalence of human pathogenic microorganisms. The downside is of course that less prevalent microorganisms will be determined less fast. See this example for the ID of <em>Thermus islandicus</em> (<code>B_THERMS_ISL</code>), a bug probably never found before in humans:</p>
@ -261,12 +261,12 @@
<a class="sourceLine" id="cb3-7" data-line-number="7"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/print">print</a></span>(T.islandicus, <span class="dt">unit =</span> <span class="st">"ms"</span>, <span class="dt">signif =</span> <span class="dv">2</span>)</a>
<a class="sourceLine" id="cb3-8" data-line-number="8"><span class="co"># Unit: milliseconds</span></a>
<a class="sourceLine" id="cb3-9" data-line-number="9"><span class="co"># expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb3-10" data-line-number="10"><span class="co"># as.mo("theisl") 300 300 310 320 320 330 10</span></a>
<a class="sourceLine" id="cb3-11" data-line-number="11"><span class="co"># as.mo("THEISL") 290 300 300 300 320 320 10</span></a>
<a class="sourceLine" id="cb3-12" data-line-number="12"><span class="co"># as.mo("T. islandicus") 130 140 150 140 150 160 10</span></a>
<a class="sourceLine" id="cb3-13" data-line-number="13"><span class="co"># as.mo("T. islandicus") 140 160 160 160 170 170 10</span></a>
<a class="sourceLine" id="cb3-14" data-line-number="14"><span class="co"># as.mo("Thermus islandicus") 49 52 57 55 56 72 10</span></a></code></pre></div>
<p>That takes 1.1 times as much time on average. A value of 100 milliseconds means it can only determine ~10 different input values per second. We can conclude that looking up arbitrary codes of less prevalent microorganisms is the worst way to go, in terms of calculation performance. Full names (like <em>Thermus islandicus</em>) are almost fast - these are the most probable input from most data sets.</p>
<a class="sourceLine" id="cb3-10" data-line-number="10"><span class="co"># as.mo("theisl") 300 300 320 320 330 340 10</span></a>
<a class="sourceLine" id="cb3-11" data-line-number="11"><span class="co"># as.mo("THEISL") 290 320 330 320 330 400 10</span></a>
<a class="sourceLine" id="cb3-12" data-line-number="12"><span class="co"># as.mo("T. islandicus") 150 150 160 170 170 170 10</span></a>
<a class="sourceLine" id="cb3-13" data-line-number="13"><span class="co"># as.mo("T. islandicus") 140 150 150 150 160 170 10</span></a>
<a class="sourceLine" id="cb3-14" data-line-number="14"><span class="co"># as.mo("Thermus islandicus") 53 55 65 59 76 80 10</span></a></code></pre></div>
<p>That takes 1.2 times as much time on average. A value of 100 milliseconds means it can only determine ~10 different input values per second. We can conclude that looking up arbitrary codes of less prevalent microorganisms is the worst way to go, in terms of calculation performance. Full names (like <em>Thermus islandicus</em>) are almost fast - these are the most probable input from most data sets.</p>
<p>In the figure below, we compare <em>Escherichia coli</em> (which is very common) with <em>Prevotella brevis</em> (which is moderately common) and with <em>Thermus islandicus</em> (which is uncommon):</p>
<p><img src="benchmarks_files/figure-html/unnamed-chunk-6-1.png" width="1125"><img src="benchmarks_files/figure-html/unnamed-chunk-6-2.png" width="1125"><img src="benchmarks_files/figure-html/unnamed-chunk-6-3.png" width="1125"></p>
<p>Uncommon microorganisms take a lot more time than common microorganisms. To relieve this pitfall and further improve performance, two important calculations take almost no time at all: <strong>repetitive results</strong> and <strong>already precalculated results</strong>.</p>
@ -300,8 +300,8 @@
<a class="sourceLine" id="cb4-24" data-line-number="24"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/print">print</a></span>(run_it, <span class="dt">unit =</span> <span class="st">"ms"</span>, <span class="dt">signif =</span> <span class="dv">3</span>)</a>
<a class="sourceLine" id="cb4-25" data-line-number="25"><span class="co"># Unit: milliseconds</span></a>
<a class="sourceLine" id="cb4-26" data-line-number="26"><span class="co"># expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb4-27" data-line-number="27"><span class="co"># mo_name(x) 582 614 622 620 624 677 10</span></a></code></pre></div>
<p>So transforming 500,000 values (!!) of 50 unique values only takes 0.62 seconds (619 ms). You only lose time on your unique input values.</p>
<a class="sourceLine" id="cb4-27" data-line-number="27"><span class="co"># mo_name(x) 625 659 686 689 698 746 10</span></a></code></pre></div>
<p>So transforming 500,000 values (!!) of 50 unique values only takes 0.69 seconds (688 ms). You only lose time on your unique input values.</p>
</div>
<div id="precalculated-results" class="section level3">
<h3 class="hasAnchor">
@ -313,11 +313,11 @@
<a class="sourceLine" id="cb5-4" data-line-number="4"> <span class="dt">times =</span> <span class="dv">10</span>)</a>
<a class="sourceLine" id="cb5-5" data-line-number="5"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/print">print</a></span>(run_it, <span class="dt">unit =</span> <span class="st">"ms"</span>, <span class="dt">signif =</span> <span class="dv">3</span>)</a>
<a class="sourceLine" id="cb5-6" data-line-number="6"><span class="co"># Unit: milliseconds</span></a>
<a class="sourceLine" id="cb5-7" data-line-number="7"><span class="co"># expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb5-8" data-line-number="8"><span class="co"># A 6.520 6.600 6.790 6.800 6.930 7.080 10</span></a>
<a class="sourceLine" id="cb5-9" data-line-number="9"><span class="co"># B 22.100 22.300 25.600 23.200 23.500 42.800 10</span></a>
<a class="sourceLine" id="cb5-10" data-line-number="10"><span class="co"># C 0.705 0.772 0.816 0.806 0.854 0.977 10</span></a></code></pre></div>
<p>So going from <code><a href="../reference/mo_property.html">mo_name("Staphylococcus aureus")</a></code> to <code>"Staphylococcus aureus"</code> takes 0.0008 seconds - it doesnt even start calculating <em>if the result would be the same as the expected resulting value</em>. That goes for all helper functions:</p>
<a class="sourceLine" id="cb5-7" data-line-number="7"><span class="co"># expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb5-8" data-line-number="8"><span class="co"># A 6.930 7.380 7.87 7.580 8.20 9.54 10</span></a>
<a class="sourceLine" id="cb5-9" data-line-number="9"><span class="co"># B 23.700 25.700 30.50 26.000 29.60 59.00 10</span></a>
<a class="sourceLine" id="cb5-10" data-line-number="10"><span class="co"># C 0.859 0.912 0.99 0.958 1.05 1.24 10</span></a></code></pre></div>
<p>So going from <code><a href="../reference/mo_property.html">mo_name("Staphylococcus aureus")</a></code> to <code>"Staphylococcus aureus"</code> takes 0.001 seconds - it doesnt even start calculating <em>if the result would be the same as the expected resulting value</em>. That goes for all helper functions:</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb6-1" data-line-number="1">run_it &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/microbenchmark/topics/microbenchmark">microbenchmark</a></span>(<span class="dt">A =</span> <span class="kw"><a href="../reference/mo_property.html">mo_species</a></span>(<span class="st">"aureus"</span>),</a>
<a class="sourceLine" id="cb6-2" data-line-number="2"> <span class="dt">B =</span> <span class="kw"><a href="../reference/mo_property.html">mo_genus</a></span>(<span class="st">"Staphylococcus"</span>),</a>
<a class="sourceLine" id="cb6-3" data-line-number="3"> <span class="dt">C =</span> <span class="kw"><a href="../reference/mo_property.html">mo_name</a></span>(<span class="st">"Staphylococcus aureus"</span>),</a>
@ -330,14 +330,14 @@
<a class="sourceLine" id="cb6-10" data-line-number="10"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/print">print</a></span>(run_it, <span class="dt">unit =</span> <span class="st">"ms"</span>, <span class="dt">signif =</span> <span class="dv">3</span>)</a>
<a class="sourceLine" id="cb6-11" data-line-number="11"><span class="co"># Unit: milliseconds</span></a>
<a class="sourceLine" id="cb6-12" data-line-number="12"><span class="co"># expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb6-13" data-line-number="13"><span class="co"># A 0.470 0.477 0.506 0.492 0.498 0.674 10</span></a>
<a class="sourceLine" id="cb6-14" data-line-number="14"><span class="co"># B 0.623 0.634 0.674 0.669 0.708 0.744 10</span></a>
<a class="sourceLine" id="cb6-15" data-line-number="15"><span class="co"># C 0.778 0.819 0.845 0.844 0.866 0.915 10</span></a>
<a class="sourceLine" id="cb6-16" data-line-number="16"><span class="co"># D 0.462 0.471 0.483 0.482 0.492 0.515 10</span></a>
<a class="sourceLine" id="cb6-17" data-line-number="17"><span class="co"># E 0.462 0.464 0.476 0.472 0.479 0.518 10</span></a>
<a class="sourceLine" id="cb6-18" data-line-number="18"><span class="co"># F 0.460 0.466 0.475 0.470 0.482 0.510 10</span></a>
<a class="sourceLine" id="cb6-19" data-line-number="19"><span class="co"># G 0.456 0.465 0.478 0.477 0.486 0.513 10</span></a>
<a class="sourceLine" id="cb6-20" data-line-number="20"><span class="co"># H 0.459 0.464 0.472 0.470 0.475 0.509 10</span></a></code></pre></div>
<a class="sourceLine" id="cb6-13" data-line-number="13"><span class="co"># A 0.478 0.490 0.512 0.509 0.530 0.579 10</span></a>
<a class="sourceLine" id="cb6-14" data-line-number="14"><span class="co"># B 0.644 0.670 0.711 0.673 0.740 0.930 10</span></a>
<a class="sourceLine" id="cb6-15" data-line-number="15"><span class="co"># C 0.697 0.815 0.887 0.840 0.992 1.150 10</span></a>
<a class="sourceLine" id="cb6-16" data-line-number="16"><span class="co"># D 0.456 0.486 0.511 0.503 0.521 0.643 10</span></a>
<a class="sourceLine" id="cb6-17" data-line-number="17"><span class="co"># E 0.465 0.477 0.534 0.497 0.556 0.804 10</span></a>
<a class="sourceLine" id="cb6-18" data-line-number="18"><span class="co"># F 0.459 0.472 0.490 0.477 0.509 0.556 10</span></a>
<a class="sourceLine" id="cb6-19" data-line-number="19"><span class="co"># G 0.466 0.488 0.526 0.522 0.544 0.637 10</span></a>
<a class="sourceLine" id="cb6-20" data-line-number="20"><span class="co"># H 0.455 0.455 0.476 0.465 0.485 0.535 10</span></a></code></pre></div>
<p>Of course, when running <code><a href="../reference/mo_property.html">mo_phylum("Firmicutes")</a></code> the function has zero knowledge about the actual microorganism, namely <em>S. aureus</em>. But since the result would be <code>"Firmicutes"</code> too, there is no point in calculating the result. And because this package knows all phyla of all known bacteria (according to the Catalogue of Life), it can just return the initial value immediately.</p>
</div>
<div id="results-in-other-languages" class="section level3">
@ -364,13 +364,13 @@
<a class="sourceLine" id="cb7-18" data-line-number="18"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/print">print</a></span>(run_it, <span class="dt">unit =</span> <span class="st">"ms"</span>, <span class="dt">signif =</span> <span class="dv">4</span>)</a>
<a class="sourceLine" id="cb7-19" data-line-number="19"><span class="co"># Unit: milliseconds</span></a>
<a class="sourceLine" id="cb7-20" data-line-number="20"><span class="co"># expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb7-21" data-line-number="21"><span class="co"># en 17.64 17.88 20.31 18.36 19.05 37.62 10</span></a>
<a class="sourceLine" id="cb7-22" data-line-number="22"><span class="co"># de 19.15 19.25 21.73 19.75 20.40 37.72 10</span></a>
<a class="sourceLine" id="cb7-23" data-line-number="23"><span class="co"># nl 24.34 24.48 36.33 24.88 26.21 121.60 10</span></a>
<a class="sourceLine" id="cb7-24" data-line-number="24"><span class="co"># es 18.95 19.09 19.29 19.28 19.53 19.61 10</span></a>
<a class="sourceLine" id="cb7-25" data-line-number="25"><span class="co"># it 19.02 19.10 22.80 19.24 20.42 36.65 10</span></a>
<a class="sourceLine" id="cb7-26" data-line-number="26"><span class="co"># fr 19.01 19.04 19.21 19.15 19.20 19.94 10</span></a>
<a class="sourceLine" id="cb7-27" data-line-number="27"><span class="co"># pt 18.94 19.08 22.28 19.55 20.36 38.81 10</span></a></code></pre></div>
<a class="sourceLine" id="cb7-21" data-line-number="21"><span class="co"># en 19.02 19.15 20.50 19.34 21.18 27.84 10</span></a>
<a class="sourceLine" id="cb7-22" data-line-number="22"><span class="co"># de 19.56 20.25 28.34 22.84 39.77 50.78 10</span></a>
<a class="sourceLine" id="cb7-23" data-line-number="23"><span class="co"># nl 26.12 26.25 27.73 27.17 28.60 31.65 10</span></a>
<a class="sourceLine" id="cb7-24" data-line-number="24"><span class="co"># es 20.02 20.58 22.36 22.26 23.95 25.71 10</span></a>
<a class="sourceLine" id="cb7-25" data-line-number="25"><span class="co"># it 20.30 20.47 23.21 21.23 24.56 34.71 10</span></a>
<a class="sourceLine" id="cb7-26" data-line-number="26"><span class="co"># fr 20.14 20.56 31.97 21.47 23.47 125.00 10</span></a>
<a class="sourceLine" id="cb7-27" data-line-number="27"><span class="co"># pt 19.83 20.24 22.74 20.46 22.65 38.93 10</span></a></code></pre></div>
<p>Currently supported are German, Dutch, Spanish, Italian, French and Portuguese.</p>
</div>
</div>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 220 KiB

After

Width:  |  Height:  |  Size: 219 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 104 KiB

After

Width:  |  Height:  |  Size: 103 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 108 KiB

After

Width:  |  Height:  |  Size: 108 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 106 KiB

After

Width:  |  Height:  |  Size: 106 KiB

View File

@ -78,7 +78,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9069</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9070</span>
</span>
</div>

View File

@ -78,7 +78,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9069</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9070</span>
</span>
</div>

View File

@ -42,7 +42,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9069</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9070</span>
</span>
</div>

View File

@ -78,7 +78,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9069</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9070</span>
</span>
</div>
@ -225,11 +225,11 @@
</div>
<div id="amr-0-7-1-9069" class="section level1">
<div id="amr-0-7-1-9070" class="section level1">
<h1 class="page-header">
<a href="#amr-0-7-1-9069" class="anchor"></a>AMR 0.7.1.9069<small> Unreleased </small>
<a href="#amr-0-7-1-9070" class="anchor"></a>AMR 0.7.1.9070<small> Unreleased </small>
</h1>
<p><small>Last updated: 01-Sep-2019</small></p>
<p><small>Last updated: 02-Sep-2019</small></p>
<div id="breaking" class="section level3">
<h3 class="hasAnchor">
<a href="#breaking" class="anchor"></a>Breaking</h3>
@ -340,6 +340,7 @@ Since this is a major change, usage of the old <code>also_single_tested</code> w
<li>Speed improvement for <code><a href="../reference/guess_ab_col.html">guess_ab_col()</a></code> which is now 30 times faster for antibiotic abbreviations</li>
<li>Improved <code><a href="../reference/filter_ab_class.html">filter_ab_class()</a></code> to be more reliable and to support 5th generation cephalosporins</li>
<li>Function <code><a href="../reference/availability.html">availability()</a></code> now uses <code><a href="../reference/portion.html">portion_R()</a></code> instead of <code><a href="../reference/portion.html">portion_IR()</a></code>, to comply with EUCAST insights</li>
<li>Functions <code><a href="../reference/age.html">age()</a></code> and <code><a href="../reference/age_groups.html">age_groups()</a></code> now have a <code>na.rm</code> parameter to remove empty values</li>
</ul>
<div id="other" class="section level4">
<h4 class="hasAnchor">
@ -1259,7 +1260,7 @@ Using <code><a href="../reference/as.mo.html">as.mo(..., allow_uncertain = 3)</a
<div id="tocnav">
<h2>Contents</h2>
<ul class="nav nav-pills nav-stacked">
<li><a href="#amr-0-7-1-9069">0.7.1.9069</a></li>
<li><a href="#amr-0-7-1-9070">0.7.1.9070</a></li>
<li><a href="#amr-0-7-1">0.7.1</a></li>
<li><a href="#amr-0-7-0">0.7.0</a></li>
<li><a href="#amr-0-6-1">0.6.1</a></li>

View File

@ -80,7 +80,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9055</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9070</span>
</span>
</div>
@ -234,7 +234,7 @@
</div>
<pre class="usage"><span class='fu'>age</span>(<span class='no'>x</span>, <span class='kw'>reference</span> <span class='kw'>=</span> <span class='fu'><a href='https://www.rdocumentation.org/packages/base/topics/Sys.time'>Sys.Date</a></span>(), <span class='kw'>exact</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>)</pre>
<pre class="usage"><span class='fu'>age</span>(<span class='no'>x</span>, <span class='kw'>reference</span> <span class='kw'>=</span> <span class='fu'><a href='https://www.rdocumentation.org/packages/base/topics/Sys.time'>Sys.Date</a></span>(), <span class='kw'>exact</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>, <span class='kw'>na.rm</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>)</pre>
<h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a>Arguments</h2>
<table class="ref-arguments">
@ -251,6 +251,10 @@
<th>exact</th>
<td><p>a logical to indicate whether age calculation should be exact, i.e. with decimals. It divides the number of days of <a href='https://en.wikipedia.org/wiki/Year-to-date'>year-to-date</a> (YTD) of <code>x</code> by the number of days in a year of <code>reference</code> (either 365 or 366).</p></td>
</tr>
<tr>
<th>na.rm</th>
<td><p>a logical to indicate whether missing values should be removed</p></td>
</tr>
</table>
<h2 class="hasAnchor" id="value"><a class="anchor" href="#value"></a>Value</h2>
@ -264,7 +268,7 @@
<h2 class="hasAnchor" id="see-also"><a class="anchor" href="#see-also"></a>See also</h2>
<div class='dont-index'><p><code><a href='age_groups.html'>age_groups</a></code> to split age into age groups</p></div>
<div class='dont-index'><p>To split ages into groups, use the <code><a href='age_groups.html'>age_groups</a></code> function.</p></div>
<h2 class="hasAnchor" id="examples"><a class="anchor" href="#examples"></a>Examples</h2>
@ -298,7 +302,7 @@
<footer>
<div class="copyright">
<p>Developed by <a href='https://www.rug.nl/staff/m.s.berends/'>Matthijs S. Berends</a>, <a href='https://www.rug.nl/staff/c.f.luz/'>Christian F. Luz</a>, <a href='https://www.rug.nl/staff/a.w.friedrich/'>Alex W. Friedrich</a>, <a href='https://www.rug.nl/staff/b.sinha/'>Bhanu N. M. Sinha</a>, <a href='https://www.rug.nl/staff/c.glasner/'>Corinna Glasner</a>.</p>
<p>Developed by <a href='https://www.rug.nl/staff/m.s.berends/'>Matthijs S. Berends</a>, <a href='https://www.rug.nl/staff/c.f.luz/'>Christian F. Luz</a>, <a href='https://www.rug.nl/staff/a.w.friedrich/'>Alex W. Friedrich</a>, <a href='https://www.rug.nl/staff/b.sinha/'>Bhanu N. M. Sinha</a>, <a href='https://www.rug.nl/staff/c.j.albers/'>Casper J. Albers</a>, <a href='https://www.rug.nl/staff/c.glasner/'>Corinna Glasner</a>.</p>
</div>
<div class="pkgdown">

View File

@ -80,7 +80,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9067</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9070</span>
</span>
</div>
@ -234,7 +234,7 @@
</div>
<pre class="usage"><span class='fu'>age_groups</span>(<span class='no'>x</span>, <span class='kw'>split_at</span> <span class='kw'>=</span> <span class='fu'><a href='https://www.rdocumentation.org/packages/base/topics/c'>c</a></span>(<span class='fl'>12</span>, <span class='fl'>25</span>, <span class='fl'>55</span>, <span class='fl'>75</span>))</pre>
<pre class="usage"><span class='fu'>age_groups</span>(<span class='no'>x</span>, <span class='kw'>split_at</span> <span class='kw'>=</span> <span class='fu'><a href='https://www.rdocumentation.org/packages/base/topics/c'>c</a></span>(<span class='fl'>12</span>, <span class='fl'>25</span>, <span class='fl'>55</span>, <span class='fl'>75</span>), <span class='kw'>na.rm</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>)</pre>
<h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a>Arguments</h2>
<table class="ref-arguments">
@ -247,6 +247,10 @@
<th>split_at</th>
<td><p>values to split <code>x</code> at, defaults to age groups 0-11, 12-24, 25-54, 55-74 and 75+. See Details.</p></td>
</tr>
<tr>
<th>na.rm</th>
<td><p>a logical to indicate whether missing values should be removed</p></td>
</tr>
</table>
<h2 class="hasAnchor" id="value"><a class="anchor" href="#value"></a>Value</h2>
@ -273,7 +277,7 @@
<h2 class="hasAnchor" id="see-also"><a class="anchor" href="#see-also"></a>See also</h2>
<div class='dont-index'><p><code><a href='age.html'>age</a></code> to determine ages based on one or more reference dates</p></div>
<div class='dont-index'><p>To determine ages, based on one or more reference dates, use the <code><a href='age.html'>age</a></code> function.</p></div>
<h2 class="hasAnchor" id="examples"><a class="anchor" href="#examples"></a>Examples</h2>

View File

@ -78,7 +78,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9069</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9070</span>
</span>
</div>

View File

@ -4,7 +4,7 @@
\alias{age}
\title{Age in years of individuals}
\usage{
age(x, reference = Sys.Date(), exact = FALSE)
age(x, reference = Sys.Date(), exact = FALSE, na.rm = FALSE)
}
\arguments{
\item{x}{date(s), will be coerced with \code{\link{as.POSIXlt}}}
@ -12,6 +12,8 @@ age(x, reference = Sys.Date(), exact = FALSE)
\item{reference}{reference date(s) (defaults to today), will be coerced with \code{\link{as.POSIXlt}} and cannot be lower than \code{x}}
\item{exact}{a logical to indicate whether age calculation should be exact, i.e. with decimals. It divides the number of days of \href{https://en.wikipedia.org/wiki/Year-to-date}{year-to-date} (YTD) of \code{x} by the number of days in a year of \code{reference} (either 365 or 366).}
\item{na.rm}{a logical to indicate whether missing values should be removed}
}
\value{
An integer (no decimals) if \code{exact = FALSE}, a double (with decimals) otherwise
@ -35,5 +37,5 @@ df$age_exact <- age(df$birth_date, exact = TRUE)
df
}
\seealso{
\code{\link{age_groups}} to split age into age groups
To split ages into groups, use the \code{\link{age_groups}} function.
}

View File

@ -4,12 +4,14 @@
\alias{age_groups}
\title{Split ages into age groups}
\usage{
age_groups(x, split_at = c(12, 25, 55, 75))
age_groups(x, split_at = c(12, 25, 55, 75), na.rm = FALSE)
}
\arguments{
\item{x}{age, e.g. calculated with \code{\link{age}}}
\item{split_at}{values to split \code{x} at, defaults to age groups 0-11, 12-24, 25-54, 55-74 and 75+. See Details.}
\item{na.rm}{a logical to indicate whether missing values should be removed}
}
\value{
Ordered \code{\link{factor}}
@ -68,7 +70,7 @@ example_isolates \%>\%
ggplot_rsi(x = "age_group")
}
\seealso{
\code{\link{age}} to determine ages based on one or more reference dates
To determine ages, based on one or more reference dates, use the \code{\link{age}} function.
}
\keyword{age}
\keyword{age_group}

View File

@ -40,6 +40,10 @@ test_that("age works", {
expect_warning(age(x = c("1800-01-01", "1805-01-01", "1810-01-01"),
reference = "2019-01-01"))
expect_equal(length(age(x = c("2019-01-01", NA), na.rm = TRUE)),
1)
})
test_that("age_groups works", {
@ -60,5 +64,8 @@ test_that("age_groups works", {
expect_identical(class(age_groups(ages, "fives")),
c("ordered", "factor"))
expect_equal(length(age_groups(c(10, 20, 30, NA), na.rm = TRUE)),
3)
})