<metaproperty="og:description"content="Determine first (weighted) isolates of all microorganisms of every patient per episode and (if needed) per specimen type. To determine patient episodes not necessarily based on microorganisms, use is_new_episode() that also supports grouping with the dplyr package."/>
<p>Determine first (weighted) isolates of all microorganisms of every patient per episode and (if needed) per specimen type. To determine patient episodes not necessarily based on microorganisms, use <code><ahref='get_episode.html'>is_new_episode()</a></code> that also supports grouping with the <code>dplyr</code> package.</p>
info <spanclass='op'>=</span><spanclass='fu'><ahref='https://rdrr.io/r/base/interactive.html'>interactive</a></span><spanclass='op'>(</span><spanclass='op'>)</span>,
<td><p>a <ahref='https://rdrr.io/r/base/data.frame.html'>data.frame</a> containing isolates. Can be left blank when used inside <code>dplyr</code> verbs, such as <code><ahref='https://dplyr.tidyverse.org/reference/filter.html'>filter()</a></code>, <code><ahref='https://dplyr.tidyverse.org/reference/mutate.html'>mutate()</a></code> and <code><ahref='https://dplyr.tidyverse.org/reference/summarise.html'>summarise()</a></code>.</p></td>
<td><p>column name of the IDs of the microorganisms (see <code><ahref='as.mo.html'>as.mo()</a></code>), defaults to the first column of class <code><ahref='as.mo.html'>mo</a></code>. Values will be coerced using <code><ahref='as.mo.html'>as.mo()</a></code>.</p></td>
<td><p>column name of the test codes. Use <code>col_testcode = NULL</code> to <strong>not</strong> exclude certain test codes (such as test codes for screening). In that case <code>testcodes_exclude</code> will be ignored.</p></td>
<td><p>column name of the key antibiotics to determine first <em>weighted</em> isolates, see <code><ahref='key_antibiotics.html'>key_antibiotics()</a></code>. Defaults to the first column that starts with 'key' followed by 'ab' or 'antibiotics' (case insensitive). Use <code>col_keyantibiotics = FALSE</code> to prevent this.</p></td>
<td><p>episode in days after which a genus/species combination will be determined as 'first isolate' again. The default of 365 days is based on the guideline by CLSI, see Source.</p></td>
<td><p>type to determine weighed isolates; can be <code>"keyantibiotics"</code> or <code>"points"</code>, see Details</p></td>
</tr>
<tr>
<th>ignore_I</th>
<td><p>logical to determine whether antibiotic interpretations with <code>"I"</code> will be ignored when <code>type = "keyantibiotics"</code>, see Details</p></td>
</tr>
<tr>
<th>points_threshold</th>
<td><p>points until the comparison of key antibiotics will lead to inclusion of an isolate when <code>type = "points"</code>, see Details</p></td>
<td><p>logical to determine whether 'unknown' microorganisms should be included too, i.e. microbial code <code>"UNKNOWN"</code>, which defaults to <code>FALSE</code>. For WHONET users, this means that all records with organism code <code>"con"</code> (<em>contamination</em>) will be excluded at default. Isolates with a microbial ID of <code>NA</code> will always be excluded as first isolate.</p></td>
<td><p>arguments passed on to <code>first_isolate()</code> when using <code>filter_first_isolate()</code>, or arguments passed on to <code><ahref='key_antibiotics.html'>key_antibiotics()</a></code> when using <code>filter_first_weighted_isolate()</code></p></td>
<p><strong>M39 Analysis and Presentation of Cumulative Antimicrobial Susceptibility Test Data, 4th Edition</strong>, 2014, <em>Clinical and Laboratory Standards Institute (CLSI)</em>. <ahref='https://clsi.org/standards/products/microbiology/documents/m39/'>https://clsi.org/standards/products/microbiology/documents/m39/</a>.</p>
<p>These functions are context-aware when used inside <code>dplyr</code> verbs, such as <code><ahref='https://dplyr.tidyverse.org/reference/filter.html'>filter()</a></code>, <code><ahref='https://dplyr.tidyverse.org/reference/mutate.html'>mutate()</a></code> and <code><ahref='https://dplyr.tidyverse.org/reference/summarise.html'>summarise()</a></code>. This means that then the <code>x</code> argument can be left blank, please see <em>Examples</em>.</p>
<p>The <code>first_isolate()</code> function is a wrapper around the <code><ahref='get_episode.html'>is_new_episode()</a></code> function, but more efficient for data sets containing microorganism codes or names.</p>
<p>All isolates with a microbial ID of <code>NA</code> will be excluded as first isolate.</p><h3class='hasAnchor'id='arguments'><aclass='anchor'href='#arguments'></a>Why this is so important</h3>
<p>To conduct an analysis of antimicrobial resistance, you should only include the first isolate of every patient per episode <ahref='https://pubmed.ncbi.nlm.nih.gov/17304462/'>(Hindler <em>et al.</em> 2007)</a>. If you would not do this, you could easily get an overestimate or underestimate of the resistance of an antibiotic. Imagine that a patient was admitted with an MRSA and that it was found in 5 different blood cultures the following week. The resistance percentage of oxacillin of all <em>S. aureus</em> isolates would be overestimated, because you included this MRSA more than once. It would be <ahref='https://en.wikipedia.org/wiki/Selection_bias'>selection bias</a>.</p>
<p>The functions <code>filter_first_isolate()</code> and <code>filter_first_weighted_isolate()</code> are helper functions to quickly filter on first isolates.</p>
<p>The function <code>filter_first_isolate()</code> is essentially equal to either:</p><pre><spanclass='va'>x</span><spanclass='op'>[</span><spanclass='fu'>first_isolate</span><spanclass='op'>(</span><spanclass='va'>x</span>, <spanclass='va'>...</span><spanclass='op'>)</span>, <spanclass='op'>]</span>
<p>There are two ways to determine whether isolates can be included as first <em>weighted</em> isolates which will give generally the same results:</p><ol>
<p>Any difference from S to R (or vice versa) will (re)select an isolate as a first weighted isolate. With <code>ignore_I = FALSE</code>, also differences from I to S|R (or vice versa) will lead to this. This is a reliable method and 30-35 times faster than method 2. Read more about this in the <code><ahref='key_antibiotics.html'>key_antibiotics()</a></code> function.</p></li>
<p>A difference from I to S|R (or vice versa) means 0.5 points, a difference from S to R (or vice versa) means 1 point. When the sum of points exceeds <code>points_threshold</code>, which default to <code>2</code>, an isolate will be (re)selected as a first weighted isolate.</p></li>
The <ahref='lifecycle.html'>lifecycle</a> of this function is <strong>stable</strong>. 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.</p>
<p>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.</p>
<p>On our website <ahref='https://msberends.github.io/AMR/'>https://msberends.github.io/AMR/</a> you can find <ahref='https://msberends.github.io/AMR/articles/AMR.html'>a comprehensive tutorial</a> about how to conduct AMR analysis, the <ahref='https://msberends.github.io/AMR/reference/'>complete documentation of all functions</a> and <ahref='https://msberends.github.io/AMR/articles/WHONET.html'>an example analysis using WHONET data</a>. As we would like to better understand the backgrounds and needs of our users, please <ahref='https://msberends.github.io/AMR/survey.html'>participate in our survey</a>!</p>
<spanclass='fu'>filter_first_weighted_isolate</span><spanclass='op'>(</span><spanclass='op'>)</span><spanclass='op'>%>%</span><spanclass='co'># the 1st isolate filter</span>
<p>Developed by <ahref='https://www.rug.nl/staff/m.s.berends/'>Matthijs S. Berends</a>, <ahref='https://www.rug.nl/staff/c.f.luz/'>Christian F. Luz</a>, <ahref='https://www.rug.nl/staff/a.w.friedrich/'>Alexander W. Friedrich</a>, <ahref='https://www.rug.nl/staff/b.sinha/'>Bhanu N. M. Sinha</a>, <ahref='https://www.rug.nl/staff/c.j.albers/'>Casper J. Albers</a>, <ahref='https://www.rug.nl/staff/c.glasner/'>Corinna Glasner</a>.</p>