<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Posts | Poisson Consulting</title>
    <link>/post/</link>
      <atom:link href="/post/index.xml" rel="self" type="application/rss+xml" />
    <description>Posts</description>
    <generator>Hugo Blox Builder (https://hugoblox.com)</generator><language>en-us</language><copyright>© Poisson Consulting</copyright><lastBuildDate>Mon, 25 May 2026 00:00:00 +0000</lastBuildDate>
    <image>
      <url>/media/logo_hu_f47d9b87cbc5aa6e.png</url>
      <title>Posts</title>
      <link>/post/</link>
    </image>
    
    <item>
      <title>What are s-values?</title>
      <link>/post/2026/what-are-s-values/</link>
      <pubDate>Mon, 25 May 2026 00:00:00 +0000</pubDate>
      <guid>/post/2026/what-are-s-values/</guid>
      <description>&lt;p&gt;P-values are a common measure of statistical significance that are often misunderstood.&lt;/p&gt;
&lt;p&gt;One issue is that the scale of p-values can be difficult to interpret.
For example, small p-values such as 0.0001 and 0.00001 are easily confused, and many readers often convert p-values to fractions ($\frac1{100}, \frac1{1,000}, \frac1{10,000}$), rounding them in the process (e.g., $0.0103 \approx 0.01 = \frac1{100}$).&lt;/p&gt;
&lt;p&gt;S-values address the issue of interpretability by converting p-values into a more tangible representation of probability: the number of heads in a row on a fair coin.&lt;/p&gt;
&lt;p&gt;Figure 1 shows the relationship between s-values and p-values.
A p-value of 0.5 corresponds to an s-value of 1, since a probability of 0.5 corresponds to a single successful coin flip.
Similarly, the common significance cutoff of 0.05 is equivalent to flipping 4.32 heads in a row.&lt;/p&gt;
&lt;figure&gt;
  &lt;img src=&#34;/post/what-are-s-values/s-val-fig-1.png&#34; alt=&#34;The relationship between s-values and p-values.&#34; /&gt;
  &lt;figcaption&gt;Figure 1: The relationship between s-values and p-values.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;S-values are particularly convenient when comparing or evaluating p-values that are very small or correspond to difficult fractions.
See Table 1 below for some examples.&lt;/p&gt;
&lt;table&gt;
&lt;caption&gt;Table 1: Example conversions from p-values to their equivalent simplest fractions and (rounded) s-values.&lt;/caption&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th style=&#34;text-align: right;&#34;&gt;P-value&lt;/th&gt;
&lt;th style=&#34;text-align: right;&#34;&gt;Fraction&lt;/th&gt;
&lt;th style=&#34;text-align: right;&#34;&gt;S-value&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&#34;text-align: right;&#34;&gt;0.5000000&lt;/td&gt;&lt;td style=&#34;text-align: right;&#34;&gt;1 / 2&lt;/td&gt;&lt;td style=&#34;text-align: right;&#34;&gt;1.00&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&#34;text-align: right;&#34;&gt;0.2500000&lt;/td&gt;&lt;td style=&#34;text-align: right;&#34;&gt;1 / 4&lt;/td&gt;&lt;td style=&#34;text-align: right;&#34;&gt;2.00&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&#34;text-align: right;&#34;&gt;0.1000000&lt;/td&gt;&lt;td style=&#34;text-align: right;&#34;&gt;1 / 10&lt;/td&gt;&lt;td style=&#34;text-align: right;&#34;&gt;3.32&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&#34;text-align: right;&#34;&gt;0.0625000&lt;/td&gt;&lt;td style=&#34;text-align: right;&#34;&gt;1 / 16&lt;/td&gt;&lt;td style=&#34;text-align: right;&#34;&gt;4.00&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&#34;text-align: right;&#34;&gt;0.0500000&lt;/td&gt;&lt;td style=&#34;text-align: right;&#34;&gt;1 / 20&lt;/td&gt;&lt;td style=&#34;text-align: right;&#34;&gt;4.32&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&#34;text-align: right;&#34;&gt;0.0100000&lt;/td&gt;&lt;td style=&#34;text-align: right;&#34;&gt;1 / 100&lt;/td&gt;&lt;td style=&#34;text-align: right;&#34;&gt;6.64&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&#34;text-align: right;&#34;&gt;0.0058366&lt;/td&gt;&lt;td style=&#34;text-align: right;&#34;&gt;3 / 514&lt;/td&gt;&lt;td style=&#34;text-align: right;&#34;&gt;7.42&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&#34;text-align: right;&#34;&gt;0.0010000&lt;/td&gt;&lt;td style=&#34;text-align: right;&#34;&gt;1 / 1000&lt;/td&gt;&lt;td style=&#34;text-align: right;&#34;&gt;9.97&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&#34;text-align: right;&#34;&gt;0.0001000&lt;/td&gt;&lt;td style=&#34;text-align: right;&#34;&gt;1 / 10000&lt;/td&gt;&lt;td style=&#34;text-align: right;&#34;&gt;13.30&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&#34;text-align: right;&#34;&gt;0.0000010&lt;/td&gt;&lt;td style=&#34;text-align: right;&#34;&gt;1 / 1e+06&lt;/td&gt;&lt;td style=&#34;text-align: right;&#34;&gt;19.90&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
</description>
    </item>
    
    <item>
      <title>How many fish are in the river?</title>
      <link>/post/2026/how-many-fish/</link>
      <pubDate>Thu, 05 Feb 2026 00:00:00 +0000</pubDate>
      <guid>/post/2026/how-many-fish/</guid>
      <description>&lt;p&gt;On February 28th, 2025 &lt;a href=&#34;/author/joe-thorley&#34;&gt;Joe Thorley&lt;/a&gt;, presented on &lt;em&gt;“How many trout are in the river?” Rethinking the logic of riverine population abundance assessments&lt;/em&gt; at the &lt;a href=&#34;https://open.alberta.ca/publications/alberta-species-at-risk-report-178&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Alberta Native Trout Science Workshop &amp;amp; Gathering II&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The abstract was as follows&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Obtaining a reliable answer to the question of ‘how many trout are in the river?’ plays an important role in monitoring threats to fish populations.
Although approaches to answering this question are often formulated in terms of statistical procedures, we present the underlying logic and rethink some misconceptions.
If a method was 100% efficient at capturing fish and was applied to the entire river, the population abundance would simply be the total number of fish caught.
However, typically, the capture efficiency is less than 100% and can be highly variable which necessitates methods to estimate the efficiency.
Currently, depletion-removal methods estimate the number of fish based on the rate of decline of the catch under the often-erroneous assumption that the capture efficiency does not change between passes.
Mark-recapture makes the more reasonable assumption that marked and unmarked fish have the same probability of recapture.
As a method can rarely be applied to the entire river it is also necessary to estimate the number of fish at the unsampled sites.
Index sites with high fish densities do not allow the number of fish at the other sites to be estimated and may even be decoupled from changes in the population abundance.
At the other extreme totally random site selection introduces unnecessary uncertainty.
A stratified approach requires more thought but produces more reliable estimates.
Fish densities are often calculated in terms of the number of trout by wetted area but this assumes that doubling the stream width is equivalent to doubling the stream length and means that trout densities change with discharge.
Lineal fish densities, in contrast, facilitate comparisons within and among systems while also allowing the effect of stream width to be estimated.
We provide examples from the literature and via thought experiments of both logically valid and invalid estimates.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;The presentation is available &lt;a href=&#34;/post/2026-02-05-how-many-fish/how-many-fish.pdf&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Shiny Upload App User Guide</title>
      <link>/post/2023/shiny-upload-app-guide/</link>
      <pubDate>Thu, 27 Jul 2023 00:00:00 +0000</pubDate>
      <guid>/post/2023/shiny-upload-app-guide/</guid>
      <description>&lt;p&gt;We have created a document to guide users through the steps for
submitting their data to Poisson via the &lt;a href=&#34;/post/2021/shiny-upload-app/&#34;&gt;shiny upload app&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You can find the user guide at
&lt;a href=&#34;https://poissonconsulting.github.io/shiny-upload-app-user-guide/&#34;&gt;Shiny Upload
App User Guide&lt;/a&gt;.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Shiny Upload App</title>
      <link>/post/2021/shiny-upload-app/</link>
      <pubDate>Thu, 12 Aug 2021 00:00:00 +0000</pubDate>
      <guid>/post/2021/shiny-upload-app/</guid>
      <description>&lt;p&gt;We are pleased to announce that we can now efficiently deploy user-friendly web interfaces for clients to upload different types of data including punched excel workbooks, scanned field cards, photographs, logger downloads and GPS tracks.&lt;/p&gt;
&lt;p&gt;A demo app for Yakoun Lake is available at &lt;a href=&#34;https://poissonconsulting.shinyapps.io/shinyupload2demo/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;https://poissonconsulting.shinyapps.io/shinyupload2demo/&lt;/a&gt;.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt = &#34;A screenshot of the demo shiny upload app for Yakoun Lake, Haida Gwaii&#34; src = &#34;/post/2021-08-12-shiny-upload/screen-shot.png&#34; title = &#34;A screenshot of the Columbia Basin Hydrological Database shiny app&#34; width = &#34;100%&#34;&gt;
&lt;figcaption&gt;
Figure 1. A screenshot of the demo shiny upload app for Yakoun Lake on Haida Gwaii.
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id=&#34;creditation&#34;&gt;Creditation&lt;/h2&gt;
&lt;p&gt;The shiny app creation and deployment software is the result of several years of development and testing by &lt;a href=&#34;/ayla/&#34;&gt;Ayla Pearson&lt;/a&gt; and &lt;a href=&#34;https://www.linkedin.com/in/sebastian-dalgarno-739538131&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Seb Dalgarno&lt;/a&gt; in conjunction with various clients.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Hidden Page</title>
      <link>/post/2019/hidden-page/</link>
      <pubDate>Tue, 04 Jun 2019 00:00:00 +0000</pubDate>
      <guid>/post/2019/hidden-page/</guid>
      <description>&lt;p&gt;This page should be hidden.&lt;/p&gt;
&lt;p&gt;hideawaypage&lt;/p&gt;
&lt;p&gt;If you can view it please email &lt;a href=&#34;mailto:joe@poissonconsulting.ca&#34;&gt;joe@poissonconsulting.ca&lt;/a&gt;.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Species Sensitivity Distributions App</title>
      <link>/post/2018/ssdca-shiny/</link>
      <pubDate>Fri, 17 Aug 2018 00:00:00 +0000</pubDate>
      <guid>/post/2018/ssdca-shiny/</guid>
      <description>&lt;p&gt;The &lt;a href=&#34;https://bcgov-env.shinyapps.io/ssdtools/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Species Sensitivity Distributions shiny app&lt;/a&gt; is a webpage for
interactively fitting &lt;a href=&#34;https://edild.github.io/ssd/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;species sensitivity distributions&lt;/a&gt; to concentration data.
The user is able to select more than one distribution and plot the individual fits.&lt;/p&gt;
&lt;p&gt;The calculations are performed by the &lt;a href=&#34;https://github.com/bcgov/ssdtools&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;ssdtools&lt;/a&gt; R package, which also generates the plots and tables.
The shiny app also provides the R code that was used to perform an analysis so the user can replicate it using an R script.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt = &#34;A screenshot of the fits from the Species Sensitivity Distributions shiny app&#34; src = &#34;/post/ssdca-shiny/fits.png&#34; title = &#34;A screenshot of the fits from the Species Sensitivity Distributions shiny app&#34; width = &#34;100%&#34;&gt;
&lt;figcaption&gt;
Figure 1. A screenshot of the fits from the Species Sensitivity Distributions shiny app.
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;/br&gt;
&lt;p&gt;The app was developed for the &lt;a href=&#34;/orgs/moe&#34;&gt;Ministry of the Environment&lt;/a&gt;, British Columbia.&lt;/p&gt;
&lt;p&gt;The app can be viewed at &lt;a href=&#34;https://bcgov-env.shinyapps.io/ssdtools/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;https://bcgov-env.shinyapps.io/ssdtools/&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;citation&#34;&gt;Citation&lt;/h2&gt;
&lt;p&gt;To cite package &lt;code&gt;ssdtools&lt;/code&gt; in publications use:&lt;/p&gt;
&lt;p&gt;Thorley, J., and Schwarz, C. 2018. ssdtools: An R package to fit Species Sensitivity Distributions. JOSS 3(31): 1082. &lt;a href=&#34;doi:10.21105/joss.01082&#34;&gt;doi:10.21105/joss.01082&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To cite the web app use:&lt;/p&gt;
&lt;p&gt;Dalgarno, S. 2021. shinyssdtools: A web application for fitting Species Sensitivity Distributions (SSDs). JOSS 6(57): 2848. &lt;a href=&#34;doi:10.21105/joss.02848&#34;&gt;doi:10.21105/joss.02848&lt;/a&gt;.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Yield per Recruit App</title>
      <link>/post/2018/ypr-shiny/</link>
      <pubDate>Thu, 16 Aug 2018 00:00:00 +0000</pubDate>
      <guid>/post/2018/ypr-shiny/</guid>
      <description>&lt;p&gt;The &lt;a href=&#34;https://poissonconsulting.shinyapps.io/shinyypr/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Yield per Recruit shiny
app&lt;/a&gt; is a webpage for
interactively exploring the effect of various fish population parameters on the schedule, stock-recruitment relationship and yield.&lt;/p&gt;
&lt;p&gt;The calculations are performed by the &lt;a href=&#34;https://github.com/poissonconsulting/ypr&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;ypr&lt;/a&gt; R package, which also generates the plots and table.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt = &#34;A screenshot of the yield from the Yield per Recruit shiny app&#34; src = &#34;/post/ypr-shiny/yield.png&#34; title = &#34;A screenshot of the yield from the Yield per Recruit shiny app&#34; width = &#34;100%&#34;&gt;
&lt;figcaption&gt;
Figure 1. A screenshot of the yield from the Yield per Recruit shiny app.
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;/br&gt;
&lt;p&gt;The app can be viewed at &lt;a href=&#34;https://poissonconsulting.shinyapps.io/shinyypr/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;https://poissonconsulting.shinyapps.io/shinyypr/&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;creditation&#34;&gt;Creditation&lt;/h2&gt;
&lt;p&gt;The app was developed by &lt;a href=&#34;https://www.linkedin.com/in/sebastian-dalgarno-739538131&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Seb Dalgarno&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Development of the app was supported by the &lt;a href=&#34;https://www.poissonconsulting.ca/orgs/hctf.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Habitat Conservation Trust Foundation&lt;/a&gt;
and the &lt;a href=&#34;https://www.poissonconsulting.ca/orgs/mflnro.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Ministy of Forests, Lands and Natural Resource Operations&lt;/a&gt;.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Tidal Predictions App</title>
      <link>/post/2018/rtide/</link>
      <pubDate>Tue, 07 Aug 2018 00:00:00 +0000</pubDate>
      <guid>/post/2018/rtide/</guid>
      <description>&lt;p&gt;The &lt;a href=&#34;https://poissonconsulting.shinyapps.io/rtide/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Tide Predictions shiny
app&lt;/a&gt; is a webpage for
visualizing and downloading tide height data.&lt;/p&gt;
&lt;p&gt;The tide heights are calculated using the &lt;a href=&#34;https://github.com/poissonconsulting/rtide&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;rtide&lt;/a&gt; R package.&lt;/p&gt;
&lt;p&gt;Currently, predictions are available for 637 US stations.
Unfortunately, Canadian stations are not available under an open license.&lt;/p&gt;
&lt;p&gt;Stations can be selected by name or by clicking on a map.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt = &#34;A screenshot of the stations map from the Tide Predictions shiny app&#34; src = &#34;/post/rtide/stations.png&#34; title = &#34;A screenshot of the stations map from the Tide Predictions shiny app&#34; width = &#34;100%&#34;&gt;
&lt;figcaption&gt;
Figure 1. A screenshot of the stations map from the Tide Predictions shiny app.
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;/br&gt;
&lt;p&gt;When a station is selected, an window opens allowing the user to select the period, interval, and units (meters or feet).
The data can be viewed as an interactive plot or table (which can be downloaded as a csv file).&lt;/p&gt;
&lt;figure&gt;
&lt;img alt = &#34;A screenshot of the tide heights window from the Tide Predictions shiny app&#34; src = &#34;/post/rtide/heights.png&#34; title = &#34;A screenshot of the tide heights window from the Tide Predictions shiny app&#34; width = &#34;100%&#34;&gt;
&lt;figcaption&gt;
Figure 2. A screenshot of the tide heights window from the Tide Predictions shiny app.
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;/br&gt;
&lt;p&gt;The app can be viewed at &lt;a href=&#34;https://poissonconsulting.shinyapps.io/rtide/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;https://poissonconsulting.shinyapps.io/rtide/&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;creditation&#34;&gt;Creditation&lt;/h2&gt;
&lt;p&gt;The Tide Predictions shiny app was developed by &lt;a href=&#34;https://www.linkedin.com/in/sebastian-dalgarno-739538131&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Seb Dalgarno&lt;/a&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Kootenay Lake Fish Movement App</title>
      <link>/post/2018/klexdatr/</link>
      <pubDate>Sun, 05 Aug 2018 00:00:00 +0000</pubDate>
      <guid>/post/2018/klexdatr/</guid>
      <description>&lt;p&gt;The &lt;a href=&#34;https://poissonconsulting.shinyapps.io/klexdatr-movement/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Kootenay Lake Fish Movement shiny app&lt;/a&gt; is a webpage to view detections of acoustically tagged Bull Trout and Rainbow Trout in Kootenay Lake from 2008 to 2014.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt = &#34;A screenshot of the Kootenay Lake Fish Movement shiny app&#34; src = &#34;/post/klexdatr/detection.png&#34; title = &#34;A screenshot of the Kootenay Lake Fish Movement shiny
app&#34; width = &#34;100%&#34;&gt;
&lt;figcaption&gt;
Figure 1. A screenshot of the Kootenay Lake Fish Movement shiny app.
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;/br&gt;
&lt;p&gt;The app uses data from the &lt;a href=&#34;https://github.com/poissonconsulting/klexdatr&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;klexdatr&lt;/a&gt; R package.&lt;/p&gt;
&lt;p&gt;There are two approaches to visualizing the data:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Movement by Individual
&lt;ul&gt;
&lt;li&gt;Allows the user to view movements of individual fish over time by selecting a fish ID.&lt;/li&gt;
&lt;li&gt;Detections are aggregated daily for each fish ID; the receiver with the most detections (or in case of a tie, the receiver with the smallest coverage area) in a given day is chosen.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Movement by Group
&lt;ul&gt;
&lt;li&gt;Allows the user to select a group of fish by species and fork length range. For each day, the proportion of detections at each receiver are shown with variable-sized circles.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;An appropriate basemap may be selected from the Layer Control button in the top right of the map.
We recommend using the &amp;lsquo;Basemap&amp;rsquo; layer as it prioritizes visibility of data over geographic features.
However, the Satelite (default) and Terrain basemaps may be more useful for orienting oneself geographically.&lt;/p&gt;
&lt;p&gt;The app is viewable at
&lt;a href=&#34;https://poissonconsulting.shinyapps.io/klexdatr-movement/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;https://poissonconsulting.shinyapps.io/klexdatr-movement/&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;creditation&#34;&gt;Creditation&lt;/h2&gt;
&lt;p&gt;The shiny app was developed by &lt;a href=&#34;https://www.linkedin.com/in/sebastian-dalgarno-739538131&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Seb Dalgarno&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The original project was supported by the Habitat Conservation Trust Foundation, Ministry of Forests Lands and Natural Resource Operations, Fish and Wildlife Compensation Program of the Columbia Basin, Freshwater Fish Society of BC, Idaho Department of Fish and Game, the Bonneville Power Administration and the Kootenai Tribe of Idaho.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt = &#34;Sponsors&#39; logos&#34; src = &#34;/post/klexdatr/logos.png&#34; title = &#34;Sponsors&#39; logos&#34; width = &#34;100%&#34;&gt;
&lt;/figure&gt;
&lt;/br&gt;
</description>
    </item>
    
    <item>
      <title>Columbia Basin Hydrological Database</title>
      <link>/post/2018/columbia-basin-hydrological-database/</link>
      <pubDate>Tue, 15 May 2018 00:00:00 +0000</pubDate>
      <guid>/post/2018/columbia-basin-hydrological-database/</guid>
      <description>&lt;p&gt;The Columbia Basin Hydrological Database shiny app is a webpage that allows &lt;strong&gt;approved&lt;/strong&gt; users to request historical BC Hydro discharge, temperature, elevation and stage data for the Columbia Basin.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt = &#34;A screenshot of the Columbia Basin Hydrological Database shiny app&#34; src = &#34;/post/columbia-basin-hydrological-database/screen-shot.png&#34; title = &#34;A screenshot of the Columbia Basin Hydrological Database shiny app&#34; width = &#34;100%&#34;&gt;
&lt;figcaption&gt;
Figure 1. A screenshot of the Columbia Basin Hydrological Database shiny app.
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;/br&gt;
&lt;p&gt;It also allows users to request data that was provided by the Columbia Power Corporation, Ministry of the Environment, Water Survey of Canada, Golder and Mountain Water Research.&lt;/p&gt;
&lt;p&gt;Each time series of a particular measurement is referred to as a station.
The Database contains hourly information for over 50 stations from the 1960s onwards.
If a BC Hydro project requires data for a station that is not currently included in the database it may be possible to add it.&lt;/p&gt;
&lt;p&gt;In order to access the app you will need to be a BC Hydro employee or a consultant working on a BC Hydro project in the Columbia Basin.
To request an access username and password contact &lt;a href=&#34;/joe/&#34;&gt;Joe Thorley&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The secured app is located at &lt;a href=&#34;https://poissonconsulting.shinyapps.io/kootqlt-download/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;https://poissonconsulting.shinyapps.io/kootqlt-download/&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;creditation&#34;&gt;Creditation&lt;/h2&gt;
&lt;p&gt;The database was maintained by &lt;a href=&#34;/robyn/&#34;&gt;Robyn Irvine&lt;/a&gt; from 2006 to 2017.
The app is powered by the &lt;a href=&#34;https://github.com/poissonconsulting/tsdbr&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;tsdbr&lt;/a&gt; R package which was developed by &lt;a href=&#34;/joe/&#34;&gt;Joe Thorley&lt;/a&gt;.
The shiny app was developed by &lt;a href=&#34;https://www.linkedin.com/in/sebastian-dalgarno-739538131&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Seb Dalgarno&lt;/a&gt;.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Large Lake Exploitation Data</title>
      <link>/post/2017/large-lake-exploitation-data/</link>
      <pubDate>Mon, 10 Apr 2017 00:00:00 +0000</pubDate>
      <guid>/post/2017/large-lake-exploitation-data/</guid>
      <description>&lt;figure&gt;
&lt;img alt = &#34;A photograph of a Rainbow Trout recovering post-tagging&#34; src = &#34;/post/large-lake-exploitation-data/tag0531.jpg&#34; title = &#34;Tagged Rainbow Trout&#34; width = &#34;100%&#34;&gt;
&lt;figcaption&gt;
Figure 1. A Rainbow Trout recovers post-tagging by [Alistair Fraser &amp;copy;](http://kootenay-lake.ca).
&lt;/figcaption&gt;
&lt;h2 id=&#34;background&#34;&gt;Background&lt;/h2&gt;
&lt;p&gt;Large lake exploitation studies typically involve the capture and tagging of fish whose subsequest movements are detected using acoustic receivers.
The detections, in conjunction with angler reports of externally tagged fish, are used to estimate the proportion of individuals that are captured by anglers versus die of natural causes.&lt;/p&gt;
&lt;p&gt;While lots of information can be recorded, there is a limited amount of data that &lt;strong&gt;must&lt;/strong&gt; be recorded to allow exploitation to be estimated.&lt;/p&gt;
&lt;p&gt;The following tables list what we consider to be the key information.&lt;/p&gt;
&lt;h3 id=&#34;captures&#34;&gt;Captures&lt;/h3&gt;
&lt;p&gt;Table 1. Capture data.&lt;/p&gt;
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;Column&lt;/th&gt;
					&lt;th&gt;Description&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;DateTimeReleased&lt;/td&gt;
					&lt;td&gt;The date and time at which the individual was released (yyyy-mm-dd HH:MM:SS)&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;LongitudeReleased&lt;/td&gt;
					&lt;td&gt;The longitude at which the individual was released (dd.ddddd)&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;LatitudeReleased&lt;/td&gt;
					&lt;td&gt;The latitude at which the individual was released (dd.ddddd)&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;CaptureMethod&lt;/td&gt;
					&lt;td&gt;The capture method (typically rod or net or trap)&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;FishSpecies&lt;/td&gt;
					&lt;td&gt;The fish species&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;FishLength&lt;/td&gt;
					&lt;td&gt;The fish fork length (mm)&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;AcousticTagNumber&lt;/td&gt;
					&lt;td&gt;The unique acoustic tag number (leave blank if not applicable)&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;ExternalTagNumber1&lt;/td&gt;
					&lt;td&gt;The unique first external tag number (leave blank if not applicable)&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;ExternalTagNumber2&lt;/td&gt;
					&lt;td&gt;The unique second external tag number (leave blank if not applicable)&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;All fish should be released within 100 m of the point of capture.
Fish in poor condition should not be tagged.&lt;/p&gt;
&lt;h3 id=&#34;receivers&#34;&gt;Receivers&lt;/h3&gt;
&lt;p&gt;Table 2. Receiver data.&lt;/p&gt;
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;Column&lt;/th&gt;
					&lt;th&gt;Description&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;ReceiverNumber&lt;/td&gt;
					&lt;td&gt;The unique acoustic receiver number&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;DateTimeDeployed&lt;/td&gt;
					&lt;td&gt;The date and time at which the receiver was deployed (yyyy-mm-dd HH:MM:SS)&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;LongitudeDeployed&lt;/td&gt;
					&lt;td&gt;The longitude at which the receiver was deployed (dd.ddddd)&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;LatitudeDeployed&lt;/td&gt;
					&lt;td&gt;The latitude at which the receiver was deployed (dd.ddddd)&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;DateTimeRetrieved&lt;/td&gt;
					&lt;td&gt;The date and time at which the receiver was retrieved (yyyy-mm-dd HH:MM:SS)&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;LongitudeRetrieved&lt;/td&gt;
					&lt;td&gt;The longitude at which the receiver was retrieved (dd.ddddd)&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;LatitudeRetrieved&lt;/td&gt;
					&lt;td&gt;The latitude at which the receiver was retrieved (dd.ddddd)&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Only receivers which are successfully retrieved and downloaded should be recorded.
The raw data file from each receiver retrieval should be saved to file and provided as is.&lt;/p&gt;
&lt;h3 id=&#34;recaptures&#34;&gt;Recaptures&lt;/h3&gt;
&lt;p&gt;Table 3. Recapture data.&lt;/p&gt;
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;Column&lt;/th&gt;
					&lt;th&gt;Description&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;DateRecapture&lt;/td&gt;
					&lt;td&gt;The date of recapture (yyyy-mm-dd)&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;ExternalTagNumber1&lt;/td&gt;
					&lt;td&gt;The first external tag number (leave blank if missing or not applicable)&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;ExternalTagNumber2&lt;/td&gt;
					&lt;td&gt;The second external tag number (leave blank if missing or not applicable)&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Anglers must return all non-missing external tags to receive the reward.&lt;/p&gt;
&lt;h3 id=&#34;acoustic-tags&#34;&gt;Acoustic Tags&lt;/h3&gt;
&lt;p&gt;Table 4. Acoustic tag data.&lt;/p&gt;
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;Column&lt;/th&gt;
					&lt;th&gt;Description&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;AcousticTagNumber&lt;/td&gt;
					&lt;td&gt;The unique acoustic tag number&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;AcousticTagModel&lt;/td&gt;
					&lt;td&gt;The manufacturers tag model code&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;AcousticTagLife&lt;/td&gt;
					&lt;td&gt;The acoustic tag life (days)&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Recovered acoustic tags should not be reused in the same study.&lt;/p&gt;
&lt;h3 id=&#34;external-tags&#34;&gt;External Tags&lt;/h3&gt;
&lt;p&gt;Table 5. External tag data.&lt;/p&gt;
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;Column&lt;/th&gt;
					&lt;th&gt;Description&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;ExternalTagNumber&lt;/td&gt;
					&lt;td&gt;The unique external tag number&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;ExternalTagValue&lt;/td&gt;
					&lt;td&gt;The reward value of the tag ($0 if a standard tag)&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;ExternalTagColor&lt;/td&gt;
					&lt;td&gt;The color of the tag&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;External tags must include the text REWARD with the reward value and a phone number for reporting purposes.&lt;/p&gt;
&lt;h2 id=&#34;summary&#34;&gt;Summary&lt;/h2&gt;
&lt;p&gt;For accuracy, all latitudes and longitudes should be recorded as decimal degrees to five decimal places.
To minimize conversions, all latitudes and longitudes should be recorded in WGS84 (the internal format of most GPS units).
For consistency, all dates and times should be recorded in local daylight-savings time.&lt;/p&gt;
&lt;p&gt;For details of a more comprehensive but consistent data collection program see the &lt;a href=&#34;https://members.oceantrack.org/data/data-collection&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Ocean Tracking Network&lt;/a&gt;.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Calculating Water Quality Thresholds and Indices for British Columbia using R</title>
      <link>/post/2015/wqbc-vignette/</link>
      <pubDate>Thu, 08 Oct 2015 00:00:00 +0000</pubDate>
      <guid>/post/2015/wqbc-vignette/</guid>
      <description>&lt;p&gt;The &lt;a href=&#34;https://github.com/bcgov/wqbc&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;wqbc&lt;/a&gt; R package calculates water quality thresholds and water quality indices and plots water quality indices spatially and temporally for British Columbia.&lt;/p&gt;
&lt;p&gt;The package was written for the B.C. Ministry of Environment by
Poisson Consulting. Ministry of Environment staff maintain the package.
This vignette was primarily written by &lt;a href=&#34;https://github.com/colinpmillar&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Colin Millar&lt;/a&gt;.&lt;/p&gt;
&lt;h1 id=&#34;introduction&#34;&gt;Introduction&lt;/h1&gt;
&lt;p&gt;The main function of the &lt;code&gt;wqbc&lt;/code&gt; (water quality for British Columbia) package is to calculate the Canadian Council of Ministers of the Environment (CCME) water quality index (WQI) for water bodies in British Columbia, the procedure is set out in the CCME WQI (1.0) &lt;a href=&#34;http://www.ccme.ca/files/Resources/calculators/WQI%20User%27s%20Manual%20%28en%29.pdf&#34; title=&#34;download pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;User&amp;rsquo;s Manual&lt;/a&gt; [@saffran_canadian_2001].&lt;/p&gt;
&lt;p&gt;Water quality indices are calculated using the &lt;code&gt;calc_wqi&lt;/code&gt; function.
In addition water quality thresholds can be calculated with &lt;code&gt;calc_limits&lt;/code&gt;. In this document, &lt;em&gt;thresholds&lt;/em&gt; and &lt;em&gt;limits&lt;/em&gt; are used interchangeably to describe environmental benchmarks for safe levels of specific substances.
For the visual display of the calculated water quality indices over
a map of British Columbia, the function &lt;code&gt;plot_map&lt;/code&gt; is provided.&lt;/p&gt;
&lt;p&gt;The purpose of this document is to provide some background to the calculation of indices,
provide worked examples of the calculation of indices and and to show how various summaries of the indices can be displayed visually.&lt;/p&gt;
&lt;p&gt;The data used in the examples are from the Fraser River basin (data available &lt;a href=&#34;http://data.gc.ca/data/en/dataset/9ec91c92-22f8-4520-8b2c-0f1cce663e18&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here&lt;/a&gt; under the &lt;a href=&#34;http://open.canada.ca/en/open-government-licence-canada&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Candian Open Government License&lt;/a&gt;, and an example taken from the CCME WQI &lt;a href=&#34;http://www.ccme.ca/files/Resources/calculators/WQI%20User%27s%20Manual%20%28en%29.pdf&#34; title=&#34;download pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;User&amp;rsquo;s Manual&lt;/a&gt; [@saffran_canadian_2001].&lt;/p&gt;
&lt;p&gt;The following methods of analyzing water quality are provided:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Calculation of thresholds for water quality variables&lt;/li&gt;
&lt;li&gt;Calculation of the CCME water quality index&lt;/li&gt;
&lt;li&gt;Methods for visualization of water quality indices&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The package is intended to be easy to use and provide a flexible means for the exploration of water quality monitoring data. The document is split into the following sections:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;[The CCME Water Quality Index (1.0)]&lt;/li&gt;
&lt;li&gt;[The CCME Example]&lt;/li&gt;
&lt;li&gt;[Data Format]&lt;/li&gt;
&lt;li&gt;[Water Quality Index Calculation]&lt;/li&gt;
&lt;li&gt;[Visual Display of Indices]&lt;/li&gt;
&lt;/ul&gt;
&lt;!--
____________________________________________________

     An overview of the index definition
____________________________________________________

--&gt;
&lt;h1 id=&#34;the-ccme-water-quality-index-10&#34;&gt;The CCME Water Quality Index (1.0)&lt;/h1&gt;
&lt;p&gt;Water quality is assessed by the monitoring of a range of parameters, referred to in this document as &lt;em&gt;variables&lt;/em&gt;.  The majority of water quality variables are concentrations of various chemicals, however, quantities such as water turbidity and pH are also important.  Comprehensive water quality monitoring has been undertaken in the Fraser River Basin (BC, Canada) since 1979, and this data is provided in the package, however the tools in this package can be applied to any suitable data set provided it meets specific requirements detailed in the [Data Format] section.&lt;/p&gt;
&lt;p&gt;The CCME Water Quality Index (1.0) is based on a combination of three factors (F1 to F3):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;F1: &lt;strong&gt;Scope&lt;/strong&gt; the percent of variables where thresholds are exceeded at least once,&lt;/li&gt;
&lt;li&gt;F2: &lt;strong&gt;Frequency&lt;/strong&gt; the percent of individual tests in which thresholds are exceeded, and&lt;/li&gt;
&lt;li&gt;F3: &lt;strong&gt;Amplitude&lt;/strong&gt; the amount by which the thresholds are exceeded.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These are combined to produce a single value (between 0 and 100) which is then converted to a ranking of quality (poor, marginal, fair, good, and excellent) intended to describe overall water quality.   In the [Water Quality Index Calculation] section you can see examples of the CCME WQI in action.&lt;/p&gt;
&lt;p&gt;The (CCME) WQI is used across Canada as a standardized approach to roll-up the status of multiple water quality parameters at a site and communicate the ‘state’ in a simple manner. The WQI focuses on water quality with respect to the health of freshwater aquatic health. The WQI approach is documented on the &lt;a href=&#34;http://www.ccme.ca/en/resources/canadian_environmental_quality_guidelines/index.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;CCME website&lt;/a&gt;, including detailed methods, a list of established national parameter guidelines/thresholds, and a point and click &lt;a href=&#34;http://www.ccme.ca/files/Resources/calculators/WQI%20Calculator%201.2%20%28en%29.xls&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;MS Excel Calculator&lt;/a&gt;.&lt;/p&gt;
&lt;!--
____________________________________________________

               Easy Example Section
____________________________________________________

--&gt;
&lt;h1 id=&#34;the-ccme-example&#34;&gt;The CCME Example&lt;/h1&gt;
&lt;p&gt;Lets begin with an example to help understand how the wqbc package works in practice. To begin the package is loaded into R using&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;library(wqbc)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;a good example dataset is that tabled in the CCME WQI (1.0) &lt;a href=&#34;http://www.ccme.ca/files/Resources/calculators/WQI%20User%27s%20Manual%20%28en%29.pdf&#34; title=&#34;download pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;User&amp;rsquo;s Manual&lt;/a&gt;, which uses a simplified data set from the North Saskatchewan River at Devon, Alberta. A table of the data is given below&lt;/p&gt;
&lt;!-- html table generated in R 3.2.2 by xtable 1.7-4 package --&gt;
&lt;!-- Thu Oct  8 09:36:34 2015 --&gt;
&lt;table border=1&gt;
&lt;tr&gt; &lt;th&gt;  &lt;/th&gt; &lt;th&gt; Date &lt;/th&gt; &lt;th&gt; DO &lt;/th&gt; &lt;th&gt; pH &lt;/th&gt; &lt;th&gt; TP &lt;/th&gt; &lt;th&gt; TN &lt;/th&gt; &lt;th&gt; FC &lt;/th&gt; &lt;th&gt; As &lt;/th&gt; &lt;th&gt; Pb &lt;/th&gt; &lt;th&gt; Hg &lt;/th&gt; &lt;th&gt; 2,4-D &lt;/th&gt; &lt;th&gt; Lindane &lt;/th&gt;  &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&#34;right&#34;&gt; 1 &lt;/td&gt; &lt;td&gt; 1997-01-07 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 11.40 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 8.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.01 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.16 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 4.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&#34;right&#34;&gt; 2 &lt;/td&gt; &lt;td&gt; 1997-02-04 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 11.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 7.90 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.01 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.17 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.01 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt;  &lt;/td&gt; &lt;td align=&#34;right&#34;&gt;  &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&#34;right&#34;&gt; 3 &lt;/td&gt; &lt;td&gt; 1997-03-04 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 11.50 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 7.90 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.01 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.13 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 4.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt;  &lt;/td&gt; &lt;td align=&#34;right&#34;&gt;  &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&#34;right&#34;&gt; 4 &lt;/td&gt; &lt;td&gt; 1997-04-08 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 12.50 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 7.90 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.06 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.43 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&#34;right&#34;&gt; 5 &lt;/td&gt; &lt;td&gt; 1997-05-06 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 10.40 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 8.10 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.04 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.25 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt;  &lt;/td&gt; &lt;td align=&#34;right&#34;&gt;  &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&#34;right&#34;&gt; 6 &lt;/td&gt; &lt;td&gt; 1997-06-03 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 8.90 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 8.20 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.11 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.71 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 26.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt;  &lt;/td&gt; &lt;td align=&#34;right&#34;&gt;  &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&#34;right&#34;&gt; 7 &lt;/td&gt; &lt;td&gt; 1997-07-08 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 8.50 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 8.30 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.02 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.15 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 9.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt;  &lt;/td&gt; &lt;td align=&#34;right&#34;&gt;  &lt;/td&gt; &lt;td align=&#34;right&#34;&gt;  &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&#34;right&#34;&gt; 8 &lt;/td&gt; &lt;td&gt; 1997-08-05 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 7.50 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 8.20 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.01 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.15 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 8.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&#34;right&#34;&gt; 9 &lt;/td&gt; &lt;td&gt; 1997-09-02 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 9.20 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 8.20 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.01 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.13 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 12.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt;  &lt;/td&gt; &lt;td align=&#34;right&#34;&gt;  &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&#34;right&#34;&gt; 10 &lt;/td&gt; &lt;td&gt; 1997-10-07 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 11.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 8.10 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.01 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.09 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 12.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&#34;right&#34;&gt; 11 &lt;/td&gt; &lt;td&gt; 1997-11-04 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 12.10 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 8.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.01 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.30 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 8.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.01 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt;  &lt;/td&gt; &lt;td align=&#34;right&#34;&gt;  &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&#34;right&#34;&gt; 12 &lt;/td&gt; &lt;td&gt; 1997-12-01 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 13.30 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 8.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.05 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 4.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt; 0.00 &lt;/td&gt; &lt;td align=&#34;right&#34;&gt;  &lt;/td&gt; &lt;td align=&#34;right&#34;&gt;  &lt;/td&gt; &lt;/tr&gt;
   &lt;/table&gt;
&lt;p&gt;This data is shipped with the wqbc package and has been called &lt;code&gt;ccme&lt;/code&gt;.  To load the &lt;code&gt;ccme&lt;/code&gt; data into the R session run&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;data(ccme)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The first 12 rows of the data contain all the data for Dissolved Oxygen (DO) as shown here&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;head(ccme, 12)
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;#&amp;gt;          Date Variable Value DetectionLimit LowerLimit UpperLimit Units
#&amp;gt; 1  1997-01-07       DO  11.4             NA          5         NA  Mg/L
#&amp;gt; 2  1997-02-04       DO  11.0             NA          5         NA  Mg/L
#&amp;gt; 3  1997-03-04       DO  11.5             NA          5         NA  Mg/L
#&amp;gt; 4  1997-04-08       DO  12.5             NA          5         NA  Mg/L
#&amp;gt; 5  1997-05-06       DO  10.4             NA          5         NA  Mg/L
#&amp;gt; 6  1997-06-03       DO   8.9             NA          5         NA  Mg/L
#&amp;gt; 7  1997-07-08       DO   8.5             NA          5         NA  Mg/L
#&amp;gt; 8  1997-08-05       DO   7.5             NA          5         NA  Mg/L
#&amp;gt; 9  1997-09-02       DO   9.2             NA          5         NA  Mg/L
#&amp;gt; 10 1997-10-07       DO  11.0             NA          5         NA  Mg/L
#&amp;gt; 11 1997-11-04       DO  12.1             NA          5         NA  Mg/L
#&amp;gt; 12 1997-12-01       DO  13.3             NA          5         NA  Mg/L
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Not only are the observed water chemistry values, there is auxiliary information
on the analysis methods used, i.e. the detection limits, as well as the
lower and upper limits and the units of measurement.  The water quality index based on all this data is calculated using the command&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;calc_wqi(ccme)
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;#&amp;gt;      WQI Lower Upper Category Variables Tests F1  F2  F3
#&amp;gt; WQI 88.1  87.3  94.2     Good        10   103 20 3.9 2.8
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Giving the result 88.1, and given the categories defined in the CCME WQI this equates to a score of &amp;lsquo;Good&amp;rsquo;.  The &lt;code&gt;calc_wqi&lt;/code&gt; function gives some additional information.  The values for each component of the index are given, so, F1 = 20, F2 = 3.9, and F3 = 2.8.  We are also told that there were 10 variables included in the index, which allows us to interpret F1=20 as there being 2 variables which did not meet objectives, however, the proportion of tests not meeting objectives (F2) and the excursions were small (F3) so that these failures are not considered to be a concern.  In order to assess the certainty of the classification, confidence intervals are provided for the overall WQI.  In this case, both confidence intervals lie within the definition of &amp;lsquo;Good&amp;rsquo;.&lt;/p&gt;
&lt;!--
____________________________________________________

     Something on data?  Might put this to the end
____________________________________________________

--&gt;
&lt;h1 id=&#34;data-format&#34;&gt;Data Format&lt;/h1&gt;
&lt;p&gt;There are two datasets provided with the package which follow the data format required by the index calculation routines:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;[ccme] This dataset contains the CCME (Canadian Council of Ministers of the Environment) Water Quality Index 1.0 &lt;a href=&#34;http://www.ccme.ca/files/Resources/calculators/WQI%20User%27s%20Manual%20%28en%29.pdf&#34; title=&#34;download pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;User&amp;rsquo;s Manual&lt;/a&gt; example dataset [@saffran_canadian_2001].  The data is a time series of water chemistry measurements taken from North Saskatchewan river at Devon throughout 1997.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;[Fraser] This dataset contains long term surface freshwater quality monitoring data from the Fraser River Basin (the data was extracted from &lt;a href=&#34;http://open.canada.ca/data/en/dataset/9ec91c92-22f8-4520-8b2c-0f1cce663e18&#34; title=&#34;data&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here&lt;/a&gt; where it is provided under the &lt;a href=&#34;http://open.canada.ca/en/open-government-licence-canada&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Candian Open Government License&lt;/a&gt;) carried out under the Canada-British Columbia Water Quality Monitoring Agreement. Water quality monitoring is conducted to assess water quality status and long-term trends, detect emerging issues, establish water quality guidelines and track the effectiveness of remedial measures and regulatory decisions&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The minimal data format is a data frame with columns named, &lt;code&gt;Variable&lt;/code&gt;, &lt;code&gt;Value&lt;/code&gt; and &lt;code&gt;Units&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#&amp;gt;   Variable Value Units
#&amp;gt; 1       DO  11.4  Mg/L
#&amp;gt; 2       DO  11.0  Mg/L
#&amp;gt; 3       DO  11.5  Mg/L
#&amp;gt; 4       DO  12.5  Mg/L
#&amp;gt; 5       DO  10.4  Mg/L
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;however, this data can only be used if there are water quality limits defined.  The list of variables for which limits are defined can be found using the &lt;code&gt;lookup_limits&lt;/code&gt; function&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;lookup_limits()
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;#&amp;gt;                         Variable UpperLimit Units
#&amp;gt; 1            Aluminium Dissolved         NA  mg/L
#&amp;gt; 2                  Arsenic Total      5.000  ug/L
#&amp;gt; 3                          Boron      1.200  mg/L
#&amp;gt; 4              Cadmium Dissolved         NA  ug/L
#&amp;gt; 5                 Chloride Total         NA  mg/L
#&amp;gt; 6        Chlorine Total Residual      2.000  ug/L
#&amp;gt; 7                   Cobalt Total      4.000  ug/L
#&amp;gt; 8                   Copper Total         NA  ug/L
#&amp;gt; 9  Cyanide Weak Acid Dissociable      5.000  ug/L
#&amp;gt; 10          Ethinylestradiol 17a      0.500  ng/L
#&amp;gt; 11                  Ethylbenzene      0.200  mg/L
#&amp;gt; 12                          Lead         NA  ug/L
#&amp;gt; 13                     Manganese         NA  mg/L
#&amp;gt; 14                 Mercury Total         NA  ug/L
#&amp;gt; 15   Methyl Tertiary Butyl Ether      3.400  mg/L
#&amp;gt; 16              Molybdenum Total      1.000  mg/L
#&amp;gt; 17                 Nitrate Total      3.000  mg/L
#&amp;gt; 18                       Nitrite         NA  mg/L
#&amp;gt; 19                Selenium Total      0.002  mg/L
#&amp;gt; 20                        Silver         NA  ug/L
#&amp;gt; 21                      Sulphate         NA  mg/L
#&amp;gt; 22                       Toluene      0.039  mg/L
#&amp;gt; 23                    Zinc Total         NA  ug/L
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This function will be discussed further in the following section, but note for now that the variable listed as &lt;code&gt;DO&lt;/code&gt; (Dissolved Oxygen) in the &lt;code&gt;ccme&lt;/code&gt; data does not have a corresponding limit defined in &lt;code&gt;lookup_limits&lt;/code&gt; and so for water quality indices to be calculated for the &lt;code&gt;ccme&lt;/code&gt; data, there must be thresholds provided for each observation. This should be included by providing
upper limits in a column called &lt;code&gt;UpperLimit&lt;/code&gt;, and optionally
lower limits in &lt;code&gt;LowerLimit&lt;/code&gt;, for example&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;head(ccme, 5)
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;#&amp;gt;         Date Variable Value DetectionLimit LowerLimit UpperLimit Units
#&amp;gt; 1 1997-01-07       DO  11.4             NA          5         NA  Mg/L
#&amp;gt; 2 1997-02-04       DO  11.0             NA          5         NA  Mg/L
#&amp;gt; 3 1997-03-04       DO  11.5             NA          5         NA  Mg/L
#&amp;gt; 4 1997-04-08       DO  12.5             NA          5         NA  Mg/L
#&amp;gt; 5 1997-05-06       DO  10.4             NA          5         NA  Mg/L
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To show this in action, lets arbitrarily set all the upper limits in the ccme data to 50, and see what the water quality index is&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;ccme2 &amp;lt;- ccme
ccme2 $ UpperLimit &amp;lt;- 50
calc_wqi(ccme2)
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;#&amp;gt; Calculating water quality indices...
#&amp;gt; Deleted 17 rows with missing or negative values in Value.
#&amp;gt; Replaced 31 of the values in column Value with the detection limit in column DetectionLimit.
#&amp;gt; Calculated water quality indices.
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;#&amp;gt;     WQI Lower Upper  Category Variables Tests F1 F2 F3
#&amp;gt; WQI 100   100   100 Excellent        10   103  0  0  0
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And as expected by setting the  thresholds arbitrarily high, we get no failures and an Excellent marking!&lt;/p&gt;
&lt;!--
____________________________________________________

     More in depth description and use of the calc_wqi function
____________________________________________________

--&gt;
&lt;h1 id=&#34;water-quality-index-calculation&#34;&gt;Water Quality Index Calculation&lt;/h1&gt;
&lt;p&gt;To explore the functions in more detail a larger data set than &lt;code&gt;ccme&lt;/code&gt; is required. Contained in the &lt;code&gt;wqbc&lt;/code&gt; package is a second dataset: a copy of the Fraser Basin long term surface freshwater quality monitoring data.  To load this data run&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;data(fraser)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As with the &lt;code&gt;ccme&lt;/code&gt; data, the &lt;code&gt;fraser&lt;/code&gt; data is organized so that each row corresponds to one observation.  The first 10 observations in the &lt;code&gt;fraser&lt;/code&gt; dataset are:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;head(fraser, 10)
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;#&amp;gt;        SiteID       Date               Variable   Value Units
#&amp;gt; 1  BC08MB0007 2004-11-15 ALKALINITY TOTAL CACO3  36.900  MG/L
#&amp;gt; 2  BC08MB0007 2004-11-15   ALUMINUM EXTRACTABLE 736.000  UG/L
#&amp;gt; 3  BC08MB0007 2004-11-15         ALUMINUM TOTAL 747.000  UG/L
#&amp;gt; 4  BC08MB0007 2004-11-15      AMMONIA DISSOLVED   0.005  MG/L
#&amp;gt; 5  BC08MB0007 2004-11-15   ANTIMONY EXTRACTABLE   0.044  UG/L
#&amp;gt; 6  BC08MB0007 2004-11-15         ANTIMONY TOTAL   0.045  UG/L
#&amp;gt; 7  BC08MB0007 2004-11-15    ARSENIC EXTRACTABLE   0.430  UG/L
#&amp;gt; 8  BC08MB0007 2004-11-15          ARSENIC TOTAL   0.460  UG/L
#&amp;gt; 9  BC08MB0007 2004-11-15     BARIUM EXTRACTABLE  14.300  UG/L
#&amp;gt; 10 BC08MB0007 2004-11-15           BARIUM TOTAL  14.400  UG/L
#&amp;gt;                                                Site      Lat      Long
#&amp;gt; 1  Chilcotin River upstream of Christie Road Bridge 52.07197 -123.2614
#&amp;gt; 2  Chilcotin River upstream of Christie Road Bridge 52.07197 -123.2614
#&amp;gt; 3  Chilcotin River upstream of Christie Road Bridge 52.07197 -123.2614
#&amp;gt; 4  Chilcotin River upstream of Christie Road Bridge 52.07197 -123.2614
#&amp;gt; 5  Chilcotin River upstream of Christie Road Bridge 52.07197 -123.2614
#&amp;gt; 6  Chilcotin River upstream of Christie Road Bridge 52.07197 -123.2614
#&amp;gt; 7  Chilcotin River upstream of Christie Road Bridge 52.07197 -123.2614
#&amp;gt; 8  Chilcotin River upstream of Christie Road Bridge 52.07197 -123.2614
#&amp;gt; 9  Chilcotin River upstream of Christie Road Bridge 52.07197 -123.2614
#&amp;gt; 10 Chilcotin River upstream of Christie Road Bridge 52.07197 -123.2614
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In this dataset the auxiliary data available are a site identifier (&lt;code&gt;SiteID&lt;/code&gt;), the site name in full (&lt;code&gt;Site&lt;/code&gt;), and the position in terms of latitude (&lt;code&gt;Lat&lt;/code&gt;) and longitude (&lt;code&gt;Long&lt;/code&gt;).  This information can be used to visualize the site positions on a map, and through the use of coloured symbols, additional information, such as the site name, can be included.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;plot_map(fraser, fill = &amp;quot;SiteID&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;















&lt;figure  &gt;
  &lt;div class=&#34;d-flex justify-content-center&#34;&gt;
    &lt;div class=&#34;w-100&#34; &gt;&lt;img src=&#34;/post/wqbc-vignette/figures/unnamed-chunk-12-1.png&#34; alt=&#34;&#34; loading=&#34;lazy&#34; data-zoomable /&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p&gt;For more information on plotting see the section on [Visual Display of Indices].  This will be particularly useful when summarizing the results of the water quality index calculations.&lt;/p&gt;
&lt;p&gt;To calculate the long-term water quality index for each site all that needs to be done is to run&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;calc_wqi(fraser, by = &amp;quot;SiteID&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But this does not help to explain what is going on which is the purpose of this section.&lt;/p&gt;
&lt;!-- ____________________________________________________ --&gt;
&lt;h2 id=&#34;cleaning-and-standardising-data&#34;&gt;cleaning and standardising data&lt;/h2&gt;
&lt;p&gt;The &lt;code&gt;fraser&lt;/code&gt; data is a large dataset, and to get things started we will use a &lt;code&gt;subset&lt;/code&gt;  of this data.  Lets take the data from 2012.  A useful package for working with the dates is the &lt;code&gt;lubridate&lt;/code&gt; package. We will use the function &lt;code&gt;year&lt;/code&gt; from the lubridate package to help subset the data.  Before using the &lt;code&gt;year&lt;/code&gt; function you should make sure the &lt;code&gt;lubridate&lt;/code&gt; package is loaded by running &lt;code&gt;library(lubridate)&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;library(lubridate)
data2012 &amp;lt;- subset(fraser, year(Date) == 2012)
head(data2012)
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;#&amp;gt;           SiteID       Date               Variable    Value Units
#&amp;gt; 12659 BC08MB0007 2012-01-10 ALKALINITY TOTAL CACO3  55.2000  MG/L
#&amp;gt; 12660 BC08MB0007 2012-01-10         ALUMINUM TOTAL 318.0000  UG/L
#&amp;gt; 12661 BC08MB0007 2012-01-10      AMMONIA DISSOLVED   0.0103  MG/L
#&amp;gt; 12662 BC08MB0007 2012-01-10         ANTIMONY TOTAL   0.0470  UG/L
#&amp;gt; 12663 BC08MB0007 2012-01-10          ARSENIC TOTAL   0.4600  UG/L
#&amp;gt; 12664 BC08MB0007 2012-01-10           BARIUM TOTAL  11.2000  UG/L
#&amp;gt;                                                   Site      Lat      Long
#&amp;gt; 12659 Chilcotin River upstream of Christie Road Bridge 52.07197 -123.2614
#&amp;gt; 12660 Chilcotin River upstream of Christie Road Bridge 52.07197 -123.2614
#&amp;gt; 12661 Chilcotin River upstream of Christie Road Bridge 52.07197 -123.2614
#&amp;gt; 12662 Chilcotin River upstream of Christie Road Bridge 52.07197 -123.2614
#&amp;gt; 12663 Chilcotin River upstream of Christie Road Bridge 52.07197 -123.2614
#&amp;gt; 12664 Chilcotin River upstream of Christie Road Bridge 52.07197 -123.2614
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We are now in a position to calculate the long term water quality index for 2012, and as previously stated, this is done using&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;calc_wqi(data2012)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The function &lt;code&gt;calc_wqi&lt;/code&gt; performs a number of tasks.  The first of these is to check if the dataset contains user defined limits in columns called &lt;code&gt;UpperLimit&lt;/code&gt; or &lt;code&gt;LowerLimit&lt;/code&gt;.  If the dataset has these columns, the function proceeds directly to calculating the water quality index.&lt;/p&gt;
&lt;p&gt;If the data do not contain user defined limits, as is the case for the &lt;code&gt;fraser&lt;/code&gt; dataset, the next steps are to check and standardize the data so that they can be matched with known water quality limits. The list of known water quality limits can be queried using the function &lt;code&gt;lookup_limits&lt;/code&gt;, which has arguments to help evaluate the limit.  Because some limits are dependent on the concentrations of other chemicals, &lt;code&gt;lookup_limits&lt;/code&gt; has the following arguments: &lt;code&gt;ph&lt;/code&gt;, &lt;code&gt;hardness&lt;/code&gt;, &lt;code&gt;chloride&lt;/code&gt; and &lt;code&gt;methyl_mercury&lt;/code&gt;.  In addition because limits are different depending on the time scale, there is a further argument &lt;code&gt;term&lt;/code&gt; which can take the values &amp;ldquo;short&amp;rdquo; or &amp;ldquo;long&amp;rdquo; (defined later in [Calculating limits]).&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;lookup_limits(ph = 7)
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;#&amp;gt;                         Variable UpperLimit Units
#&amp;gt; 1            Aluminium Dissolved      0.050  mg/L
#&amp;gt; 2                  Arsenic Total      5.000  ug/L
#&amp;gt; 3                          Boron      1.200  mg/L
#&amp;gt; 4              Cadmium Dissolved         NA  ug/L
#&amp;gt; 5                 Chloride Total         NA  mg/L
#&amp;gt; 6        Chlorine Total Residual      2.000  ug/L
#&amp;gt; 7                   Cobalt Total      4.000  ug/L
#&amp;gt; 8                   Copper Total         NA  ug/L
#&amp;gt; 9  Cyanide Weak Acid Dissociable      5.000  ug/L
#&amp;gt; 10          Ethinylestradiol 17a      0.500  ng/L
#&amp;gt; 11                  Ethylbenzene      0.200  mg/L
#&amp;gt; 12                          Lead         NA  ug/L
#&amp;gt; 13                     Manganese         NA  mg/L
#&amp;gt; 14                 Mercury Total         NA  ug/L
#&amp;gt; 15   Methyl Tertiary Butyl Ether      3.400  mg/L
#&amp;gt; 16              Molybdenum Total      1.000  mg/L
#&amp;gt; 17                 Nitrate Total      3.000  mg/L
#&amp;gt; 18                       Nitrite         NA  mg/L
#&amp;gt; 19                Selenium Total      0.002  mg/L
#&amp;gt; 20                        Silver         NA  ug/L
#&amp;gt; 21                      Sulphate         NA  mg/L
#&amp;gt; 22                       Toluene      0.039  mg/L
#&amp;gt; 23                    Zinc Total         NA  ug/L
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;From this we can see that there are 23 standard variables with limits defined.  Some variable in the previous example have &lt;code&gt;NA&lt;/code&gt; because these limits require knowledge of hardness, chloride or methyl mercury concentrations.&lt;/p&gt;
&lt;p&gt;The first step in assigning these limits to observations involves converting any non-standard variable names, checking and converting the units, and removing any missing and negative values.  Although this is done within the &lt;code&gt;calc_wqi&lt;/code&gt; function, it can be useful to run a manual check on the data first.  This is done using the &lt;code&gt;standardize_wqdata&lt;/code&gt; function&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;data2012 &amp;lt;- standardize_wqdata(data2012)
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;#&amp;gt; Standardizing water quality data...
#&amp;gt; Deleted 45 rows with negative values in Value.
#&amp;gt; Substituted &#39;ALUMINUM DISSOLVED&#39; with &#39;Aluminium Dissolved&#39;, &#39;ARSENIC TOTAL&#39; with &#39;Arsenic Total&#39;, &#39;BORON DISSOLVED&#39; with &#39;Boron&#39;, &#39;BORON TOTAL&#39; with &#39;Boron&#39;, &#39;CADMIUM DISSOLVED&#39; with &#39;Cadmium Dissolved&#39;, &#39;COBALT TOTAL&#39; with &#39;Cobalt Total&#39;, &#39;COPPER TOTAL&#39; with &#39;Copper Total&#39;, &#39;CYANIDE WEAK ACID DISSOCIABLE&#39; with &#39;Cyanide Weak Acid Dissociable&#39;, &#39;HARDNESS TOTAL (CALCD.) CACO3&#39; with &#39;Hardness Total&#39;, &#39;IRON DISSOLVED&#39; with &#39;Iron Dissolved&#39;, &#39;IRON TOTAL&#39; with &#39;Iron Total&#39;, &#39;LEAD DISSOLVED&#39; with &#39;Lead&#39;, &#39;LEAD TOTAL&#39; with &#39;Lead&#39;, &#39;MANGANESE DISSOLVED&#39; with &#39;Manganese&#39;, &#39;MANGANESE TOTAL&#39; with &#39;Manganese&#39;, &#39;MOLYBDENUM TOTAL&#39; with &#39;Molybdenum Total&#39;, &#39;NITROGEN NITRITE&#39; with &#39;Nitrite&#39;, &#39;PH&#39; with &#39;pH&#39;, &#39;PH - FIELD&#39; with &#39;pH&#39;, &#39;SELENIUM TOTAL&#39; with &#39;Selenium Total&#39;, &#39;SILVER DISSOLVED&#39; with &#39;Silver&#39;, &#39;SILVER TOTAL&#39; with &#39;Silver&#39;, &#39;SULPHATE DISSOLVED&#39; with &#39;Sulphate&#39; and &#39;ZINC TOTAL&#39; with &#39;Zinc Total&#39;.
#&amp;gt; Failed to substitute &#39;ALKALINITY GRAN CACO3&#39;, &#39;ALKALINITY TOTAL CACO3&#39;, &#39;ALUMINUM TOTAL&#39;, &#39;AMMONIA DISSOLVED&#39;, &#39;ANTIMONY DISSOLVED&#39;, &#39;ANTIMONY TOTAL&#39;, &#39;ARSENIC DISSOLVED&#39;, &#39;BARIUM DISSOLVED&#39;, &#39;BARIUM TOTAL&#39;, &#39;BERYLLIUM DISSOLVED&#39;, &#39;BERYLLIUM TOTAL&#39;, &#39;BISMUTH DISSOLVED&#39;, &#39;BISMUTH TOTAL&#39;, &#39;CADMIUM TOTAL&#39;, &#39;CALCIUM DISSOLVED&#39;, &#39;CALCIUM TOTAL&#39;, &#39;CARBON DISSOLVED INORGANIC&#39;, &#39;CARBON DISSOLVED ORGANIC&#39;, &#39;CARBON TOTAL INORGANIC&#39;, &#39;CARBON TOTAL ORGANIC&#39;, &#39;CERIUM DISSOLVED&#39;, &#39;CERIUM TOTAL&#39;, &#39;CESIUM DISSOLVED&#39;, &#39;CESIUM TOTAL&#39;, &#39;CHLORIDE DISSOLVED&#39;, &#39;CHROMIUM DISSOLVED&#39;, &#39;CHROMIUM TOTAL&#39;, &#39;COBALT DISSOLVED&#39;, &#39;COLIFORMS FECAL&#39;, &#39;COLOUR TRUE&#39;, &#39;COPPER DISSOLVED&#39;, &#39;CYANIDE TOTAL&#39;, &#39;ENTEROCOCUS&#39;, &#39;ESCHERICHIA COLI&#39;, &#39;FLUORIDE DISSOLVED&#39;, &#39;GALLIUM DISSOLVED&#39;, &#39;GALLIUM TOTAL&#39;, &#39;LANTHANUM DISSOLVED&#39;, &#39;LANTHANUM TOTAL&#39;, &#39;LITHIUM DISSOLVED&#39;, &#39;LITHIUM TOTAL&#39;, &#39;MAGNESIUM DISSOLVED&#39;, &#39;MAGNESIUM TOTAL&#39;, &#39;MOLYBDENUM DISSOLVED&#39;, &#39;NICKEL DISSOLVED&#39;, &#39;NICKEL TOTAL&#39;, &#39;NIOBIUM DISSOLVED&#39;, &#39;NIOBIUM TOTAL&#39;, &#39;NITROGEN DISSOLVED KJELDAHL&#39;, &#39;NITROGEN DISSOLVED NITRATE&#39;, &#39;NITROGEN DISSOLVED NO3 &amp;amp; NO2&#39;, &#39;NITROGEN DISSOLVED ORGANIC (CALCD.)&#39;, &#39;NITROGEN TOTAL&#39;, &#39;NITROGEN TOTAL DISSOLVED&#39;, &#39;NITROGEN TOTAL KJELDAHL&#39;, &#39;NITROGEN TOTAL ORGANIC (CALCD.)&#39;, &#39;OXYGEN DISSOLVED&#39;, &#39;PHOSPHORUS DISSOLVED ORTHO&#39;, &#39;PHOSPHORUS TOTAL&#39;, &#39;PHOSPHORUS TOTAL DISSOLVED&#39;, &#39;PLATINUM DISSOLVED&#39;, &#39;PLATINUM TOTAL&#39;, &#39;POTASSIUM DISSOLVED&#39;, &#39;POTASSIUM TOTAL&#39;, &#39;RESIDUE FILTERABLE&#39;, &#39;RESIDUE NONFILTRABLE&#39;, &#39;RESIDUE TOTAL&#39;, &#39;RUBIDIUM DISSOLVED&#39;, &#39;RUBIDIUM TOTAL&#39;, &#39;SALINITY&#39;, &#39;SELENIUM DISSOLVED&#39;, &#39;SILICON DISSOLVED&#39;, &#39;SILICON TOTAL&#39;, &#39;SODIUM DISSOLVED&#39;, &#39;SODIUM TOTAL&#39;, &#39;SPECIFIC CONDUCTANCE&#39;, &#39;SPECIFIC CONDUCTANCE - FIELD&#39;, &#39;STRONTIUM DISSOLVED&#39;, &#39;STRONTIUM TOTAL&#39;, &#39;SULPHUR DISSOLVED&#39;, &#39;SULPHUR TOTAL&#39;, &#39;TEMPERATURE AIR&#39;, &#39;TEMPERATURE WATER&#39;, &#39;THALLIUM DISSOLVED&#39;, &#39;THALLIUM TOTAL&#39;, &#39;TIN DISSOLVED&#39;, &#39;TIN TOTAL&#39;, &#39;TITANIUM DISSOLVED&#39;, &#39;TITANIUM TOTAL&#39;, &#39;TUNGSTEN DISSOLVED&#39;, &#39;TUNGSTEN TOTAL&#39;, &#39;TURBIDITY&#39;, &#39;URANIUM DISSOLVED&#39;, &#39;URANIUM TOTAL&#39;, &#39;VANADIUM DISSOLVED&#39;, &#39;VANADIUM TOTAL&#39;, &#39;YTTRIUM DISSOLVED&#39;, &#39;YTTRIUM TOTAL&#39;, &#39;ZINC DISSOLVED&#39;, &#39;ZIRCONIUM DISSOLVED&#39; and &#39;ZIRCONIUM TOTAL&#39;.
#&amp;gt; Deleted 13823 rows with missing values in Variable.
#&amp;gt; Substituted &#39;MG/L&#39; with &#39;mg/L&#39;, &#39;PH UNITS&#39; with &#39;pH&#39; and &#39;UG/L&#39; with &#39;ug/L&#39;.
#&amp;gt; Standardized water quality data.
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;head(data2012)
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;#&amp;gt;       SiteID       Date            Variable  Value Units
#&amp;gt; 1 BC08MH0453 2012-04-13 Aluminium Dissolved 0.0511  mg/L
#&amp;gt; 2 BC08MH0453 2012-05-16 Aluminium Dissolved 0.0043  mg/L
#&amp;gt; 3 BC08MH0453 2012-06-21 Aluminium Dissolved 0.1320  mg/L
#&amp;gt; 4 BC08MH0453 2012-06-21 Aluminium Dissolved 0.1390  mg/L
#&amp;gt; 5 BC08MH0453 2012-06-21 Aluminium Dissolved 0.1310  mg/L
#&amp;gt; 6 BC08MH0453 2012-07-13 Aluminium Dissolved 0.0664  mg/L
#&amp;gt;                                                Site    Lat     Long
#&amp;gt; 1 Fraser River (Main Arm) at Gravesend Reach - Buoy 49.167 -123.035
#&amp;gt; 2 Fraser River (Main Arm) at Gravesend Reach - Buoy 49.167 -123.035
#&amp;gt; 3 Fraser River (Main Arm) at Gravesend Reach - Buoy 49.167 -123.035
#&amp;gt; 4 Fraser River (Main Arm) at Gravesend Reach - Buoy 49.167 -123.035
#&amp;gt; 5 Fraser River (Main Arm) at Gravesend Reach - Buoy 49.167 -123.035
#&amp;gt; 6 Fraser River (Main Arm) at Gravesend Reach - Buoy 49.167 -123.035
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that the effect of running &lt;code&gt;standardize_wqdata&lt;/code&gt; is to convert some variable names to a standard form, for example, &amp;lsquo;ALUMINUM DISSOLVED&amp;rsquo; has been replaced with &amp;lsquo;Aluminium Dissolved&amp;rsquo;.  The messages output by the function relay this information, along with all the other substitutions made.  In addition, there are a number of variable names which are not part of the standard list of variables and were removed from the dataset. Unit names are also standardized, for example &amp;lsquo;MG/L&amp;rsquo; has been replaced with &amp;lsquo;mg/L&amp;rsquo;, there are also some unrecognized units which result in the related observations being removed from the dataset.  As a result of the standardization, the 2012 Fraser dataset has been reduced from 18062 recorded observations, to 4194 standard observations, which can all be matched with the  thresholds.&lt;/p&gt;
&lt;p&gt;After standardization, it is necessary to ensure that there are only single values for each date for a given variable and this is done using the function &lt;code&gt;clean_wqdata&lt;/code&gt;.  If the data is to be considered as observations of one entity, i.e. the whole Fraser river basin, then this function will average over all data occurring on a given day. If this was desired, the following code would be used&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;clean_wqdata(data2012)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;However, with the Fraser river basin data it makes more sense to consider the data as observations of different sites within the river basin.  To tell the &lt;code&gt;clean_wqdata&lt;/code&gt; function to average observations within site, the argument &lt;code&gt;by&lt;/code&gt; is used&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;data2012 &amp;lt;- clean_wqdata(data2012, by = &amp;quot;SiteID&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;#&amp;gt; Standardizing water quality data...
#&amp;gt; Standardized water quality data.
#&amp;gt; Cleaning water quality data...
#&amp;gt; Cleansed water quality data.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In this case there are no problems, and the data is ready for the next step. Note that, to be on the safe side, the function &lt;code&gt;clean_wqdata&lt;/code&gt; runs a standardization again, in case it wasn&amp;rsquo;t done previously.&lt;/p&gt;
&lt;!-- ____________________________________________________ --&gt;
&lt;h2 id=&#34;calculating-limits&#34;&gt;Calculating limits&lt;/h2&gt;
&lt;p&gt;Now that we have observations for a range of standard variables it is possible to calculate the relevant limits with which to assess exceedances.  Taking into account the various rules for calculating thresholds for the standard variables, the function &lt;code&gt;calc_limits&lt;/code&gt; calculates the limits required to evaluate the water quality index.  Again, if it is required to calculate the water quality index for each site, then the &lt;code&gt;by&lt;/code&gt; argument is used&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;calc_limits(data2012, by = &amp;quot;SiteID&amp;quot;, term = &amp;quot;long&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;#&amp;gt; Standardizing water quality data...
#&amp;gt; Standardized water quality data.
#&amp;gt; Cleaning water quality data...
#&amp;gt; Cleansed water quality data.
#&amp;gt; Calculating long-term water quality limits...
#&amp;gt; Calculated long-term water quality limits.
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;#&amp;gt;        SiteID       Date         Variable      Value UpperLimit Units
#&amp;gt; 1  BC08MC0001 2012-04-11    Arsenic Total  1.8500000   5.000000  ug/L
#&amp;gt; 2  BC08MC0001 2012-04-11            Boron  0.0024400   1.200000  mg/L
#&amp;gt; 3  BC08MC0001 2012-04-11     Cobalt Total  4.5840000   4.000000  ug/L
#&amp;gt; 4  BC08MC0001 2012-04-11     Copper Total 13.8340000   2.332800  ug/L
#&amp;gt; 5  BC08MC0001 2012-04-11             Lead  3.0680000   4.913114  ug/L
#&amp;gt; 6  BC08MC0001 2012-04-11        Manganese  0.2528000   0.861608  mg/L
#&amp;gt; 7  BC08MC0001 2012-04-11 Molybdenum Total  0.0005056   1.000000  mg/L
#&amp;gt; 8  BC08MC0001 2012-04-11   Selenium Total  0.0001440   0.002000  mg/L
#&amp;gt; 9  BC08MC0001 2012-04-11           Silver  0.0538000   0.050000  ug/L
#&amp;gt; 10 BC08MC0001 2012-04-11       Zinc Total 23.4400000   7.500000  ug/L
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now the 2012 Fraser River basin data has been reduced to daily means of the standard variables, and  thresholds have been attributed to each observation.  A visual inspection of the data shows that for the period starting the 11th April, several variables at the &lt;code&gt;BC08MC0001&lt;/code&gt; site are above their long-term limits, i.e. Cobalt Total, Copper Total, Silver and Zinc Total.&lt;/p&gt;
&lt;!-- ____________________________________________________ --&gt;
&lt;h3 id=&#34;long-or-short-term&#34;&gt;Long or Short term&lt;/h3&gt;
&lt;p&gt;In the previous output, the &lt;code&gt;calc_limits&lt;/code&gt; function returned a total of ten limits, all with the same date and all from the same site.  But what is going on?  A plot of the 2012 data show that there are observations throughout the year from a number of different sites. (Note this plot requires the use of the library &lt;code&gt;ggplot2&lt;/code&gt;, which is loaded using &lt;code&gt;library(ggplot2)&lt;/code&gt;)&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;qplot(Date, SiteID, xlab = &amp;quot;&amp;quot;, ylab = &amp;quot;&amp;quot;, data = data2012, colour = SiteID == &amp;quot;BC08MC0001&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;















&lt;figure  &gt;
  &lt;div class=&#34;d-flex justify-content-center&#34;&gt;
    &lt;div class=&#34;w-100&#34; &gt;&lt;img src=&#34;/post/wqbc-vignette/figures/unnamed-chunk-21-1.png&#34; alt=&#34;&#34; loading=&#34;lazy&#34; data-zoomable /&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p&gt;The point here is that the &lt;code&gt;calc_limits&lt;/code&gt; function can calculate long or short-term limits.  For long-term limits, thresholds are calculated for each 30 day period.  Then in the water quality calculation, these 30 day periods are treated as individual test units for exceedances. There are strict rules applied to whether a 30 day period is considered valid for limit calculation: there must be at least 5 values spanning at least 21 days in a 30 day period for that period to be valid, and since replicates are averaged (by the &lt;code&gt;clean_wqdata&lt;/code&gt; function) prior to calculating the limits each of the 5 values must occur on a separate date.  This explains why the long term limits, by site are so few for the 2012 data: only the &lt;code&gt;BC08MC0001&lt;/code&gt; site has sufficiently frequent observations, occurring once in the year in the 30 day period following the 11th of April, to be considered valid for the calculation of long-term limits.&lt;/p&gt;
&lt;p&gt;The strict conditions required for long-term limits are not required when calculating short-term limits, where instead individual days are considered as the test units for exceedances.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;data2012 &amp;lt;- calc_limits(data2012, by = &amp;quot;SiteID&amp;quot;, term = &amp;quot;short&amp;quot;) 
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;#&amp;gt; Standardizing water quality data...
#&amp;gt; Standardized water quality data.
#&amp;gt; Cleaning water quality data...
#&amp;gt; Cleansed water quality data.
#&amp;gt; Calculating short-term water quality limits...
#&amp;gt; Calculated short-term water quality limits.
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;head(data2012, 12)
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;#&amp;gt;        SiteID       Date         Variable   Value UpperLimit Units
#&amp;gt; 1  BC08KA0007 2012-01-24     Cobalt Total 0.20000 110.000000  ug/L
#&amp;gt; 2  BC08KA0007 2012-01-24     Copper Total 0.45000   9.491800  ug/L
#&amp;gt; 3  BC08KA0007 2012-01-24       Iron Total 0.03030   1.000000  mg/L
#&amp;gt; 4  BC08KA0007 2012-01-24             Lead 0.01000  61.162679  ug/L
#&amp;gt; 5  BC08KA0007 2012-01-24        Manganese 0.01120   1.418294  mg/L
#&amp;gt; 6  BC08KA0007 2012-01-24 Molybdenum Total 0.00007   2.000000  mg/L
#&amp;gt; 7  BC08KA0007 2012-01-24           Silver 0.00100   0.100000  ug/L
#&amp;gt; 8  BC08KA0007 2012-01-24       Zinc Total 0.30000  33.000000  ug/L
#&amp;gt; 9  BC08KA0007 2012-04-11     Cobalt Total 0.20000 110.000000  ug/L
#&amp;gt; 10 BC08KA0007 2012-04-11     Copper Total 0.42000   9.679800  ug/L
#&amp;gt; 11 BC08KA0007 2012-04-11       Iron Total 0.04450   1.000000  mg/L
#&amp;gt; 12 BC08KA0007 2012-04-11             Lead 0.02100  63.123160  ug/L
&lt;/code&gt;&lt;/pre&gt;
&lt;!-- ____________________________________________________ --&gt;
&lt;h2 id=&#34;calculating-the-water-quality-index&#34;&gt;Calculating the Water Quality Index&lt;/h2&gt;
&lt;p&gt;Note that the default for calculating the water quality index is the use of long-term limits, but for the sake of continuing the example, we will keep with the 2012 data.  Lets begin by summarizing the steps so far: The full Fraser river basin dataset was subset to retain only the data from 2012.  Then this data (which we have called &lt;code&gt;data2012&lt;/code&gt;) was first, standardized, cleaned and then the  limits were calculated for daily values.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;data2012 &amp;lt;- subset(fraser, year(Date) == 2012)
data2012 &amp;lt;- standardize_wqdata(data2012)
data2012 &amp;lt;- clean_wqdata(data2012, by = &amp;quot;SiteID&amp;quot;)
data2012 &amp;lt;- calc_limits(data2012, by = &amp;quot;SiteID&amp;quot;, term = &amp;quot;short&amp;quot;) 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The data is now ready to have the water quality index calculated for each site, and this is done using&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;wqi2012 &amp;lt;- calc_wqi(data2012, by = &amp;quot;SiteID&amp;quot;) 
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;#&amp;gt; Calculating water quality indices...
#&amp;gt; Added missing column LowerLimit to x.
#&amp;gt; Added missing column DetectionLimit to x.
#&amp;gt; Calculated water quality indices.
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;wqi2012
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;#&amp;gt;        SiteID   WQI Lower Upper  Category Variables Tests   F1   F2   F3
#&amp;gt; 1  BC08KA0007 100.0 100.0 100.0 Excellent         8   160  0.0  0.0  0.0
#&amp;gt; 2  BC08KE0010  92.7  92.3 100.0      Good         8   184 12.5  1.1  1.4
#&amp;gt; 3  BC08KH0012  89.5  85.4 100.0      Good        11   195 18.2  1.0  0.7
#&amp;gt; 4  BC08LC0005  93.6  93.5 100.0      Good         9   226 11.1  0.4  0.0
#&amp;gt; 5  BC08LE0004  86.8  85.9  93.5      Good         9   204 22.2  3.4  4.0
#&amp;gt; 6  BC08LF0001  85.5  85.2 100.0      Good         8   200 25.0  2.0  1.4
#&amp;gt; 7  BC08LG0001  85.2  83.8 100.0      Good         8    96 25.0  3.1  4.3
#&amp;gt; 8  BC08MB0007  85.0  83.4  92.6      Good         8   144 25.0  5.6  4.8
#&amp;gt; 9  BC08MC0001  73.1  68.9  82.9      Fair         8   208 37.5 12.0 24.8
#&amp;gt; 10 BC08MF0001  82.8  80.2  84.7      Good         8   216 25.0  9.3 13.4
#&amp;gt; 11 BC08MH0269 100.0 100.0 100.0 Excellent        10   212  0.0  0.0  0.0
#&amp;gt; 12 BC08MH0453  83.2  80.8  94.2      Good        11   140 27.3  7.9  6.8
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Due to the sampling frequency in 2012, it is not possible to calculate long term limits, because there are not enough samples in each 30 day period for each site.  A long-term water quality index for 2012 can be calculated for the whole river basin:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;data2012 &amp;lt;- subset(fraser, year(Date) == 2012)
calc_wqi(data2012) 
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;#&amp;gt;     WQI Lower Upper Category Variables Tests   F1  F2  F3
#&amp;gt; WQI  90  88.3  95.1     Good        12   121 16.7 4.1 2.5
&lt;/code&gt;&lt;/pre&gt;
&lt;!--
____________________________________________________

     More in depth use of the plot functions
____________________________________________________

--&gt;
&lt;h1 id=&#34;visual-display-of-indices&#34;&gt;Visual Display of Indices&lt;/h1&gt;
&lt;p&gt;In order to display the indices, it is required to retain the spatial location of the sites through the analysis.  This can be done by amending the code used previously to calculate  WQI for 2012.  We will take a short cut this time and use the fact that &lt;code&gt;calc_limits&lt;/code&gt; standardizes and cleans the data before calculating limits.  One way to keep the latitude and longitude information is to add it to the &lt;code&gt;by&lt;/code&gt; argument.  Because each &lt;code&gt;siteID&lt;/code&gt; always has the same latitude and longitude, the effect of this will be to have additional columns in the output from &lt;code&gt;calc_limits&lt;/code&gt;.  We can also turn off messages about variable name substitution if desired&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;options(wqbc.messages = FALSE)
data2012 &amp;lt;- subset(fraser, year(Date) == 2012)
data2012 &amp;lt;- calc_limits(data2012, by = c(&amp;quot;SiteID&amp;quot;, &amp;quot;Lat&amp;quot;, &amp;quot;Long&amp;quot;), term = &amp;quot;short&amp;quot;) 
head(data2012)
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;#&amp;gt;       SiteID     Lat      Long       Date         Variable   Value
#&amp;gt; 1 BC08KA0007 52.9878 -119.0101 2012-01-24     Cobalt Total 0.20000
#&amp;gt; 2 BC08KA0007 52.9878 -119.0101 2012-01-24     Copper Total 0.45000
#&amp;gt; 3 BC08KA0007 52.9878 -119.0101 2012-01-24       Iron Total 0.03030
#&amp;gt; 4 BC08KA0007 52.9878 -119.0101 2012-01-24             Lead 0.01000
#&amp;gt; 5 BC08KA0007 52.9878 -119.0101 2012-01-24        Manganese 0.01120
#&amp;gt; 6 BC08KA0007 52.9878 -119.0101 2012-01-24 Molybdenum Total 0.00007
#&amp;gt;   UpperLimit Units
#&amp;gt; 1 110.000000  ug/L
#&amp;gt; 2   9.491800  ug/L
#&amp;gt; 3   1.000000  mg/L
#&amp;gt; 4  61.162679  ug/L
#&amp;gt; 5   1.418294  mg/L
#&amp;gt; 6   2.000000  mg/L
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now when the water quality index is calculated, we have to pass the additional columns again to retain latitude and longitude in the output from &lt;code&gt;calc_wqi&lt;/code&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;wqi2012 &amp;lt;- calc_wqi(data2012, by = c(&amp;quot;SiteID&amp;quot;, &amp;quot;Lat&amp;quot;, &amp;quot;Long&amp;quot;)) 
wqi2012
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;#&amp;gt;        SiteID      Lat      Long   WQI Lower Upper  Category Variables
#&amp;gt; 1  BC08KA0007 52.98780 -119.0101 100.0 100.0 100.0 Excellent         8
#&amp;gt; 2  BC08KE0010 53.92722 -122.7650  92.7  92.3 100.0      Good         8
#&amp;gt; 3  BC08KH0012 52.40330 -121.4342  89.5  85.5 100.0      Good        11
#&amp;gt; 4  BC08LC0005 50.68484 -119.0700  93.6  93.5 100.0      Good         9
#&amp;gt; 5  BC08LE0004 50.69139 -119.3289  86.8  85.8  93.5      Good         9
#&amp;gt; 6  BC08LF0001 50.42083 -121.3414  85.5  85.2 100.0      Good         8
#&amp;gt; 7  BC08LG0001 50.42500 -121.3164  85.2  83.8 100.0      Good         8
#&amp;gt; 8  BC08MB0007 52.07197 -123.2614  85.0  83.5  92.6      Good         8
#&amp;gt; 9  BC08MC0001 52.52964 -122.4423  73.1  68.7  83.0      Fair         8
#&amp;gt; 10 BC08MF0001 49.38722 -121.4508  82.8  80.3  84.7      Good         8
#&amp;gt; 11 BC08MH0269 49.24211 -122.5961 100.0 100.0 100.0 Excellent        10
#&amp;gt; 12 BC08MH0453 49.16700 -123.0350  83.2  81.1  89.4      Good        11
#&amp;gt;    Tests   F1   F2   F3
#&amp;gt; 1    160  0.0  0.0  0.0
#&amp;gt; 2    184 12.5  1.1  1.4
#&amp;gt; 3    195 18.2  1.0  0.7
#&amp;gt; 4    226 11.1  0.4  0.0
#&amp;gt; 5    204 22.2  3.4  4.0
#&amp;gt; 6    200 25.0  2.0  1.4
#&amp;gt; 7     96 25.0  3.1  4.3
#&amp;gt; 8    144 25.0  5.6  4.8
#&amp;gt; 9    208 37.5 12.0 24.8
#&amp;gt; 10   216 25.0  9.3 13.4
#&amp;gt; 11   212  0.0  0.0  0.0
#&amp;gt; 12   140 27.3  7.9  6.8
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Since this data now has the coordinates of each site, we can plot the index on a map using the function used at the start of the [Water quality index calculation] section.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;plot_map(wqi2012, fill = &amp;quot;WQI&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;















&lt;figure  &gt;
  &lt;div class=&#34;d-flex justify-content-center&#34;&gt;
    &lt;div class=&#34;w-100&#34; &gt;&lt;img src=&#34;/post/wqbc-vignette/figures/unnamed-chunk-28-1.png&#34; alt=&#34;&#34; loading=&#34;lazy&#34; data-zoomable /&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p&gt;However, there is a special plotting function designed especially for plotting the results of &lt;code&gt;calc_wqi&lt;/code&gt;, and this is &lt;code&gt;plot_map_wqis&lt;/code&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;plot_map_wqis(wqi2012)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;















&lt;figure  &gt;
  &lt;div class=&#34;d-flex justify-content-center&#34;&gt;
    &lt;div class=&#34;w-100&#34; &gt;&lt;img src=&#34;/post/wqbc-vignette/figures/unnamed-chunk-29-1.png&#34; alt=&#34;&#34; loading=&#34;lazy&#34; data-zoomable /&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;!--
____________________________________________________

     Pull in analysis tools from other wq packages
____________________________________________________

--&gt;
&lt;h1 id=&#34;additional-examples&#34;&gt;Additional Examples&lt;/h1&gt;
&lt;!-- 
* Show grouping sites together and plotting
* Facet wrap results of yearly short-term WQIs by site 
* trend analysis using wq package
--&gt;
&lt;!-- ____________________________________________________ --&gt;
&lt;h2 id=&#34;an-example-calculating-water-quality-indices-for-grouped-sites&#34;&gt;An example calculating water quality indices for grouped sites&lt;/h2&gt;
&lt;p&gt;This first example shows how it is possible to create a group of sites, in this case it is based on latitude, the group &lt;code&gt;South&lt;/code&gt; is below 52 degrees latitude, while the sites above this line are in the &lt;code&gt;North&lt;/code&gt; group.  Short term water quality indices for 2012 are calculated for these groups using the following&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;options(wqbc.messages = FALSE)
dataNorthSouth &amp;lt;- subset(fraser, year(Date) %in% 2012)
dataNorthSouth $ NorthSouth &amp;lt;- ifelse(dataNorthSouth $ Lat &amp;lt; 52, &amp;quot;South&amp;quot;, &amp;quot;North&amp;quot;)
limitsNorthSouth &amp;lt;- calc_limits(dataNorthSouth, by = &amp;quot;NorthSouth&amp;quot;, term = &amp;quot;short&amp;quot;) 
wqiNorthSouth &amp;lt;- calc_wqi(limitsNorthSouth, by = &amp;quot;NorthSouth&amp;quot;) 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then to attribute these grouped water quality indices back to the individual sites, a basic R function called &lt;code&gt;merge&lt;/code&gt; is used, which merges based on column names.  An additional trick is used here where the function &lt;code&gt;unique&lt;/code&gt; keeps only the unique combinations of &lt;code&gt;NorthSouth&lt;/code&gt;, &lt;code&gt;SiteID&lt;/code&gt;, &lt;code&gt;Lat&lt;/code&gt; and &lt;code&gt;Long&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;wqiNorthSouth &amp;lt;- merge(unique(dataNorthSouth[c(&amp;quot;NorthSouth&amp;quot;, &amp;quot;SiteID&amp;quot;, &amp;quot;Lat&amp;quot;, &amp;quot;Long&amp;quot;)]), wqiNorthSouth)
wqiNorthSouth
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;#&amp;gt;    NorthSouth     SiteID      Lat      Long  WQI Lower Upper Category
#&amp;gt; 1       North BC08MB0007 52.07197 -123.2614 83.5  77.2  89.3     Good
#&amp;gt; 2       North BC08KH0012 52.40330 -121.4342 83.5  77.2  89.3     Good
#&amp;gt; 3       North BC08KE0010 53.92722 -122.7650 83.5  77.2  89.3     Good
#&amp;gt; 4       North BC08MC0001 52.52964 -122.4423 83.5  77.2  89.3     Good
#&amp;gt; 5       North BC08KA0007 52.98780 -119.0101 83.5  77.2  89.3     Good
#&amp;gt; 6       South BC08MH0453 49.16700 -123.0350 85.1  84.7  90.0     Good
#&amp;gt; 7       South BC08MF0001 49.38722 -121.4508 85.1  84.7  90.0     Good
#&amp;gt; 8       South BC08LG0001 50.42500 -121.3164 85.1  84.7  90.0     Good
#&amp;gt; 9       South BC08MH0269 49.24211 -122.5961 85.1  84.7  90.0     Good
#&amp;gt; 10      South BC08LE0004 50.69139 -119.3289 85.1  84.7  90.0     Good
#&amp;gt; 11      South BC08LC0005 50.68484 -119.0700 85.1  84.7  90.0     Good
#&amp;gt; 12      South BC08LF0001 50.42083 -121.3414 85.1  84.7  90.0     Good
#&amp;gt;    Variables Tests   F1  F2  F3
#&amp;gt; 1         11   683 27.3 4.0 7.4
#&amp;gt; 2         11   683 27.3 4.0 7.4
#&amp;gt; 3         11   683 27.3 4.0 7.4
#&amp;gt; 4         11   683 27.3 4.0 7.4
#&amp;gt; 5         11   683 27.3 4.0 7.4
#&amp;gt; 6         12   921 25.0 4.1 4.7
#&amp;gt; 7         12   921 25.0 4.1 4.7
#&amp;gt; 8         12   921 25.0 4.1 4.7
#&amp;gt; 9         12   921 25.0 4.1 4.7
#&amp;gt; 10        12   921 25.0 4.1 4.7
#&amp;gt; 11        12   921 25.0 4.1 4.7
#&amp;gt; 12        12   921 25.0 4.1 4.7
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;plot_map(wqiNorthSouth, fill = &amp;quot;WQI&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;















&lt;figure  &gt;
  &lt;div class=&#34;d-flex justify-content-center&#34;&gt;
    &lt;div class=&#34;w-100&#34; &gt;&lt;img src=&#34;/post/wqbc-vignette/figures/unnamed-chunk-31-1.png&#34; alt=&#34;&#34; loading=&#34;lazy&#34; data-zoomable /&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p&gt;Sites could be grouped based on other attributes if these were available, such as altitude for example.&lt;/p&gt;
&lt;!-- ____________________________________________________ --&gt;
&lt;h2 id=&#34;an-example-over-multiple-years&#34;&gt;An example over multiple years&lt;/h2&gt;
&lt;p&gt;This example calculates short term water quality indices over multiple years (in this case from 2002 to 2012), and by site.  The function &lt;code&gt;facet_wrap&lt;/code&gt; is then used to produce a gridded plot output showing multiple years&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;options(wqbc.messages = TRUE)
data07to12 &amp;lt;- subset(fraser, year(Date) %in% 2007:2012)
data07to12 $ year &amp;lt;- year(data07to12 $ Date)
limits07to12 &amp;lt;- calc_limits(data07to12, by = c(&amp;quot;year&amp;quot;, &amp;quot;SiteID&amp;quot;, &amp;quot;Lat&amp;quot;, &amp;quot;Long&amp;quot;), term = &amp;quot;short&amp;quot;) 
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;#&amp;gt; Standardizing water quality data...
#&amp;gt; Deleted 253 rows with negative values in Value.
#&amp;gt; Substituted &#39;ALUMINUM DISSOLVED&#39; with &#39;Aluminium Dissolved&#39;, &#39;ARSENIC TOTAL&#39; with &#39;Arsenic Total&#39;, &#39;BORON DISSOLVED&#39; with &#39;Boron&#39;, &#39;BORON EXTRACTABLE&#39; with &#39;Boron&#39;, &#39;BORON TOTAL&#39; with &#39;Boron&#39;, &#39;CADMIUM DISSOLVED&#39; with &#39;Cadmium Dissolved&#39;, &#39;COBALT TOTAL&#39; with &#39;Cobalt Total&#39;, &#39;COPPER TOTAL&#39; with &#39;Copper Total&#39;, &#39;CYANIDE WEAK ACID DISSOCIABLE&#39; with &#39;Cyanide Weak Acid Dissociable&#39;, &#39;HARDNESS TOTAL (CALCD.) CACO3&#39; with &#39;Hardness Total&#39;, &#39;IRON DISSOLVED&#39; with &#39;Iron Dissolved&#39;, &#39;IRON TOTAL&#39; with &#39;Iron Total&#39;, &#39;LEAD DISSOLVED&#39; with &#39;Lead&#39;, &#39;LEAD EXTRACTABLE&#39; with &#39;Lead&#39;, &#39;LEAD TOTAL&#39; with &#39;Lead&#39;, &#39;MANGANESE DISSOLVED&#39; with &#39;Manganese&#39;, &#39;MANGANESE EXTRACTABLE&#39; with &#39;Manganese&#39;, &#39;MANGANESE TOTAL&#39; with &#39;Manganese&#39;, &#39;MOLYBDENUM TOTAL&#39; with &#39;Molybdenum Total&#39;, &#39;NITROGEN NITRITE&#39; with &#39;Nitrite&#39;, &#39;PH&#39; with &#39;pH&#39;, &#39;PH - FIELD&#39; with &#39;pH&#39;, &#39;SELENIUM TOTAL&#39; with &#39;Selenium Total&#39;, &#39;SILVER DISSOLVED&#39; with &#39;Silver&#39;, &#39;SILVER EXTRACTABLE&#39; with &#39;Silver&#39;, &#39;SILVER TOTAL&#39; with &#39;Silver&#39;, &#39;SULPHATE DISSOLVED&#39; with &#39;Sulphate&#39; and &#39;ZINC TOTAL&#39; with &#39;Zinc Total&#39;.
#&amp;gt; Failed to substitute &#39;ADSORBABLE ORGANIC HALIDE - AOX&#39;, &#39;ALKALINITY GRAN CACO3&#39;, &#39;ALKALINITY PHENOLPHTHALEIN CACO3&#39;, &#39;ALKALINITY TOTAL CACO3&#39;, &#39;ALUMINUM EXTRACTABLE&#39;, &#39;ALUMINUM TOTAL&#39;, &#39;ALUMINUM_27 TOTAL RECOVERABLE - AL&#39;, &#39;AMMONIA DISSOLVED&#39;, &#39;ANTIMONY DISSOLVED&#39;, &#39;ANTIMONY EXTRACTABLE&#39;, &#39;ANTIMONY TOTAL&#39;, &#39;ARSENIC DISSOLVED&#39;, &#39;ARSENIC EXTRACTABLE&#39;, &#39;BARIUM DISSOLVED&#39;, &#39;BARIUM EXTRACTABLE&#39;, &#39;BARIUM TOTAL&#39;, &#39;BERYLLIUM DISSOLVED&#39;, &#39;BERYLLIUM EXTRACTABLE&#39;, &#39;BERYLLIUM TOTAL&#39;, &#39;BICARBONATE (CALCD.)&#39;, &#39;BISMUTH DISSOLVED&#39;, &#39;BISMUTH EXTRACTABLE&#39;, &#39;BISMUTH TOTAL&#39;, &#39;BROMIDE DISSOLVED&#39;, &#39;CADMIUM EXTRACTABLE&#39;, &#39;CADMIUM TOTAL&#39;, &#39;CALCIUM DISSOLVED&#39;, &#39;CALCIUM EXTRACTABLE&#39;, &#39;CALCIUM TOTAL&#39;, &#39;CARBON DISSOLVED INORGANIC&#39;, &#39;CARBON DISSOLVED ORGANIC&#39;, &#39;CARBON TOTAL INORGANIC&#39;, &#39;CARBON TOTAL ORGANIC&#39;, &#39;CARBONATE (CALCD.)&#39;, &#39;CERIUM DISSOLVED&#39;, &#39;CERIUM EXTRACTABLE&#39;, &#39;CERIUM TOTAL&#39;, &#39;CESIUM DISSOLVED&#39;, &#39;CESIUM EXTRACTABLE&#39;, &#39;CESIUM TOTAL&#39;, &#39;CHLORIDE DISSOLVED&#39;, &#39;CHROMIUM DISSOLVED&#39;, &#39;CHROMIUM EXTRACTABLE&#39;, &#39;CHROMIUM TOTAL&#39;, &#39;COBALT DISSOLVED&#39;, &#39;COBALT EXTRACTABLE&#39;, &#39;COLIFORMS FECAL&#39;, &#39;COLOUR APPARENT&#39;, &#39;COLOUR TRUE&#39;, &#39;COPPER DISSOLVED&#39;, &#39;COPPER EXTRACTABLE&#39;, &#39;CYANIDE TOTAL&#39;, &#39;ENTEROCOCUS&#39;, &#39;ESCHERICHIA COLI&#39;, &#39;FLUORIDE DISSOLVED&#39;, &#39;GALLIUM DISSOLVED&#39;, &#39;GALLIUM EXTRACTABLE&#39;, &#39;GALLIUM TOTAL&#39;, &#39;HYDROXIDE (CALCD.)&#39;, &#39;IRON EXTRACTABLE&#39;, &#39;LANTHANUM DISSOLVED&#39;, &#39;LANTHANUM EXTRACTABLE&#39;, &#39;LANTHANUM TOTAL&#39;, &#39;LITHIUM DISSOLVED&#39;, &#39;LITHIUM EXTRACTABLE&#39;, &#39;LITHIUM TOTAL&#39;, &#39;MAGNESIUM DISSOLVED&#39;, &#39;MAGNESIUM EXTRACTABLE&#39;, &#39;MAGNESIUM TOTAL&#39;, &#39;MERCURY DISSOLVED&#39;, &#39;MOLYBDENUM DISSOLVED&#39;, &#39;MOLYBDENUM EXTRACTABLE&#39;, &#39;NICKEL DISSOLVED&#39;, &#39;NICKEL EXTRACTABLE&#39;, &#39;NICKEL TOTAL&#39;, &#39;NIOBIUM DISSOLVED&#39;, &#39;NIOBIUM EXTRACTABLE&#39;, &#39;NIOBIUM TOTAL&#39;, &#39;NITROGEN DISSOLVED KJELDAHL&#39;, &#39;NITROGEN DISSOLVED NITRATE&#39;, &#39;NITROGEN DISSOLVED NO3 &amp;amp; NO2&#39;, &#39;NITROGEN DISSOLVED ORGANIC (CALCD.)&#39;, &#39;NITROGEN TOTAL&#39;, &#39;NITROGEN TOTAL DISSOLVED&#39;, &#39;NITROGEN TOTAL KJELDAHL&#39;, &#39;NITROGEN TOTAL ORGANIC (CALCD.)&#39;, &#39;OXYGEN DISSOLVED&#39;, &#39;PHOSPHORUS DISSOLVED ORTHO&#39;, &#39;PHOSPHORUS TOTAL&#39;, &#39;PHOSPHORUS TOTAL DISSOLVED&#39;, &#39;PLATINUM DISSOLVED&#39;, &#39;PLATINUM EXTRACTABLE&#39;, &#39;PLATINUM TOTAL&#39;, &#39;POTASSIUM DISSOLVED&#39;, &#39;POTASSIUM EXTRACTABLE&#39;, &#39;POTASSIUM TOTAL&#39;, &#39;RESIDUE FILTERABLE&#39;, &#39;RESIDUE NONFILTRABLE&#39;, &#39;RESIDUE TOTAL&#39;, &#39;RUBIDIUM DISSOLVED&#39;, &#39;RUBIDIUM EXTRACTABLE&#39;, &#39;RUBIDIUM TOTAL&#39;, &#39;SALINITY&#39;, &#39;SELENIUM DISSOLVED&#39;, &#39;SELENIUM EXTRACTABLE&#39;, &#39;SILICON DISSOLVED&#39;, &#39;SILICON EXTRACTABLE&#39;, &#39;SILICON TOTAL&#39;, &#39;SODIUM DISSOLVED&#39;, &#39;SODIUM EXTRACTABLE&#39;, &#39;SODIUM TOTAL&#39;, &#39;SPECIFIC CONDUCTANCE&#39;, &#39;SPECIFIC CONDUCTANCE - FIELD&#39;, &#39;STRONTIUM DISSOLVED&#39;, &#39;STRONTIUM EXTRACTABLE&#39;, &#39;STRONTIUM TOTAL&#39;, &#39;SULPHUR DISSOLVED&#39;, &#39;SULPHUR TOTAL&#39;, &#39;TEMPERATURE AIR&#39;, &#39;TEMPERATURE WATER&#39;, &#39;THALLIUM DISSOLVED&#39;, &#39;THALLIUM EXTRACTABLE&#39;, &#39;THALLIUM TOTAL&#39;, &#39;TIN DISSOLVED&#39;, &#39;TIN EXTRACTABLE&#39;, &#39;TIN TOTAL&#39;, &#39;TITANIUM DISSOLVED&#39;, &#39;TITANIUM TOTAL&#39;, &#39;TUNGSTEN DISSOLVED&#39;, &#39;TUNGSTEN EXTRACTABLE&#39;, &#39;TUNGSTEN TOTAL&#39;, &#39;TURBIDITY&#39;, &#39;URANIUM DISSOLVED&#39;, &#39;URANIUM EXTRACTABLE&#39;, &#39;URANIUM TOTAL&#39;, &#39;VANADIUM DISSOLVED&#39;, &#39;VANADIUM EXTRACTABLE&#39;, &#39;VANADIUM TOTAL&#39;, &#39;YTTRIUM DISSOLVED&#39;, &#39;YTTRIUM EXTRACTABLE&#39;, &#39;YTTRIUM TOTAL&#39;, &#39;ZINC DISSOLVED&#39;, &#39;ZINC EXTRACTABLE&#39;, &#39;ZIRCONIUM DISSOLVED&#39; and &#39;ZIRCONIUM TOTAL&#39;.
#&amp;gt; Deleted 70652 rows with missing values in Variable.
#&amp;gt; Substituted &#39;MG/L&#39; with &#39;mg/L&#39;, &#39;PH UNITS&#39; with &#39;pH&#39; and &#39;UG/L&#39; with &#39;ug/L&#39;.
#&amp;gt; Standardized water quality data.
#&amp;gt; Cleaning water quality data...
#&amp;gt; Filtered 1 of 3 replicate values with a CV of 1.4 for Boron on 2010-03-16.
#&amp;gt; Filtered 1 of 3 replicate values with a CV of 1.3 for Silver on 2010-03-16.
#&amp;gt; Filtered 1 of 4 replicate values with a CV of 1.99 for Arsenic Total on 2010-08-04.
#&amp;gt; Filtered 1 of 3 replicate values with a CV of 1.72 for Arsenic Total on 2010-11-03.
#&amp;gt; Filtered 1 of 4 replicate values with a CV of 1.96 for Cobalt Total on 2010-08-04.
#&amp;gt; Filtered 1 of 3 replicate values with a CV of 1.71 for Cobalt Total on 2010-11-03.
#&amp;gt; Filtered 1 of 4 replicate values with a CV of 1.89 for Copper Total on 2010-08-04.
#&amp;gt; Filtered 1 of 3 replicate values with a CV of 1.65 for Copper Total on 2010-11-03.
#&amp;gt; Filtered 1 of 4 replicate values with a CV of 2 for Lead on 2010-08-04.
#&amp;gt; Filtered 2 of 5 replicate values with a CV of 1.38 for Lead on 2010-11-03.
#&amp;gt; Filtered 1 of 4 replicate values with a CV of 1.81 for Molybdenum Total on 2010-08-04.
#&amp;gt; Filtered 1 of 3 replicate values with a CV of 1.68 for Molybdenum Total on 2010-11-03.
#&amp;gt; Filtered 1 of 4 replicate values with a CV of 1.99 for Selenium Total on 2010-08-04.
#&amp;gt; Filtered 1 of 3 replicate values with a CV of 1.72 for Selenium Total on 2010-11-03.
#&amp;gt; Filtered 1 of 4 replicate values with a CV of 1.99 for Silver on 2010-08-04.
#&amp;gt; Filtered 2 of 5 replicate values with a CV of 1.36 for Silver on 2010-11-03.
#&amp;gt; Filtered 1 of 4 replicate values with a CV of 1.86 for Zinc Total on 2010-08-04.
#&amp;gt; Filtered 1 of 3 replicate values with a CV of 1.54 for Zinc Total on 2010-11-03.
#&amp;gt; Filtered 1 of 3 replicate values with a CV of 1.72 for Arsenic Total on 2011-03-09.
#&amp;gt; Filtered 2 of 5 replicate values with a CV of 1.36 for Arsenic Total on 2011-06-01.
#&amp;gt; Filtered 1 of 3 replicate values with a CV of 1.71 for Cobalt Total on 2011-03-09.
#&amp;gt; Filtered 2 of 5 replicate values with a CV of 1.36 for Cobalt Total on 2011-06-01.
#&amp;gt; Filtered 1 of 3 replicate values with a CV of 1.66 for Copper Total on 2011-03-09.
#&amp;gt; Filtered 2 of 5 replicate values with a CV of 1.32 for Copper Total on 2011-06-01.
#&amp;gt; Filtered 2 of 5 replicate values with a CV of 1.38 for Lead on 2011-03-09.
#&amp;gt; Filtered 1 of 3 replicate values with a CV of 1.65 for Molybdenum Total on 2011-03-09.
#&amp;gt; Filtered 2 of 5 replicate values with a CV of 1.34 for Molybdenum Total on 2011-06-01.
#&amp;gt; Filtered 1 of 3 replicate values with a CV of 1.72 for Selenium Total on 2011-03-09.
#&amp;gt; Filtered 2 of 5 replicate values with a CV of 1.36 for Selenium Total on 2011-06-01.
#&amp;gt; Filtered 2 of 5 replicate values with a CV of 1.36 for Silver on 2011-03-09.
#&amp;gt; Cleansed water quality data.
#&amp;gt; Calculating short-term water quality limits...
#&amp;gt; Calculated short-term water quality limits.
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;wqi07to12 &amp;lt;- calc_wqi(limits07to12, by = c(&amp;quot;year&amp;quot;, &amp;quot;SiteID&amp;quot;, &amp;quot;Lat&amp;quot;, &amp;quot;Long&amp;quot;)) 
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;#&amp;gt; Calculating water quality indices...
#&amp;gt; Added missing column LowerLimit to x.
#&amp;gt; Added missing column DetectionLimit to x.
#&amp;gt; Dropped WQI with less than four variables sampled at least four times by year: 2009, SiteID: 3, Lat: 53.02955 and Long: -119.23201.
#&amp;gt; Calculated water quality indices.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To visualize the water quality indices over the years, a handy function from the &lt;code&gt;ggplot2&lt;/code&gt; package called &lt;code&gt;facet_wrap&lt;/code&gt; can be used.  This is because the plotting functions return a ggplot2 object which can be replotted and adapted - see the &lt;a href=&#34;https://ggplot2.tidyverse.org&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;ggplot2 webpage&lt;/a&gt; for lots of helpful ideas on how to add to and customize these type of plots.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;p &amp;lt;- plot_map_wqis(wqi07to12, keep = &amp;quot;year&amp;quot;) 
p + facet_wrap(~year)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;















&lt;figure  &gt;
  &lt;div class=&#34;d-flex justify-content-center&#34;&gt;
    &lt;div class=&#34;w-100&#34; &gt;&lt;img src=&#34;/post/wqbc-vignette/figures/unnamed-chunk-33-1.png&#34; alt=&#34;&#34; loading=&#34;lazy&#34; data-zoomable /&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;!-- ____________________________________________________ --&gt;
&lt;h2 id=&#34;the-ccme-example-data-demonstration&#34;&gt;the CCME example data demonstration&lt;/h2&gt;
&lt;p&gt;The following example is taken from the demonstration of the &lt;code&gt;ccme&lt;/code&gt; dataset.  This can be run in your R session by typing &lt;code&gt;demo(ccme)&lt;/code&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;library(tidyr)
library(dplyr)

options(wqbc.messages = TRUE)

data(ccme)

spread(select(ccme, Variable, Value, Date), Variable, Value)
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;#&amp;gt;          Date   DO  pH    TP    TN FC    As     Pb Hg 2,4-D Lindane
#&amp;gt; 1  1997-01-07 11.4 8.0 0.006 0.160  4 2e-04 0.0004  0 0.000       0
#&amp;gt; 2  1997-02-04 11.0 7.9 0.005 0.170  0 0e+00 0.0094  0    NA      NA
#&amp;gt; 3  1997-03-04 11.5 7.9 0.006 0.132  4 0e+00 0.0000  0    NA      NA
#&amp;gt; 4  1997-04-08 12.5 7.9 0.058 0.428  0 0e+00 0.0008  0 0.004       0
#&amp;gt; 5  1997-05-06 10.4 8.1 0.042 0.250  0 2e-04 0.0008  0    NA      NA
#&amp;gt; 6  1997-06-03  8.9 8.2 0.108 0.707 26 6e-04 0.0013  0    NA      NA
#&amp;gt; 7  1997-07-08  8.5 8.3 0.017 0.153  9 2e-04 0.0004 NA    NA      NA
#&amp;gt; 8  1997-08-05  7.5 8.2 0.008 0.153  8 0e+00 0.0000  0 0.000       0
#&amp;gt; 9  1997-09-02  9.2 8.2 0.006 0.130 12 3e-04 0.0018  0    NA      NA
#&amp;gt; 10 1997-10-07 11.0 8.1 0.008 0.093 12 0e+00 0.0011  0 0.000       0
#&amp;gt; 11 1997-11-04 12.1 8.0 0.006 0.296  8 0e+00 0.0051  0    NA      NA
#&amp;gt; 12 1997-12-01 13.3 8.0 0.004 0.054  4 0e+00 0.0000  0    NA      NA
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;calc_wqi(ccme)
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;#&amp;gt; Calculating water quality indices...
#&amp;gt; Deleted 17 rows with missing or negative values in Value.
#&amp;gt; Replaced 31 of the values in column Value with the detection limit in column DetectionLimit.
#&amp;gt; Calculated water quality indices.
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;#&amp;gt;      WQI Lower Upper Category Variables Tests F1  F2  F3
#&amp;gt; WQI 88.1  87.3  94.2     Good        10   103 20 3.9 2.8
&lt;/code&gt;&lt;/pre&gt;
&lt;!-- ____________________________________________________ --&gt;
&lt;h2 id=&#34;the-fraser-river-basin-data-demonstration&#34;&gt;the Fraser river basin data demonstration&lt;/h2&gt;
&lt;p&gt;The following example is taken from the demonstration of the &lt;code&gt;fraser&lt;/code&gt; dataset.  This can be run in your R session by typing &lt;code&gt;demo(fraser)&lt;/code&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-r&#34;&gt;library(dplyr)
library(lubridate)
library(ggplot2)
library(sp)
library(rgdal)

options(wqbc.messages = TRUE)

data(fraser)
print(summary(fraser))

fraser$SiteID &amp;lt;-  factor(sub(&amp;quot;BC08&amp;quot;, &amp;quot;&amp;quot;, as.character(fraser$SiteID)))
fraser$Year &amp;lt;- year(fraser$Date)
plot_map(fraser, fill = &amp;quot;SiteID&amp;quot;)
fraser &amp;lt;- calc_wqi(fraser, by = c(&amp;quot;SiteID&amp;quot;, &amp;quot;Lat&amp;quot;, &amp;quot;Long&amp;quot;))
plot_map_wqis(fraser, shape = &amp;quot;SiteID&amp;quot;)

data(fraser)
fraser$Year &amp;lt;- year(fraser$Date)
fraser &amp;lt;- standardize_wqdata(fraser, strict = FALSE)
fraser &amp;lt;- clean_wqdata(fraser, by = &amp;quot;Year&amp;quot;, max_cv = Inf)
fraser &amp;lt;- calc_limits(fraser, by = &amp;quot;Year&amp;quot;, term = &amp;quot;short&amp;quot;)
fraser &amp;lt;- calc_wqi(fraser, by = &amp;quot;Year&amp;quot;)
plot_wqis(fraser, x = &amp;quot;Year&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;h1 id=&#34;references&#34;&gt;References&lt;/h1&gt;
</description>
    </item>
    
  </channel>
</rss>
