<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>Posts on Thomas Roh</title>
        <link>https://roh.engineering/posts/</link>
        <description>Recent content in Posts on Thomas Roh</description>
        <generator>Hugo -- gohugo.io</generator>
        <language>en-us</language>
        <copyright>&lt;a href=&#34;https://creativecommons.org/licenses/by-nc/4.0/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;CC BY-NC 4.0&lt;/a&gt;</copyright>
        <lastBuildDate>Sun, 31 Jul 2022 00:00:00 +0000</lastBuildDate>
        <atom:link href="https://roh.engineering/posts/index.xml" rel="self" type="application/rss+xml" />
        
        <item>
            <title>leaflegend Recipes</title>
            <link>https://roh.engineering/posts/2022/07/leaflegend-recipes/</link>
            <pubDate>Sun, 31 Jul 2022 00:00:00 +0000</pubDate>
            
            <guid>https://roh.engineering/posts/2022/07/leaflegend-recipes/</guid>
            <description><![CDATA[<ul>
<li><a href="#color-scales" id="toc-color-scales">Color Scales</a>
<ul>
<li><a href="#create-legend-for-a-continuous-scale" id="toc-create-legend-for-a-continuous-scale">Create Legend for a Continuous Scale</a></li>
<li><a href="#create-legend-for-quantiles" id="toc-create-legend-for-quantiles">Create Legend for Quantiles</a></li>
<li><a href="#create-legend-for-bins-and-change-legend-symbol" id="toc-create-legend-for-bins-and-change-legend-symbol">Create Legend for Bins and Change Legend Symbol</a></li>
<li><a href="#create-legend-for-factors-and-re-order" id="toc-create-legend-for-factors-and-re-order">Create Legend for Factors and Re-order</a></li>
</ul>
</li>
<li><a href="#symbols-and-size-scales" id="toc-symbols-and-size-scales">Symbols and Size Scales</a>
<ul>
<li><a href="#legend-and-points-with-size-encoding" id="toc-legend-and-points-with-size-encoding">Legend and Points with Size Encoding</a></li>
<li><a href="#legend-and-points-with-double-encoding" id="toc-legend-and-points-with-double-encoding">Legend and Points with Double Encoding</a></li>
<li><a href="#legend-and-points-with-size-and-color-encoding" id="toc-legend-and-points-with-size-and-color-encoding">Legend and Points with Size and Color Encoding</a></li>
<li><a href="#legend-and-points-with-symbol-encoding" id="toc-legend-and-points-with-symbol-encoding">Legend and Points with Symbol Encoding</a></li>
<li><a href="#legend-and-points-with-symbol-encoding-non-defaults" id="toc-legend-and-points-with-symbol-encoding-non-defaults">Legend and Points with Symbol Encoding (Non-Defaults)</a></li>
<li><a href="#legend-for-line-size-encodings" id="toc-legend-for-line-size-encodings">Legend for Line Size Encodings</a></li>
</ul>
</li>
<li><a href="#images" id="toc-images">Images</a>
<ul>
<li><a href="#add-custom-images-to-a-legend" id="toc-add-custom-images-to-a-legend">Add Custom Images to a Legend</a></li>
<li><a href="#generate-map-symbols" id="toc-generate-map-symbols">Generate Map Symbols</a></li>
<li><a href="#add-awesome-marker-legend-and-specify-icon-as-text" id="toc-add-awesome-marker-legend-and-specify-icon-as-text">Add Awesome Marker Legend and Specify Icon as Text</a></li>
</ul>
</li>
<li><a href="#customization" id="toc-customization">Customization</a>
<ul>
<li><a href="#turn-off-legend-background" id="toc-turn-off-legend-background">Turn off Legend Background</a></li>
<li><a href="#add-titles-with-styling" id="toc-add-titles-with-styling">Add Titles with Styling</a></li>
<li><a href="#change-label-styling" id="toc-change-label-styling">Change Label Styling</a></li>
<li><a href="#symbol-styling" id="toc-symbol-styling">Symbol Styling</a></li>
<li><a href="#make-symbol-icons" id="toc-make-symbol-icons">Make Symbol Icons</a></li>
<li><a href="#make-symbols-with-size-encodings" id="toc-make-symbols-with-size-encodings">Make Symbols with Size Encodings</a></li>
<li><a href="#legends-with-overlay-controls" id="toc-legends-with-overlay-controls">Legends with Overlay Controls</a></li>
</ul>
</li>
</ul>
<p><em>Requires leaflegend &gt;= 1.0.0</em></p>
<h4 id="base-data-and-map">Base Data and Map</h4>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">library</span>(leaflet)
<span style="color:#a6e22e">library</span>(leaflegend)
mapData <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">data.frame</span>(x <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#ae81ff">2</span>, <span style="color:#ae81ff">1</span>, <span style="color:#ae81ff">5</span>, <span style="color:#ae81ff">4</span>,<span style="color:#ae81ff">3</span>) , y <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#e6db74">&#39;A&#39;</span>, <span style="color:#e6db74">&#39;B&#39;</span>, <span style="color:#e6db74">&#39;C&#39;</span>, <span style="color:#e6db74">&#39;B&#39;</span>, <span style="color:#e6db74">&#39;A&#39;</span>), 
                      lng <span style="color:#f92672">=</span> <span style="color:#f92672">-</span>(<span style="color:#ae81ff">118</span><span style="color:#f92672">:</span><span style="color:#ae81ff">122</span>), lat <span style="color:#f92672">=</span> <span style="color:#a6e22e">rep</span>(<span style="color:#ae81ff">42</span>, <span style="color:#ae81ff">5</span>))
map <span style="color:#f92672">&lt;-</span> leaflet<span style="color:#f92672">::</span><span style="color:#a6e22e">leaflet</span>(data <span style="color:#f92672">=</span> mapData, 
                        options <span style="color:#f92672">=</span> <span style="color:#a6e22e">leafletOptions</span>(zoomControl <span style="color:#f92672">=</span> <span style="color:#66d9ef">FALSE</span>))
</code></pre></div><h2 id="color-scales">Color Scales</h2>
<h3 id="create-legend-for-a-continuous-scale">Create Legend for a Continuous Scale</h3>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">numPal <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">colorNumeric</span>(<span style="color:#e6db74">&#39;inferno&#39;</span>, mapData<span style="color:#f92672">$</span>x)
lgd <span style="color:#f92672">&lt;-</span> 
  map <span style="color:#f92672">|&gt;</span> <span style="color:#a6e22e">addLegendNumeric</span>(pal <span style="color:#f92672">=</span> numPal, values <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>x, decreasing <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>) <span style="color:#f92672">|&gt;</span> 
  <span style="color:#a6e22e">addLegendNumeric</span>(pal <span style="color:#f92672">=</span> numPal, values <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>x, orientation <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;horizontal&#39;</span>,
                   width <span style="color:#f92672">=</span> <span style="color:#ae81ff">120</span>, height <span style="color:#f92672">=</span> <span style="color:#ae81ff">20</span>, position <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;topright&#39;</span>)
lgd
</code></pre></div><p><img src="img/figure-001.png" alt=""></p>
<h3 id="create-legend-for-quantiles">Create Legend for Quantiles</h3>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">quantPal <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">colorQuantile</span>(<span style="color:#e6db74">&#39;Reds&#39;</span>, mapData<span style="color:#f92672">$</span>x, n <span style="color:#f92672">=</span> <span style="color:#ae81ff">3</span>)
lgd <span style="color:#f92672">&lt;-</span> 
  map <span style="color:#f92672">|&gt;</span> <span style="color:#a6e22e">addLegendQuantile</span>(pal <span style="color:#f92672">=</span> quantPal, values <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>x) <span style="color:#f92672">|&gt;</span> 
    <span style="color:#a6e22e">addLegendQuantile</span>(pal <span style="color:#f92672">=</span> quantPal, values <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>x, numberFormat <span style="color:#f92672">=</span> <span style="color:#66d9ef">NULL</span>, 
                      position <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;topright&#39;</span>)
lgd
</code></pre></div><p><img src="img/figure-002.png" alt=""></p>
<h3 id="create-legend-for-bins-and-change-legend-symbol">Create Legend for Bins and Change Legend Symbol</h3>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">binPal <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">colorBin</span>(<span style="color:#a6e22e">c</span>(<span style="color:#e6db74">&#39;grey&#39;</span>, <span style="color:#e6db74">&#39;blue&#39;</span>), mapData<span style="color:#f92672">$</span>x, bins <span style="color:#f92672">=</span> <span style="color:#ae81ff">3</span>, pretty <span style="color:#f92672">=</span> <span style="color:#66d9ef">FALSE</span>)
lgd <span style="color:#f92672">&lt;-</span> 
  map <span style="color:#f92672">|&gt;</span> <span style="color:#a6e22e">addLegendBin</span>(pal <span style="color:#f92672">=</span> binPal, shape <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;triangle&#39;</span>)
lgd
</code></pre></div><p><img src="img/figure-003.png" alt=""></p>
<h3 id="create-legend-for-factors-and-re-order">Create Legend for Factors and Re-order</h3>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">factorPal <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">colorFactor</span>(<span style="color:#e6db74">&#39;Dark2&#39;</span>, domain <span style="color:#f92672">=</span> mapData<span style="color:#f92672">$</span>y)
reOrder <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">c</span>(<span style="color:#e6db74">&#39;C&#39;</span>, <span style="color:#e6db74">&#39;A&#39;</span>, <span style="color:#e6db74">&#39;B&#39;</span>)
factorPalRev <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">colorFactor</span>(<span style="color:#e6db74">&#39;Dark2&#39;</span>, domain <span style="color:#f92672">=</span> reOrder, ordered <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>)
lgd <span style="color:#f92672">&lt;-</span> 
  map <span style="color:#f92672">|&gt;</span> <span style="color:#a6e22e">addLegendFactor</span>(pal <span style="color:#f92672">=</span> factorPal, values <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>y) <span style="color:#f92672">|&gt;</span> 
    <span style="color:#a6e22e">addLegendFactor</span>(pal <span style="color:#f92672">=</span> factorPalRev, 
                    values <span style="color:#f92672">=</span> <span style="color:#f92672">~</span><span style="color:#a6e22e">factor</span>(y, levels <span style="color:#f92672">=</span> reOrder), 
                    position <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;topright&#39;</span>)
lgd
</code></pre></div><p><img src="img/figure-004.png" alt=""></p>
<h2 id="symbols-and-size-scales">Symbols and Size Scales</h2>
<h3 id="legend-and-points-with-size-encoding">Legend and Points with Size Encoding</h3>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">lgd <span style="color:#f92672">&lt;-</span> 
  map <span style="color:#f92672">|&gt;</span> <span style="color:#a6e22e">addLegendSize</span>(values <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>x, color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;black&#39;</span>, shape  <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;plus&#39;</span>, 
                       breaks <span style="color:#f92672">=</span> <span style="color:#ae81ff">3</span>) <span style="color:#f92672">|&gt;</span> 
    <span style="color:#a6e22e">addSymbolsSize</span>(lng <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>lng, lat <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>lat, values <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>x, shape <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;plus&#39;</span>, 
                   color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;black&#39;</span>)
lgd
</code></pre></div><p><img src="img/figure-005.png" alt=""></p>
<h3 id="legend-and-points-with-double-encoding">Legend and Points with Double Encoding</h3>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">lgd <span style="color:#f92672">&lt;-</span> 
  map <span style="color:#f92672">|&gt;</span> <span style="color:#a6e22e">addLegendSize</span>(values <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>x, shape  <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;plus&#39;</span>, breaks <span style="color:#f92672">=</span> <span style="color:#ae81ff">3</span>, pal <span style="color:#f92672">=</span> numPal,
                       color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;black&#39;</span>) <span style="color:#f92672">|&gt;</span> 
    <span style="color:#a6e22e">addSymbolsSize</span>(lng <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>lng, lat <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>lat, values <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>x, shape <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;plus&#39;</span>, 
                   color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;black&#39;</span>, fillColor <span style="color:#f92672">=</span> <span style="color:#f92672">~</span><span style="color:#a6e22e">numPal</span>(x))
lgd
</code></pre></div><p><img src="img/figure-006.png" alt=""></p>
<h3 id="legend-and-points-with-size-and-color-encoding">Legend and Points with Size and Color Encoding</h3>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">lgd <span style="color:#f92672">&lt;-</span> 
  map <span style="color:#f92672">|&gt;</span> <span style="color:#a6e22e">addLegendSize</span>(values <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>x, shape  <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;plus&#39;</span>, breaks <span style="color:#f92672">=</span> <span style="color:#ae81ff">3</span>, pal <span style="color:#f92672">=</span> numPal,
                       color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;black&#39;</span>, fillColor <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;transparent&#39;</span>) <span style="color:#f92672">|&gt;</span> 
    <span style="color:#a6e22e">addSymbolsSize</span>(lng <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>lng, lat <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>lat, values <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>x, shape <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;plus&#39;</span>, 
                   color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;black&#39;</span>, fillColor <span style="color:#f92672">=</span> <span style="color:#f92672">~</span><span style="color:#a6e22e">factorPal</span>(y)) <span style="color:#f92672">|&gt;</span> 
    <span style="color:#a6e22e">addLegendFactor</span>(pal <span style="color:#f92672">=</span> factorPal, values <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>y, position <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;topright&#39;</span>)
lgd
</code></pre></div><p><img src="img/figure-007.png" alt=""></p>
<h3 id="legend-and-points-with-symbol-encoding">Legend and Points with Symbol Encoding</h3>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">lgd <span style="color:#f92672">&lt;-</span> 
  map <span style="color:#f92672">|&gt;</span> <span style="color:#a6e22e">addSymbols</span>(lng <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>lng, lat <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>lat, values <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>y, color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;black&#39;</span>) <span style="color:#f92672">|&gt;</span> 
    <span style="color:#a6e22e">addLegendSymbol</span>(values <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>y, color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;black&#39;</span>)
lgd
</code></pre></div><p><img src="img/figure-008.png" alt=""></p>
<h3 id="legend-and-points-with-symbol-encoding-non-defaults">Legend and Points with Symbol Encoding (Non-Defaults)</h3>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">lgd <span style="color:#f92672">&lt;-</span> 
  map <span style="color:#f92672">|&gt;</span> <span style="color:#a6e22e">addSymbols</span>(lng <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>lng, lat <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>lat, values <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>y, 
                    fillColor <span style="color:#f92672">=</span> <span style="color:#f92672">~</span><span style="color:#a6e22e">factorPal</span>(y), color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;black&#39;</span>,
                    shape <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#e6db74">&#39;cross&#39;</span>, <span style="color:#e6db74">&#39;diamond&#39;</span>, <span style="color:#e6db74">&#39;star&#39;</span>)) <span style="color:#f92672">|&gt;</span> 
    <span style="color:#a6e22e">addLegendSymbol</span>(values <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>y, pal <span style="color:#f92672">=</span> factorPal, 
                    shape <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#e6db74">&#39;cross&#39;</span>, <span style="color:#e6db74">&#39;diamond&#39;</span>, <span style="color:#e6db74">&#39;star&#39;</span>), color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;black&#39;</span>)
lgd
</code></pre></div><p><img src="img/figure-009.png" alt=""></p>
<h3 id="legend-for-line-size-encodings">Legend for Line Size Encodings</h3>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">lgd <span style="color:#f92672">&lt;-</span> 
  map <span style="color:#f92672">|&gt;</span> <span style="color:#a6e22e">addLegendLine</span>(values <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>x, color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;black&#39;</span>, 
                       orientation <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;horizontal&#39;</span>, width <span style="color:#f92672">=</span> <span style="color:#ae81ff">50</span>)
lgd
</code></pre></div><p><img src="img/figure-010.png" alt=""></p>
<h2 id="images">Images</h2>
<h3 id="add-custom-images-to-a-legend">Add Custom Images to a Legend</h3>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#75715e"># use raster image</span>
leafImg <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">system.file</span>(<span style="color:#e6db74">&#39;img/leaf-blue.png&#39;</span>, package <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;leaflegend&#39;</span>)
<span style="color:#75715e"># use svg</span>
circle <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">makeSymbol</span>(<span style="color:#e6db74">&#39;rect&#39;</span>, fillColor <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;red&#39;</span>, color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;black&#39;</span>, width <span style="color:#f92672">=</span> <span style="color:#ae81ff">20</span>)
lgd <span style="color:#f92672">&lt;-</span> 
  map <span style="color:#f92672">|&gt;</span> 
    <span style="color:#a6e22e">addLegendImage</span>(images <span style="color:#f92672">=</span> <span style="color:#a6e22e">list</span>(leafImg, circle), labels <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#e6db74">&#39;png&#39;</span>, <span style="color:#e6db74">&#39;svg&#39;</span>),
                   height <span style="color:#f92672">=</span> <span style="color:#ae81ff">30</span>, width <span style="color:#f92672">=</span> <span style="color:#ae81ff">20</span>)
lgd
</code></pre></div><p><img src="img/figure-011.png" alt=""></p>
<h3 id="generate-map-symbols">Generate Map Symbols</h3>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">shapes <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">c</span>(<span style="color:#e6db74">&#39;rect&#39;</span>, <span style="color:#e6db74">&#39;circle&#39;</span>, <span style="color:#e6db74">&#39;triangle&#39;</span>, <span style="color:#e6db74">&#39;plus&#39;</span>, <span style="color:#e6db74">&#39;cross&#39;</span>, <span style="color:#e6db74">&#39;star&#39;</span>)
colors <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">c</span>(<span style="color:#e6db74">&#39;blue&#39;</span>, <span style="color:#e6db74">&#39;red&#39;</span>, <span style="color:#e6db74">&#39;yellow&#39;</span>, <span style="color:#e6db74">&#39;green&#39;</span>, <span style="color:#e6db74">&#39;orange&#39;</span>, <span style="color:#e6db74">&#39;purple&#39;</span>)
symbols <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">Map</span>(f <span style="color:#f92672">=</span> makeSymbol, shape <span style="color:#f92672">=</span> shapes, fillColor <span style="color:#f92672">=</span> colors, 
               color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;black&#39;</span>, opacity <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>, fillOpacity <span style="color:#f92672">=</span> <span style="color:#ae81ff">.5</span>, width <span style="color:#f92672">=</span> <span style="color:#ae81ff">20</span>, 
               `stroke-width` <span style="color:#f92672">=</span> <span style="color:#ae81ff">2</span>)
lgd <span style="color:#f92672">&lt;-</span> 
  map <span style="color:#f92672">|&gt;</span> <span style="color:#a6e22e">addLegendImage</span>(images <span style="color:#f92672">=</span> symbols, labels <span style="color:#f92672">=</span> shapes, 
                        orientation <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;horizontal&#39;</span>)
lgd
</code></pre></div><p><img src="img/figure-012.png" alt=""></p>
<h3 id="add-awesome-marker-legend-and-specify-icon-as-text">Add Awesome Marker Legend and Specify Icon as Text</h3>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">iconSet <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">awesomeIconList</span>(
  `Font Awesome` <span style="color:#f92672">=</span> <span style="color:#a6e22e">makeAwesomeIcon</span>(icon <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;font-awesome&#34;</span>, library <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;fa&#34;</span>,
                                   markerColor<span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;red&#39;</span>, iconColor <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;black&#39;</span>),
  Ionic <span style="color:#f92672">=</span> <span style="color:#a6e22e">makeAwesomeIcon</span>(icon<span style="color:#f92672">=</span><span style="color:#e6db74">&#39;R&#39;</span>, library <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;fa&#39;</span>, 
                          text <span style="color:#f92672">=</span> fontawesome<span style="color:#f92672">::</span><span style="color:#a6e22e">fa</span>(<span style="color:#e6db74">&#34;r-project&#34;</span>))
)
lgd <span style="color:#f92672">&lt;-</span> 
  map <span style="color:#f92672">|&gt;</span> <span style="color:#a6e22e">addLegendAwesomeIcon</span>(iconSet <span style="color:#f92672">=</span> iconSet)
lgd
</code></pre></div><p><img src="img/figure-013.png" alt=""></p>
<h2 id="customization">Customization</h2>
<h3 id="turn-off-legend-background">Turn off Legend Background</h3>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">lgd <span style="color:#f92672">&lt;-</span> 
  map <span style="color:#f92672">|&gt;</span> <span style="color:#a6e22e">addLegendFactor</span>(values <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>y, pal <span style="color:#f92672">=</span> factorPal, 
                         class <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;leaflet-control&#39;</span>, 
                         labelStyle <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;color: black;&#39;</span>)
lgd
</code></pre></div><p><img src="img/figure-014.png" alt=""></p>
<h3 id="add-titles-with-styling">Add Titles with Styling</h3>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">lgd <span style="color:#f92672">&lt;-</span> 
  map <span style="color:#f92672">|&gt;</span> <span style="color:#a6e22e">addLegendFactor</span>(values <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>y, pal <span style="color:#f92672">=</span> factorPal, 
                         title <span style="color:#f92672">=</span> htmltools<span style="color:#f92672">::</span>tags<span style="color:#f92672">$</span><span style="color:#a6e22e">div</span>(<span style="color:#e6db74">&#39;Red Title&#39;</span>, 
                                                     style <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;color:red;&#39;</span>))
lgd
</code></pre></div><p><img src="img/figure-015.png" alt=""></p>
<h3 id="change-label-styling">Change Label Styling</h3>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">lgd <span style="color:#f92672">&lt;-</span> 
  map <span style="color:#f92672">|&gt;</span> <span style="color:#a6e22e">addLegendFactor</span>(values <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>y, pal <span style="color:#f92672">=</span> factorPal, 
                         labelStyle <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;color: blue; font-size: 10px;&#39;</span>)
lgd
</code></pre></div><p><img src="img/figure-016.png" alt=""></p>
<h3 id="symbol-styling">Symbol Styling</h3>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">lgd <span style="color:#f92672">&lt;-</span> 
  map <span style="color:#f92672">|&gt;</span> <span style="color:#a6e22e">addLegendFactor</span>(values <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>y, pal <span style="color:#f92672">=</span> factorPal, shape <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;polygon&#39;</span>,
                         fillOpacity <span style="color:#f92672">=</span> <span style="color:#ae81ff">.5</span>, width <span style="color:#f92672">=</span> <span style="color:#ae81ff">20</span>, height <span style="color:#f92672">=</span> <span style="color:#ae81ff">20</span>)
lgd
</code></pre></div><p><img src="img/figure-017.png" alt=""></p>
<h3 id="make-symbol-icons">Make Symbol Icons</h3>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">symbolSet <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">makeSymbolIcons</span>(shape <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#e6db74">&#39;rect&#39;</span>, <span style="color:#e6db74">&#39;circle&#39;</span>, <span style="color:#e6db74">&#39;triangle&#39;</span>), 
                             width <span style="color:#f92672">=</span> <span style="color:#ae81ff">10</span>, color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;grey&#39;</span>, opacity <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>)
lgd <span style="color:#f92672">&lt;-</span> 
  map <span style="color:#f92672">|&gt;</span> <span style="color:#a6e22e">addMarkers</span>(lng <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>lng, lat <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>lat, icon <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>symbolSet<span style="color:#a6e22e">[as.factor</span>(y)])
lgd
</code></pre></div><p><img src="img/figure-018.png" alt=""></p>
<h3 id="make-symbols-with-size-encodings">Make Symbols with Size Encodings</h3>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">lgd <span style="color:#f92672">&lt;-</span> 
  map <span style="color:#f92672">|&gt;</span> <span style="color:#a6e22e">addMarkers</span>(lng <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>lng, lat <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>lat, 
                    icon <span style="color:#f92672">=</span> <span style="color:#f92672">~</span><span style="color:#a6e22e">makeSymbolsSize</span>(x, color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;black&#39;</span>, 
                                            fillColor <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;black&#39;</span>,
                                            baseSize <span style="color:#f92672">=</span> <span style="color:#ae81ff">20</span>, 
                                            fillOpacity <span style="color:#f92672">=</span> <span style="color:#ae81ff">.5</span>))
lgd
</code></pre></div><p><img src="img/figure-019.png" alt=""></p>
<h3 id="legends-with-overlay-controls">Legends with Overlay Controls</h3>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">lgd <span style="color:#f92672">&lt;-</span> 
  map <span style="color:#f92672">|&gt;</span> <span style="color:#a6e22e">addLegendFactor</span>(values <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>y, pal <span style="color:#f92672">=</span> factorPal, group <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;Legend&#39;</span>) <span style="color:#f92672">|&gt;</span> 
    <span style="color:#a6e22e">addLayersControl</span>(overlayGroups <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;Legend&#39;</span>, 
                     options <span style="color:#f92672">=</span> <span style="color:#a6e22e">layersControlOptions</span>(collapsed <span style="color:#f92672">=</span> <span style="color:#66d9ef">FALSE</span>))
lgd
</code></pre></div><p><img src="img/figure-020.png" alt=""></p>
<p>[<a href="https://cran.r-project.org/web/packages/leaflegend/index.html">CRAN</a>]
[<a href="https://github.com/tomroh/leaflegend">github</a>]</p>
]]></description>
        </item>
        
        <item>
            <title>Awesome Marker Legends in Leaflet</title>
            <link>https://roh.engineering/posts/2021/10/awesome-marker-legends-in-leaflet/</link>
            <pubDate>Fri, 29 Oct 2021 00:00:00 +0000</pubDate>
            
            <guid>https://roh.engineering/posts/2021/10/awesome-marker-legends-in-leaflet/</guid>
            <description><![CDATA[<p>The <a href="https://github.com/lennardv2/Leaflet.awesome-markers">awesome-markers</a> plugin that ships with the <code>leaflet</code> package provides a great way to add iconography to points on a map. Three different icon libraries are supported, you have the ability to change to a few different options for the marker colors:</p>
<p><img src="/img/markers-plain.png" alt=""></p>
<p>, and can specify the icon color (it&rsquo;s a font!) with any
specification that is supported in HTML/CSS. While many of the icons can be self-explanatory, best practice is to always provide a legend for encodings whether it is a map or a plot. Creating an awesome marker legend is possible
using only <code>leaflet</code> but requires the user to write some HTML and CSS to put into the <code>addControl</code> function. <code>leaflegend</code> provides a new function <code>addLegendAwesomeIcon</code> that automates this task and preserves all the same features of the markers that are drawn on a map.</p>
<h1 id="creating-an-awesome-marker-legend">Creating an Awesome Marker Legend</h1>
<p>To create awesome icons for the map and the legend, use the same method as in
the example documentation from <code>leaflet</code> and create an icon set. All of the
options provided in <code>makeAwesomeIcon</code> will render in the legend. You only need to pass the icon set into the <code>addLegendAwesomeIcon</code> function with a named
icon list that will be the labels for the icon markers. As with the other
<code>addLegend*()</code> functions in <code>leaflegend</code>, the user has full control over the title, label style, etc. Grouping controls are now supported for all legends as of version 0.4.0.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">library</span>(leaflet)
<span style="color:#a6e22e">library</span>(leaflegend)
<span style="color:#a6e22e">library</span>(sf)
<span style="color:#a6e22e">library</span>(osmdata)

foodDrink <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">opq</span>(bbox<span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#ae81ff">-122.367375</span>,
                         <span style="color:#ae81ff">47.643819</span>,
                         <span style="color:#ae81ff">-122.323258</span>,
                         <span style="color:#ae81ff">47.658698</span>)) <span style="color:#f92672">|&gt;</span>
  <span style="color:#a6e22e">add_osm_feature</span>(key <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;amenity&#39;</span>, 
                  value <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#e6db74">&#39;restaurant&#39;</span>, <span style="color:#e6db74">&#39;pub&#39;</span>, <span style="color:#e6db74">&#39;cafe&#39;</span>)) <span style="color:#f92672">|&gt;</span>
  <span style="color:#a6e22e">osmdata_sf</span>() <span style="color:#f92672">|&gt;</span>
  <span style="color:#a6e22e">getElement</span>(<span style="color:#e6db74">&#39;osm_points&#39;</span>)
foodDrink <span style="color:#f92672">&lt;-</span> foodDrink[<span style="color:#f92672">!</span><span style="color:#a6e22e">is.na</span>(foodDrink<span style="color:#f92672">$</span>amenity), ]
iconSet <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">awesomeIconList</span>(
  pub <span style="color:#f92672">=</span> <span style="color:#a6e22e">makeAwesomeIcon</span>(
    icon <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;beer&#39;</span>,
    library <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;fa&#39;</span>,
    iconColor <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;gold&#39;</span>,
    markerColor <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;red&#39;</span>,
    iconRotate <span style="color:#f92672">=</span> <span style="color:#ae81ff">10</span>
  ),
  cafe <span style="color:#f92672">=</span> <span style="color:#a6e22e">makeAwesomeIcon</span>(
    icon <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;coffee&#39;</span>,
    library <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;ion&#39;</span>,
    iconColor <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;#000000&#39;</span>,
    markerColor <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;blue&#39;</span>,
    squareMarker <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>
  ),
  restaurant <span style="color:#f92672">=</span> <span style="color:#a6e22e">makeAwesomeIcon</span>(
    icon <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;cutlery&#39;</span>,
    library <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;glyphicon&#39;</span>,
    iconColor <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;rgb(192, 255, 0)&#39;</span>,
    markerColor <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;darkpurple&#39;</span>,
    spin <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>,
    squareMarker <span style="color:#f92672">=</span> <span style="color:#66d9ef">FALSE</span>
  )
)
<span style="color:#a6e22e">leaflet</span>(foodDrink) <span style="color:#f92672">|&gt;</span>
  <span style="color:#a6e22e">addTiles</span>() <span style="color:#f92672">|&gt;</span>
  <span style="color:#a6e22e">addAwesomeMarkers</span>(icon <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>iconSet[amenity],
                    group <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>amenity) <span style="color:#f92672">|&gt;</span>
  <span style="color:#a6e22e">addLegendAwesomeIcon</span>(iconSet <span style="color:#f92672">=</span> iconSet,
                       orientation <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;horizontal&#39;</span>,
                       title <span style="color:#f92672">=</span> htmltools<span style="color:#f92672">::</span>tags<span style="color:#f92672">$</span><span style="color:#a6e22e">div</span>(
                         style <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;font-size: 20px;&#39;</span>,
                         <span style="color:#e6db74">&#39;Horizontal Legend&#39;</span>),
                       labelStyle <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;font-size: 16px;&#39;</span>,
                       position <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;bottomright&#39;</span>,
                       group <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;Horizontal Legend&#39;</span>) <span style="color:#f92672">|&gt;</span>
  <span style="color:#a6e22e">addLegendAwesomeIcon</span>(iconSet <span style="color:#f92672">=</span> iconSet,
                       orientation <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;vertical&#39;</span>,
                       marker <span style="color:#f92672">=</span> <span style="color:#66d9ef">FALSE</span>,
                       title <span style="color:#f92672">=</span> htmltools<span style="color:#f92672">::</span>tags<span style="color:#f92672">$</span><span style="color:#a6e22e">div</span>(
                         style <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;font-size: 20px;&#39;</span>,
                         <span style="color:#e6db74">&#39;Vertical Legend&#39;</span>),
                       labelStyle <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;font-size: 16px;&#39;</span>,
                       position <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;bottomright&#39;</span>,
                       group <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;Vertical Legend&#39;</span>) <span style="color:#f92672">|&gt;</span>
  <span style="color:#a6e22e">addLayersControl</span>(baseGroups <span style="color:#f92672">=</span> <span style="color:#a6e22e">sprintf</span>(<span style="color:#e6db74">&#39;%s Legend&#39;</span>, 
                                        <span style="color:#a6e22e">c</span>(<span style="color:#e6db74">&#39;Horizontal&#39;</span>, <span style="color:#e6db74">&#39;Vertical&#39;</span>)),
                   overlayGroups <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#e6db74">&#39;pub&#39;</span>, <span style="color:#e6db74">&#39;cafe&#39;</span>, <span style="color:#e6db74">&#39;restaurant&#39;</span>),
                   options <span style="color:#f92672">=</span> <span style="color:#a6e22e">layersControlOptions</span>(collapsed <span style="color:#f92672">=</span> <span style="color:#66d9ef">FALSE</span>))
</code></pre></div><p><img src="/img/awesome-legend-loop.gif" alt=""></p>
<p>[<a href="https://cran.r-project.org/web/packages/leaflegend/index.html">CRAN</a>]
[<a href="https://github.com/tomroh/leaflegend">github</a>]</p>
]]></description>
        </item>
        
        <item>
            <title>Fast SQL Server Imports with R</title>
            <link>https://roh.engineering/posts/2021/08/fast-sql-server-imports-with-r/</link>
            <pubDate>Mon, 09 Aug 2021 00:00:00 +0000</pubDate>
            
            <guid>https://roh.engineering/posts/2021/08/fast-sql-server-imports-with-r/</guid>
            <description><![CDATA[<p>Writing large datasets to SQL Server can be very slow using the DBI package
with an odbc connection. The issue with writing data is that individual
INSERT statements are generated for each row of data. I&rsquo;ve also
had issues with remote connections that can make large writes to SQL Server take a very long time. SQL Server Management Studio does provide a GUI interface to import data that is much more efficient. For those that want to include the data import
in their reproducible R workflows there are a couple of options.</p>
<h2 id="bulk-insert-statements">BULK INSERT statements</h2>
<p>The fastest method is to use BULK INSERT statements with the data written to a file on the machine where the SQL Server resides. This requires that you
have access/permissions to transfer the file to the remote host&rsquo;s local
filesystem and the server can access that location.</p>
<p>We can make use of the <code>DBI::sqlCreateTable</code> to generate the table schema
and make some edits to it (optional) and then create the table for import.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">library</span>(DBI)
<span style="color:#a6e22e">library</span>(data.table)
<span style="color:#a6e22e">library</span>(nycflights13)
<span style="color:#a6e22e">data</span>(<span style="color:#e6db74">&#34;flights&#34;</span>)
<span style="color:#a6e22e">set.seed</span>(<span style="color:#ae81ff">88</span>)
con <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">ANSI</span>()
flights <span style="color:#f92672">&lt;-</span> flights<span style="color:#a6e22e">[sample.int</span>(<span style="color:#a6e22e">nrow</span>(flights), <span style="color:#ae81ff">1000000</span>, replace <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>),]
<span style="color:#a6e22e">fwrite</span>(<span style="color:#e6db74">&#39;flights.csv&#39;</span>)
<span style="color:#75715e"># Take a guess at the table schema and write it</span>
<span style="color:#a6e22e">dbCreateTable</span>(conn <span style="color:#f92672">=</span> con, name <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;dbo.TableName&#39;</span>, fields <span style="color:#f92672">=</span> flights)c
</code></pre></div><p>A handy trick for generating code that you can edit for the schema and submit
with <code>dbExecute</code> is</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">writeClipboard</span>(<span style="color:#a6e22e">sqlCreateTable</span>(con <span style="color:#f92672">=</span> con, table <span style="color:#f92672">=</span> <span style="color:#a6e22e">SQL</span>(<span style="color:#e6db74">&#39;dbo.TableName&#39;</span>), 
               fields <span style="color:#f92672">=</span> flights, row.names <span style="color:#f92672">=</span> <span style="color:#66d9ef">FALSE</span>))
</code></pre></div><p>For this example, the file is written to a temporary file with field separators and line endings that match the defaults for BULK INSERT. The order of the data columns
in the file needs to match the order of columns in the table created.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#75715e"># Create a temporary file</span>
folder <span style="color:#f92672">&lt;-</span> <span style="color:#e6db74">&#39;//server/folder&#39;</span>
tmp <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">tempfile</span>(tmpdir <span style="color:#f92672">=</span> folder, fileext <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;.txt&#39;</span>)
<span style="color:#75715e"># Headers are not accepted and BULK INSERT assumes you have the data columns</span>
<span style="color:#75715e"># in the same order as the table columns</span>
<span style="color:#a6e22e">fwrite</span>(flights, tmp, sep <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;\t&#39;</span>, col.names <span style="color:#f92672">=</span> <span style="color:#66d9ef">FALSE</span>)
<span style="color:#75715e"># Execute Bulk Insert on the MS SQL Server</span>
<span style="color:#a6e22e">dbExecute</span>(con,
          <span style="color:#a6e22e">sqlInterpolate</span>(con,
                         <span style="color:#e6db74">&#34;
</span><span style="color:#e6db74">  BULK INSERT dbo.TableName
</span><span style="color:#e6db74">  FROM ?tmp
</span><span style="color:#e6db74">  WITH
</span><span style="color:#e6db74">  (
</span><span style="color:#e6db74">    FIELDTERMINATOR =&#39;\t&#39;
</span><span style="color:#e6db74">    , ROWTERMINATOR = &#39;\n&#39;
</span><span style="color:#e6db74">  )&#34;</span>, tmp <span style="color:#f92672">=</span> tmp)
)
</code></pre></div><h2 id="bcp-utility">bcp Utility</h2>
<p>If you are not able to write the file to a location that the SQL Server
instance can access with the BULK INSERT statement, you can use the bulk copy
program utility (bcp). bcp does not require knowledge of T-SQL and offers a
few more options to control the import process.</p>
<p>The full documentation is provided here:
<a href="https://docs.microsoft.com/en-us/sql/tools/bcp-utility">bcp Utility</a>.</p>
<p>bcp will need to be installed on your local machine and added to the system
path. Using that same temp file and schema that was generated earlier, you can invoke bcp CLI with:</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">system2</span>(<span style="color:#e6db74">&#39;bcp&#39;</span>, args <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#e6db74">&#39;schema.TableName&#39;</span>,
                        <span style="color:#e6db74">&#39;in&#39;</span>, tmp,
                        <span style="color:#e6db74">&#39;-S&#39;</span>, <span style="color:#e6db74">&#39;server&#39;</span>,
                        <span style="color:#e6db74">&#39;-d&#39;</span>, <span style="color:#e6db74">&#39;database&#39;</span>,
                        <span style="color:#e6db74">&#39;-t&#39;</span>,
                        <span style="color:#e6db74">&#39;-r&#39;</span>, <span style="color:#e6db74">&#39;\n&#39;</span>,
                        <span style="color:#e6db74">&#39;-c&#39;</span>,
                        <span style="color:#e6db74">&#39;-T&#39;</span>))
</code></pre></div><p>The documentation for the arguments can be found in the aformentioned documentation. This example uses trusted authentication, &lsquo;\t&rsquo; as the column/field separators and &lsquo;\n&rsquo; as the row/line terminators.</p>
<h2 id="a-hrefhttpsbcputilityrohengineeringbcputilitya"><a href='https://bcputility.roh.engineering'>bcputility</a></h2>
<p>The <code>bcputility</code> provides a wrapper to the bcp command line program that has
some useful argument defaults, and abstracts away the file I/O and
schema creation. We can now have fast writes of large imports with one line
of code.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">library</span>(bcputility)
<span style="color:#a6e22e">bcpImport</span>(flights, server <span style="color:#f92672">=</span> server, database <span style="color:#f92672">=</span> database, table <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;flights1&#39;</span>)
</code></pre></div><p>We can customize how data is passed with the <code>batchsize</code> and <code>packetsize</code>
arguments.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">bcpImport</span>(flights, server <span style="color:#f92672">=</span> server, database <span style="color:#f92672">=</span> database, table <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;flights1&#39;</span>,
          batchsize <span style="color:#f92672">=</span> <span style="color:#ae81ff">50000</span>, packetsize <span style="color:#f92672">=</span> <span style="color:#ae81ff">4096</span><span style="color:#f92672">*</span><span style="color:#ae81ff">2</span>)
</code></pre></div><p>Arguments can be passed to <code>system2</code> with <code>...</code> so we can check the
results of the import process.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">bcpImport</span>(flights, server <span style="color:#f92672">=</span> server, database <span style="color:#f92672">=</span> database, table <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;flights1&#39;</span>,
          batchsize <span style="color:#f92672">=</span> <span style="color:#ae81ff">50000</span>, packetsize <span style="color:#f92672">=</span> <span style="color:#ae81ff">4096</span><span style="color:#f92672">*</span><span style="color:#ae81ff">2</span>, 
          stdout <span style="color:#f92672">=</span> <span style="color:#66d9ef">FALSE</span>, <span style="color:#75715e"># suppress printing to console</span>
          stderr <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;import-flights-error.txt&#39;</span> <span style="color:#75715e"># write errors to file</span>
          )
</code></pre></div><p>If you need to change the default terminators, because the data includes tabs or newlines:</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">bcpImport</span>(flights, server <span style="color:#f92672">=</span> server, database <span style="color:#f92672">=</span> database, table <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;flights1&#39;</span>,
          batchsize <span style="color:#f92672">=</span> <span style="color:#ae81ff">50000</span>, packetsize <span style="color:#f92672">=</span> <span style="color:#ae81ff">4096</span><span style="color:#f92672">*</span><span style="color:#ae81ff">2</span>, 
          stdout <span style="color:#f92672">=</span> <span style="color:#66d9ef">FALSE</span>, <span style="color:#75715e"># suppress printing to console</span>
          stderr <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;import-flights-error.txt&#39;</span> <span style="color:#75715e"># write errors to file</span>
          fieldterminator <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;|&#39;</span>,
          rowterminator <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;\r\n|\r\n&#39;</span>
          )
</code></pre></div><p>You can switch to sql authentication which you might need if writing to
a database on Azure or trusted connections are not allowed.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">bcpImport</span>(flights, server <span style="color:#f92672">=</span> server, database <span style="color:#f92672">=</span> database, table <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;flights1&#39;</span>,
          batchsize <span style="color:#f92672">=</span> <span style="color:#ae81ff">50000</span>, packetsize <span style="color:#f92672">=</span> <span style="color:#ae81ff">4096</span><span style="color:#f92672">*</span><span style="color:#ae81ff">2</span>, 
          stdout <span style="color:#f92672">=</span> <span style="color:#66d9ef">FALSE</span>, <span style="color:#75715e"># suppress printing to console</span>
          stderr <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;import-flights-error.txt&#39;</span> <span style="color:#75715e"># write errors to file</span>
          fieldterminator <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;|&#39;</span>,
          rowterminator <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;\r\n|\r\n&#39;</span>
          username <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;myname&#39;</span>,
          password <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;mypassword&#39;</span>
          )

</code></pre></div><h2 id="benchmarks">Benchmarks</h2>
<p>Benchmarks were performed with a local installation of SQL Server Express.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">library</span>(DBI)
<span style="color:#a6e22e">library</span>(data.table)
<span style="color:#a6e22e">library</span>(nycflights13)
<span style="color:#a6e22e">data</span>(<span style="color:#e6db74">&#34;flights&#34;</span>)
<span style="color:#a6e22e">set.seed</span>(<span style="color:#ae81ff">82</span>)
flights <span style="color:#f92672">&lt;-</span> flights<span style="color:#a6e22e">[sample.int</span>(<span style="color:#a6e22e">nrow</span>(flights), <span style="color:#ae81ff">1000000</span>, replace <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>),]
server <span style="color:#f92672">&lt;-</span> <span style="color:#e6db74">&#39;localhost\\SQLEXPRESS&#39;</span>
database <span style="color:#f92672">&lt;-</span> <span style="color:#e6db74">&#39;Main&#39;</span>
con <span style="color:#f92672">&lt;-</span> DBI<span style="color:#f92672">::</span><span style="color:#a6e22e">dbConnect</span>(odbc<span style="color:#f92672">::</span><span style="color:#a6e22e">odbc</span>(),
                      Driver <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;SQL Server&#34;</span>,
                      Server <span style="color:#f92672">=</span> server,
                      Database <span style="color:#f92672">=</span> database)
results <span style="color:#f92672">&lt;-</span> microbenchmark<span style="color:#f92672">::</span><span style="color:#a6e22e">microbenchmark</span>(
  bcpImport1000 <span style="color:#f92672">=</span> {
    <span style="color:#a6e22e">bcpImport</span>(flights,
              server <span style="color:#f92672">=</span> server,
              database <span style="color:#f92672">=</span> database,
              table <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;flights1&#39;</span>,
              overwrite <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>,
              stdout <span style="color:#f92672">=</span> <span style="color:#66d9ef">FALSE</span>)
    },
  bcpImport10000 <span style="color:#f92672">=</span> {
    <span style="color:#a6e22e">bcpImport</span>(flights,
              server <span style="color:#f92672">=</span> server,
              database <span style="color:#f92672">=</span> database,
              table <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;flights2&#39;</span>,
              overwrite <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>,
              stdout <span style="color:#f92672">=</span> <span style="color:#66d9ef">FALSE</span>,
              batchsize <span style="color:#f92672">=</span> <span style="color:#ae81ff">10000</span>)
  },
  bcpImport50000 <span style="color:#f92672">=</span> {
    <span style="color:#a6e22e">bcpImport</span>(flights,
              server <span style="color:#f92672">=</span> server,
              database <span style="color:#f92672">=</span> database,
              table <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;flights3&#39;</span>,
              overwrite <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>,
              stdout <span style="color:#f92672">=</span> <span style="color:#66d9ef">FALSE</span>,
              batchsize <span style="color:#f92672">=</span> <span style="color:#ae81ff">50000</span>)
  },
  dbWriteTable <span style="color:#f92672">=</span> {
    DBI<span style="color:#f92672">::</span><span style="color:#a6e22e">dbWriteTable</span>(con, name <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;flights4&#39;</span>, flights, overwrite <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>)
    },
  times <span style="color:#f92672">=</span> <span style="color:#ae81ff">30L</span>
)
</code></pre></div><p><img src="/img/bcpimportbenchmarks.png" alt=""></p>
]]></description>
        </item>
        
        <item>
            <title>Shiny in Production: Database Transactions</title>
            <link>https://roh.engineering/posts/2021/06/shiny-in-production-database-transactions/</link>
            <pubDate>Fri, 11 Jun 2021 00:00:00 +0000</pubDate>
            
            <guid>https://roh.engineering/posts/2021/06/shiny-in-production-database-transactions/</guid>
            <description><![CDATA[<p>An important aspect of maintaining databases with an application interface is to
ensure <em>atomicity</em>. When performing multiple writes on a database, any failures
that occur during the operations should not violate any logical rules.
The most common analogy is a financial transaction.
If person A withdraws X dollars from their account and deposits into the account
of person B then the withdrawal and deposit should occur as a whole <em>transaction</em>.
If only one occurs, you have either created or deleted currency (your government
does not approve of this). The <code>DBI</code> package provides a couple of abstractions to
perform transactions with R and seamlessly implement them into a <code>shiny</code>
application.</p>
<p>The following demonstrates maintaining <em>atomicity</em> through an application
that allows the user to re-allocate resources to 4 containers. Any container can
transfer resources to another container but the amount must be greater than 0
and less than what is currently in the container that is losing resources. The
condition that should always be met is that the sum of the resources should
equal 100. The full application is at the end of the post for reference.</p>
<p><img src="/img/db-transactions-01.png" alt=""></p>
<h2 id="create-a-database">Create a Database</h2>
<p>For the example, a database is created with a table that stores the amount
of resources in each container. The total amount of resources available is
limited to 100 and is pre-populated with initial values. A constraint has been
placed that will be important later on.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">library</span>(DBI)
<span style="color:#a6e22e">library</span>(RSQLite)
con <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">dbConnect</span>(RSQLite<span style="color:#f92672">::</span><span style="color:#a6e22e">SQLite</span>(), <span style="color:#e6db74">&#34;allocations.sqlite&#34;</span>)
<span style="color:#a6e22e">dbExecute</span>(con, 
  <span style="color:#e6db74">&#39;CREATE TABLE Containers (Container int, Amount float, CHECK(Amount &gt;= 0))&#39;</span>
)
<span style="color:#a6e22e">dbExecute</span>(con, <span style="color:#e6db74">&#39;INSERT INTO Containers (Container, Amount) VALUES(1, 10)&#39;</span>)
<span style="color:#a6e22e">dbExecute</span>(con, <span style="color:#e6db74">&#39;INSERT INTO Containers (Container, Amount) VALUES(2, 20)&#39;</span>)
<span style="color:#a6e22e">dbExecute</span>(con, <span style="color:#e6db74">&#39;INSERT INTO Containers (Container, Amount) VALUES(3, 30)&#39;</span>)
<span style="color:#a6e22e">dbExecute</span>(con, <span style="color:#e6db74">&#39;INSERT INTO Containers (Container, Amount) VALUES(4, 40)&#39;</span>)
<span style="color:#a6e22e">dbGetQuery</span>(con, <span style="color:#e6db74">&#39;SELECT Container, Amount FROM Containers&#39;</span>)
</code></pre></div><p><img src="/img/db-transactions-02.png" alt=""></p>
<h2 id="re-allocate-resources-with-independent-sql-statements">Re-allocate Resources with Independent SQL Statements</h2>
<p>The simplest approach is to execute two statements on the table in series. Using
some server-side logic you can control that minimum and maximum amounts
(roll your own logic with if/else statements and <code>showNotification</code> or <code>showModal</code>
or check out <a href="https://rstudio.github.io/shinyvalidate/">shinyvalidate</a>). As
long as both of these statements execute, the application will perform as intended.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">dbExecute</span>(
  con,
  <span style="color:#a6e22e">sqlInterpolate</span>(
    con,
    <span style="color:#e6db74">&#39;UPDATE Containers SET Amount = Amount + ?TransferAmount
</span><span style="color:#e6db74">                                     WHERE Container = ?ToContainer&#39;</span>,
    TransferAmount <span style="color:#f92672">=</span> input<span style="color:#f92672">$</span>Amount,
    ToContainer <span style="color:#f92672">=</span> input<span style="color:#f92672">$</span>To
  )
)
<span style="color:#a6e22e">dbExecute</span>(
  con,
  <span style="color:#a6e22e">sqlInterpolate</span>(
    con,
    <span style="color:#e6db74">&#39;UPDATE Containers SET Amount = Amount - ?TransferAmount
</span><span style="color:#e6db74">                                     WHERE Container = ?FromContainer&#39;</span>,
    TransferAmount <span style="color:#f92672">=</span> input<span style="color:#f92672">$</span>Amount,
    FromContainer <span style="color:#f92672">=</span> input<span style="color:#f92672">$</span>From
  )
)
</code></pre></div><p><img src="/img/db-transactions-03.png" alt=""></p>
<p>Because the database and application interactions are simple, the chance of an
error occuring is relatively small (maybe not that small, network/connectivity
errors are common enough). Depending on the use case, you may want to put
some calculations in between those two statements, create more complicated
database interactions, or execute some side effects. Any additions increase the
risk of failure which can lead to results such as this:</p>
<p><img src="/img/db-transactions-04.png" alt=""></p>
<p>The first statement executed but the second one that would balance the resources
was never run due to an error. There are some ways to handle this on the
database side which would prevent <em>data loss</em> (different topic
and can be extremely complicated). To handle this exception, when one statement
fails all statements should fail. This is the concept of a <em>transaction</em> and can
be handled on the application side in <code>shiny</code>.</p>
<h2 id="re-allocate-resources-with-a-transaction">Re-allocate Resources with a Transaction</h2>
<p>Start a transaction with <code>dbBegin</code> that will wrap the following database
interactions into a single statement. There are three possible outcomes to close
the transaction: <code>dbCommit</code> will make the changes, <code>dbRollback</code> will cancel
any changes, and any closing of the connection will also cancel the changes.
<code>tryCatch</code> is used to handle the errors cleanly (an error will crash the
application) and you can also use the error message to alert the user what went
wrong.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">tryCatch</span>({
  <span style="color:#a6e22e">dbBegin</span>(con)
  <span style="color:#a6e22e">dbExecute</span>(
    con,
    <span style="color:#a6e22e">sqlInterpolate</span>(
      con,
      <span style="color:#e6db74">&#39;UPDATE Containers SET Amount = Amount + ?TransferAmount
</span><span style="color:#e6db74">                                     WHERE Container = ?ToContainer&#39;</span>,
      TransferAmount <span style="color:#f92672">=</span> input<span style="color:#f92672">$</span>Amount,
      ToContainer <span style="color:#f92672">=</span> input<span style="color:#f92672">$</span>To
    )
  )
  <span style="color:#a6e22e">dbExecute</span>(
    con,
    <span style="color:#a6e22e">sqlInterpolate</span>(
      con,
      <span style="color:#e6db74">&#39;UPDATE Containers SET Amount = Amount - ?TransferAmount
</span><span style="color:#e6db74">                                     WHERE Container = ?FromContainer&#39;</span>,
      TransferAmount <span style="color:#f92672">=</span> input<span style="color:#f92672">$</span>Amount,
      FromContainer <span style="color:#f92672">=</span> input<span style="color:#f92672">$</span>From
    )
  )
  <span style="color:#a6e22e">dbCommit</span>(con)
}, error <span style="color:#f92672">=</span> <span style="color:#a6e22e">function</span>(e) {
  <span style="color:#a6e22e">dbRollback</span>(con)
  e
})
</code></pre></div><p><img src="/img/db-transactions-05.png" alt=""></p>
<h2 id="handling-invalid-values">Handling Invalid Values</h2>
<p>Now the user can enter invalid values and we can safely prevent them from
putting the database into an undesirable state. We can rely on the database to
alert the user with the error (that is the <code>CHECK</code> constraint that was
placed during creation of the database). You can also handle the check on the
application side with input validation which works with a single user, but can
trip up concurrent users when transactions happen simultaneously or close enough
together that the client side values in shiny are not up to date&ndash;<em>isolation</em>
is a separate part of <a href="https://en.wikipedia.org/wiki/ACID">ACID</a>.</p>
<h2 id="full-code">Full Code</h2>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">library</span>(shiny)
<span style="color:#a6e22e">library</span>(ggplot2)
<span style="color:#a6e22e">library</span>(DBI)
<span style="color:#a6e22e">library</span>(RSQLite)
make_reactive_trigger <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">function</span>() {
    rv <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">reactiveValues</span>(a <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>)
    <span style="color:#a6e22e">list</span>(
        depend <span style="color:#f92672">=</span> <span style="color:#a6e22e">function</span>() {
            rv<span style="color:#f92672">$</span>a
            <span style="color:#a6e22e">invisible</span>()
        },
        trigger <span style="color:#f92672">=</span> <span style="color:#a6e22e">function</span>() {
            rv<span style="color:#f92672">$</span>a <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">isolate</span>(rv<span style="color:#f92672">$</span>a <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>)
        }
    )
}
DBTrigger <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">make_reactive_trigger</span>()
con <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">dbConnect</span>(RSQLite<span style="color:#f92672">::</span><span style="color:#a6e22e">SQLite</span>(), <span style="color:#e6db74">&#34;allocations.sqlite&#34;</span>)
<span style="color:#a6e22e">dbExecute</span>(con, 
  <span style="color:#e6db74">&#39;CREATE TABLE Containers (Container int, Amount float, CHECK(Amount &gt;= 0))&#39;</span>)
<span style="color:#a6e22e">dbExecute</span>(con, <span style="color:#e6db74">&#39;INSERT INTO Containers (Container, Amount) VALUES(1, 10)&#39;</span>)
<span style="color:#a6e22e">dbExecute</span>(con, <span style="color:#e6db74">&#39;INSERT INTO Containers (Container, Amount) VALUES(2, 20)&#39;</span>)
<span style="color:#a6e22e">dbExecute</span>(con, <span style="color:#e6db74">&#39;INSERT INTO Containers (Container, Amount) VALUES(3, 30)&#39;</span>)
<span style="color:#a6e22e">dbExecute</span>(con, <span style="color:#e6db74">&#39;INSERT INTO Containers (Container, Amount) VALUES(4, 40)&#39;</span>)
initContainers <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">dbGetQuery</span>(con, <span style="color:#e6db74">&#39;SELECT Container, Amount FROM Containers&#39;</span>)

ui <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">fluidPage</span>(

    <span style="color:#a6e22e">sidebarLayout</span>(
        <span style="color:#a6e22e">sidebarPanel</span>(
            tags<span style="color:#f92672">$</span><span style="color:#a6e22e">h5</span>(<span style="color:#e6db74">&#39;Total Resources: 100&#39;</span>),
            <span style="color:#a6e22e">selectInput</span>(<span style="color:#e6db74">&#39;From&#39;</span>, <span style="color:#e6db74">&#39;Transfer from:&#39;</span>, 
                        choices <span style="color:#f92672">=</span> initContainers[[<span style="color:#e6db74">&#39;Container&#39;</span>]]),
            <span style="color:#a6e22e">selectInput</span>(<span style="color:#e6db74">&#39;To&#39;</span>, <span style="color:#e6db74">&#39;Transfer to:&#39;</span>, 
                        choices <span style="color:#f92672">=</span> initContainers[[<span style="color:#e6db74">&#39;Container&#39;</span>]][<span style="color:#ae81ff">-1</span>]),
            <span style="color:#a6e22e">numericInput</span>(<span style="color:#e6db74">&#39;Amount&#39;</span>, <span style="color:#e6db74">&#39;Amount&#39;</span>, min <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>, value <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>, 
                         max <span style="color:#f92672">=</span> initContainers[[<span style="color:#e6db74">&#39;Amount&#39;</span>]][1]),
            <span style="color:#a6e22e">actionButton</span>(<span style="color:#e6db74">&#39;Submit&#39;</span>, <span style="color:#e6db74">&#39;Submit&#39;</span>)
        ),
        <span style="color:#a6e22e">mainPanel</span>(
           <span style="color:#a6e22e">plotOutput</span>(<span style="color:#e6db74">&#34;AllocationPlot&#34;</span>)
        )
    )
)

server <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">function</span>(input, output, session) {
    Allocations <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">reactive</span>({
        DBTrigger<span style="color:#f92672">$</span><span style="color:#a6e22e">depend</span>()
        <span style="color:#a6e22e">dbGetQuery</span>(con, <span style="color:#e6db74">&#39;SELECT Container, Amount FROM Containers&#39;</span>)
    })
    <span style="color:#75715e">#  Transferring to self is redundant</span>
    <span style="color:#a6e22e">observeEvent</span>(input<span style="color:#f92672">$</span>From, {
        <span style="color:#a6e22e">updateSelectInput</span>(
            session, 
            <span style="color:#e6db74">&#39;To&#39;</span>, 
            choices <span style="color:#f92672">=</span> <span style="color:#a6e22e">Allocations</span>()[[<span style="color:#e6db74">&#39;Container&#39;</span>]][
            <span style="color:#f92672">!</span><span style="color:#a6e22e">Allocations</span>()[[<span style="color:#e6db74">&#39;Container&#39;</span>]] <span style="color:#f92672">%in%</span> input<span style="color:#f92672">$</span>From])
    })
    <span style="color:#75715e"># Limit tranfer amount</span>
    <span style="color:#75715e"># this will produce a popup warning but is not currently enforced </span>
    <span style="color:#75715e"># server side</span>
    <span style="color:#75715e"># see shinyvalidate package if using bootstrap3</span>
    <span style="color:#a6e22e">observeEvent</span>(<span style="color:#a6e22e">Allocations</span>(), {
        i <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">Allocations</span>()[[<span style="color:#e6db74">&#39;Container&#39;</span>]] <span style="color:#f92672">==</span> input<span style="color:#f92672">$</span>From
        <span style="color:#a6e22e">updateNumericInput</span>(
            session, <span style="color:#e6db74">&#39;Amount&#39;</span>,
            max <span style="color:#f92672">=</span> <span style="color:#a6e22e">Allocations</span>()[[<span style="color:#e6db74">&#39;Amount&#39;</span>]][i])
    })
    <span style="color:#a6e22e">observeEvent</span>(input<span style="color:#f92672">$</span>Submit, {
        res <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">tryCatch</span>({
            <span style="color:#a6e22e">dbBegin</span>(con)
            <span style="color:#75715e"># disallow using negative values</span>
            <span style="color:#a6e22e">stopifnot</span>(input<span style="color:#f92672">$</span>Amount <span style="color:#f92672">&gt;</span> <span style="color:#ae81ff">0</span>)
            <span style="color:#a6e22e">dbExecute</span>(con,
                      <span style="color:#a6e22e">sqlInterpolate</span>(con,
                                     <span style="color:#e6db74">&#39;UPDATE Containers 
</span><span style="color:#e6db74">                                     SET Amount = Amount + ?TransferAmount
</span><span style="color:#e6db74">                                     WHERE Container = ?ToContainer&#39;</span>,
                                     TransferAmount <span style="color:#f92672">=</span> input<span style="color:#f92672">$</span>Amount,
                                     ToContainer <span style="color:#f92672">=</span> input<span style="color:#f92672">$</span>To)
            )
            <span style="color:#a6e22e">dbExecute</span>(con,
                      <span style="color:#a6e22e">sqlInterpolate</span>(con,
                                     <span style="color:#e6db74">&#39;UPDATE Containers 
</span><span style="color:#e6db74">                                     SET Amount = Amount - ?TransferAmount
</span><span style="color:#e6db74">                                     WHERE Container = ?FromContainer&#39;</span>,
                                     TransferAmount <span style="color:#f92672">=</span> input<span style="color:#f92672">$</span>Amount,
                                     FromContainer <span style="color:#f92672">=</span> input<span style="color:#f92672">$</span>From)
            )
            <span style="color:#a6e22e">dbCommit</span>(con)
        }, error <span style="color:#f92672">=</span> <span style="color:#a6e22e">function</span>(e) {
            <span style="color:#a6e22e">dbRollback</span>(con)
            e
            })
        <span style="color:#a6e22e">if </span>( <span style="color:#a6e22e">inherits</span>(res, <span style="color:#e6db74">&#39;error&#39;</span>) ) {
            <span style="color:#a6e22e">showNotification</span>(res<span style="color:#f92672">$</span>message)
        }
        DBTrigger<span style="color:#f92672">$</span><span style="color:#a6e22e">trigger</span>()
    })
    <span style="color:#75715e"># Show Latest Allocations</span>
    output<span style="color:#f92672">$</span>AllocationPlot <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">renderPlot</span>({
        <span style="color:#a6e22e">ggplot</span>(<span style="color:#a6e22e">Allocations</span>()) <span style="color:#f92672">+</span>
            <span style="color:#a6e22e">geom_col</span>(<span style="color:#a6e22e">aes</span>(Container, Amount)) <span style="color:#f92672">+</span>
            <span style="color:#a6e22e">labs</span>(title <span style="color:#f92672">=</span> <span style="color:#a6e22e">sprintf</span>(<span style="color:#e6db74">&#39;Total Allocated: %d&#39;</span>, 
                                 <span style="color:#a6e22e">sum</span>(<span style="color:#a6e22e">Allocations</span>()[[<span style="color:#e6db74">&#39;Amount&#39;</span>]]))) <span style="color:#f92672">+</span>
            <span style="color:#a6e22e">theme_bw</span>()
    })
}
<span style="color:#a6e22e">shinyApp</span>(ui <span style="color:#f92672">=</span> ui, server <span style="color:#f92672">=</span> server)
</code></pre></div>]]></description>
        </item>
        
        <item>
            <title>Map Symbols and Size Legends for leaflet</title>
            <link>https://roh.engineering/posts/2021/05/map-symbols-and-size-legends-for-leaflet/</link>
            <pubDate>Thu, 27 May 2021 00:00:00 +0000</pubDate>
            
            <guid>https://roh.engineering/posts/2021/05/map-symbols-and-size-legends-for-leaflet/</guid>
            <description><![CDATA[<p><em>Requires leaflegend &gt;= 1.0.0</em></p>
<p>The <code>leaflet</code> package in R has built-in functionality for creating color
encoded geometries and annotating with color legends. Support is lacking in the
area of providing the ability to encode data with sizes or symbology except for
the case of circle markers. Size and symbology are an important part of
data visualization on a map. Using the <code>leaflegend</code> package, you can add both
to your leaflet maps without adding external css or javascript.</p>
<h1 id="adding-proportional-sizing-to-symbols">Adding Proportional Sizing to Symbols</h1>
<p>To create the appropriately sized symbols, The <code>makeSymbolsSize</code> function can
create a list of icons based on the output of <code>sizeNumeric</code>. The baseSize
argument sets the center point size of the data scale to the mean of the values
e.g. with values 1, 2, 3, 4, 5 and a base size of 10, the resultant size in
pixels of the symbols are 3.33, 6.67, 10, 13.33, 16.67. The symbols can be
added as icons to the map since they are svg elements. Some transparency is
added here to show overlapping symbols.</p>
<p>To add a legend for the sizes, <code>addLegendSize</code> takes in the same values and uses
the <code>pretty</code> function and <em>breaks</em> argument to create the scale. There may be some
inconsistency between the number of breaks specified (<code>leaflet</code> internals also
make use of the <code>pretty</code> function). It is easy to customize other aspects of the
legend for appearance such as here: the color, symbol, and transparency are
matched to the symbols and we align the legend items horizontally.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">library</span>(leaflet)
<span style="color:#a6e22e">library</span>(leaflegend)
<span style="color:#a6e22e">data</span>(<span style="color:#e6db74">&#34;quakes&#34;</span>)
symbols <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">makeSymbolsSize</span>(
  values <span style="color:#f92672">=</span> quakes<span style="color:#f92672">$</span>depth,
  shape <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;diamond&#39;</span>,
  color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;red&#39;</span>,
  fillColor <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;red&#39;</span>,
  opacity <span style="color:#f92672">=</span> <span style="color:#ae81ff">.5</span>,
  baseSize <span style="color:#f92672">=</span> <span style="color:#ae81ff">10</span>
)
<span style="color:#a6e22e">leaflet</span>() <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">addTiles</span>() <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">addMarkers</span>(data <span style="color:#f92672">=</span> quakes,
             icon <span style="color:#f92672">=</span> symbols,
             lat <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>lat, lng <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>long) <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">addLegendSize</span>(
    values <span style="color:#f92672">=</span> quakes<span style="color:#f92672">$</span>depth,
    color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;red&#39;</span>,
    fillColor <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;red&#39;</span>,
    opacity <span style="color:#f92672">=</span> <span style="color:#ae81ff">.5</span>,
    title <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;Depth&#39;</span>,
    shape <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;diamond&#39;</span>,
    orientation <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;horizontal&#39;</span>,
    breaks <span style="color:#f92672">=</span> <span style="color:#ae81ff">5</span>)
</code></pre></div><p><img src="/img/size-legends-01.png" alt=""></p>
<h1 id="encoding-color-and-size">Encoding Color and Size</h1>
<p>A helper function <code>addSymbolsSize</code> simplifies the above code and one can use
a palette to generate colors. The symbols are switched to a plus sign to
provide a smaller impact of area for overlapping points. The result is called
double-encoding and is a way to emphasize differences in data. Because
the Richter scale is on a logarithmic scale, the actual reading
of magnitude was taken as ten to the power of.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">numPal <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">colorNumeric</span>(<span style="color:#e6db74">&#39;viridis&#39;</span>, <span style="color:#ae81ff">10</span><span style="color:#a6e22e">^</span>(quakes<span style="color:#f92672">$</span>mag))
<span style="color:#a6e22e">leaflet</span>(quakes) <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">addTiles</span>() <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">addSymbolsSize</span>(values <span style="color:#f92672">=</span> <span style="color:#f92672">~</span><span style="color:#ae81ff">10</span><span style="color:#a6e22e">^</span>(mag),
                 lat <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>lat, 
                 lng <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>long,
                 shape <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;plus&#39;</span>,
                 color <span style="color:#f92672">=</span> <span style="color:#f92672">~</span><span style="color:#a6e22e">numPal</span>(<span style="color:#ae81ff">10</span><span style="color:#a6e22e">^</span>(mag)),
                 fillColor <span style="color:#f92672">=</span> <span style="color:#f92672">~</span><span style="color:#a6e22e">numPal</span>(<span style="color:#ae81ff">10</span><span style="color:#a6e22e">^</span>(mag)),
                 opacity <span style="color:#f92672">=</span> <span style="color:#ae81ff">.5</span>,
                 baseSize <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>) <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">addLegendSize</span>(
    values <span style="color:#f92672">=</span> <span style="color:#f92672">~</span><span style="color:#ae81ff">10</span><span style="color:#a6e22e">^</span>(mag),
    pal <span style="color:#f92672">=</span> numPal,
    title <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;Magnitude&#39;</span>,
    baseSize <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>,
    shape <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;plus&#39;</span>,
    orientation <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;horizontal&#39;</span>,
    opacity <span style="color:#f92672">=</span> <span style="color:#ae81ff">.5</span>,
    fillOpacity <span style="color:#f92672">=</span> <span style="color:#ae81ff">.3</span>,
    position <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;bottomleft&#39;</span>,
    breaks <span style="color:#f92672">=</span> <span style="color:#ae81ff">5</span>)
</code></pre></div><p><img src="/img/size-legends-02.png" alt=""></p>
<h1 id="split-color-and-size-encodings">Split Color and Size Encodings</h1>
<p>It is also possible to color encode and size encode with different values.
Using a palette function from the leaflet package, the
<em>color/fillColor</em> arguments can be used to base the color encoding on a different
vector of data than the <em>values</em> argument which is for size.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">numPal <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">colorNumeric</span>(<span style="color:#e6db74">&#39;viridis&#39;</span>, quakes<span style="color:#f92672">$</span>mag)
<span style="color:#a6e22e">leaflet</span>(quakes) <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">addTiles</span>() <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">addSymbolsSize</span>(values <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>depth,
                 lat <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>lat, 
                 lng <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>long,
                 shape <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;plus&#39;</span>,
                 color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;black&#39;</span>,
                 fillColor <span style="color:#f92672">=</span> <span style="color:#f92672">~</span><span style="color:#a6e22e">numPal</span>(mag),
                 opacity <span style="color:#f92672">=</span> <span style="color:#ae81ff">.5</span>,
                 baseSize <span style="color:#f92672">=</span> <span style="color:#ae81ff">10</span>) <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">addLegendSize</span>(
    values <span style="color:#f92672">=</span> quakes<span style="color:#f92672">$</span>depth,
    color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;black&#39;</span>,
    title <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;Depth&#39;</span>,
    shape <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;plus&#39;</span>,
    orientation <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;horizontal&#39;</span>,
    opacity <span style="color:#f92672">=</span> <span style="color:#ae81ff">.5</span>,
    fillOpacity <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>,
    breaks <span style="color:#f92672">=</span> <span style="color:#ae81ff">5</span>,
    position <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;bottomright&#39;</span>) <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">addLegendNumeric</span>(
    pal <span style="color:#f92672">=</span> numPal, 
    title <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;Magnitude&#39;</span>,
    shape <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;stadium&#39;</span>,
    values <span style="color:#f92672">=</span> quakes<span style="color:#f92672">$</span>mag, 
    fillOpacity <span style="color:#f92672">=</span> <span style="color:#ae81ff">.5</span>,
    decreasing <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>,
    position <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;bottomright&#39;</span>)
  
</code></pre></div><p><img src="/img/size-legends-03.png" alt=""></p>
<h1 id="size-legend-options">Size Legend Options</h1>
<p>Specifying <em>color</em> and <em>fillColor</em> will override any palette function that is
provided. Below are examples of all the different configurations for the
legend. The symbols are also available for <code>makeSizeIcons</code> to match
the desired legend.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">numPal <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">colorNumeric</span>(<span style="color:#e6db74">&#39;viridis&#39;</span>, quakes<span style="color:#f92672">$</span>depth)
<span style="color:#a6e22e">leaflet</span>() <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">addTiles</span>() <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">addLegendSize</span>(
    values <span style="color:#f92672">=</span> quakes<span style="color:#f92672">$</span>mag,
    color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;black&#39;</span>,
    title <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;Magnitude&#39;</span>,
    labelStyle <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;margin: auto;&#39;</span>,
    shape <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;cross&#39;</span>,
    orientation <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;horizontal&#39;</span>,
    opacity <span style="color:#f92672">=</span> <span style="color:#ae81ff">.7</span>,
    numberFormat <span style="color:#f92672">=</span> <span style="color:#a6e22e">function</span>(x) {
     <span style="color:#a6e22e">prettyNum</span>(x, big.mark <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;,&#34;</span>, scientific <span style="color:#f92672">=</span> <span style="color:#66d9ef">FALSE</span>, digits <span style="color:#f92672">=</span> <span style="color:#ae81ff">3</span>)},
    breaks <span style="color:#f92672">=</span> <span style="color:#ae81ff">5</span>,
    position <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;topright&#39;</span>) <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">addLegendSize</span>(
    values <span style="color:#f92672">=</span> quakes<span style="color:#f92672">$</span>mag,
    color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;black&#39;</span>,
    fillColor <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;transparent&#39;</span>,
    title <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;Magnitude&#39;</span>,
    labelStyle <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;margin: auto;&#39;</span>,
    shape <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;cross&#39;</span>,
    orientation <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;horizontal&#39;</span>,
    opacity <span style="color:#f92672">=</span> <span style="color:#ae81ff">.7</span>,
    numberFormat <span style="color:#f92672">=</span> <span style="color:#a6e22e">function</span>(x) {
     <span style="color:#a6e22e">prettyNum</span>(x, big.mark <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;,&#34;</span>, scientific <span style="color:#f92672">=</span> <span style="color:#66d9ef">FALSE</span>, digits <span style="color:#f92672">=</span> <span style="color:#ae81ff">3</span>)},
    breaks <span style="color:#f92672">=</span> <span style="color:#ae81ff">5</span>,
    position <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;topright&#39;</span>) <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">addLegendSize</span>(
    values <span style="color:#f92672">=</span> quakes<span style="color:#f92672">$</span>depth,
    pal <span style="color:#f92672">=</span> numPal,
    title <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;Depth&#39;</span>,
    labelStyle <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;margin: auto;&#39;</span>,
    shape <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#e6db74">&#39;cross&#39;</span>),
    orientation <span style="color:#f92672">=</span><span style="color:#e6db74">&#39;horizontal&#39;</span>,
    opacity <span style="color:#f92672">=</span> <span style="color:#ae81ff">.7</span>,
    color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;black&#39;</span>,
    breaks <span style="color:#f92672">=</span> <span style="color:#ae81ff">5</span>,
    position <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;topright&#39;</span>) <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">addLegendSize</span>(
    values <span style="color:#f92672">=</span> quakes<span style="color:#f92672">$</span>depth,
    pal <span style="color:#f92672">=</span> numPal,
    title <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;Depth&#39;</span>,
    labelStyle <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;margin: auto;&#39;</span>,
    shape <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#e6db74">&#39;cross&#39;</span>),
    orientation <span style="color:#f92672">=</span><span style="color:#e6db74">&#39;horizontal&#39;</span>,
    opacity <span style="color:#f92672">=</span> <span style="color:#ae81ff">.7</span>,
    fillColor <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;black&#39;</span>,
    breaks <span style="color:#f92672">=</span> <span style="color:#ae81ff">5</span>,
    position <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;topright&#39;</span>) <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">addLegendSize</span>(
    values <span style="color:#f92672">=</span> quakes<span style="color:#f92672">$</span>depth,
    pal <span style="color:#f92672">=</span> numPal,
    title <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;Depth&#39;</span>,
    labelStyle <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;margin: auto;&#39;</span>,
    shape <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#e6db74">&#39;cross&#39;</span>),
    orientation <span style="color:#f92672">=</span><span style="color:#e6db74">&#39;horizontal&#39;</span>,
    opacity <span style="color:#f92672">=</span> <span style="color:#ae81ff">.7</span>,
    breaks <span style="color:#f92672">=</span> <span style="color:#ae81ff">5</span>,
    position <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;topright&#39;</span>)
</code></pre></div><p><img src="/img/size-legends-04.png" alt=""></p>
<p>[<a href="https://cran.r-project.org/web/packages/leaflegend/index.html">CRAN</a>]
[<a href="https://github.com/tomroh/leaflegend">github</a>]</p>
]]></description>
        </item>
        
        <item>
            <title>Introduction to leaflegend</title>
            <link>https://roh.engineering/posts/2021/02/introduction-to-leaflegend/</link>
            <pubDate>Thu, 04 Feb 2021 00:00:00 +0000</pubDate>
            
            <guid>https://roh.engineering/posts/2021/02/introduction-to-leaflegend/</guid>
            <description><![CDATA[<p>leaflegend is a package to extend the customization of legends for the
<a href="https://rstudio.github.io/leaflet/">leaflet</a> package in R. The <code>addLegend</code>
function provides some great out of the box legends based on the internal
palette functions, but styling of the legend components has to be done with
external css code as in this
<a href="https://stackoverflow.com/questions/35778338/custom-legend-with-r-leaflet">example</a>.</p>
<p>leaflegend allows the user to add images to legends,
style the labels of the legend items, change orientation of the legend items,
use different symbologies, and style axis ticks. Syntax and style is consistent with the leaflet package
to lower the mental overhead for new users and the legends are outputs from
<code>leaflet::addControl</code> to ensure interoperability.</p>
<h1 id="custom-images-in-legends">Custom Images in Legends</h1>
<p>Image files already are supported for mapping using the <code>icon</code> series of
functions per <a href="https://rstudio.github.io/leaflet/markers.html">documentation</a>.
<code>addLegendImage</code> accepts png, jpg, and
<a href="https://css-tricks.com/lodge/svg/09-svg-data-uris/">svg data URIs</a> and
encodes and embeds them into the legend.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">library</span>(leaflet)
<span style="color:#a6e22e">library</span>(leaflegend)
<span style="color:#a6e22e">data</span>(<span style="color:#e6db74">&#34;quakes&#34;</span>)
<span style="color:#75715e"># from https://rstudio.github.io/leaflet/markers.html</span>
quakes1 <span style="color:#f92672">&lt;-</span> quakes[1<span style="color:#f92672">:</span><span style="color:#ae81ff">10</span>,]
leafIcons <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">icons</span>(
  iconUrl <span style="color:#f92672">=</span> <span style="color:#a6e22e">ifelse</span>(quakes1<span style="color:#f92672">$</span>mag <span style="color:#f92672">&lt;</span> <span style="color:#ae81ff">4.6</span>,
                   <span style="color:#e6db74">&#34;http://leafletjs.com/examples/custom-icons/leaf-green.png&#34;</span>,
                   <span style="color:#e6db74">&#34;http://leafletjs.com/examples/custom-icons/leaf-red.png&#34;</span>
  ),
  iconWidth <span style="color:#f92672">=</span> <span style="color:#ae81ff">38</span>, iconHeight <span style="color:#f92672">=</span> <span style="color:#ae81ff">95</span>,
  iconAnchorX <span style="color:#f92672">=</span> <span style="color:#ae81ff">22</span>, iconAnchorY <span style="color:#f92672">=</span> <span style="color:#ae81ff">94</span>,
  shadowUrl <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;http://leafletjs.com/examples/custom-icons/leaf-shadow.png&#34;</span>,
  shadowWidth <span style="color:#f92672">=</span> <span style="color:#ae81ff">50</span>, shadowHeight <span style="color:#f92672">=</span> <span style="color:#ae81ff">64</span>,
  shadowAnchorX <span style="color:#f92672">=</span> <span style="color:#ae81ff">4</span>, shadowAnchorY <span style="color:#f92672">=</span> <span style="color:#ae81ff">62</span>
)

<span style="color:#a6e22e">leaflet</span>(data <span style="color:#f92672">=</span> quakes1, width <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;100%&#39;</span>) <span style="color:#f92672">%&gt;%</span> <span style="color:#a6e22e">addTiles</span>() <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">addMarkers</span>(<span style="color:#f92672">~</span>long, <span style="color:#f92672">~</span>lat, icon <span style="color:#f92672">=</span> leafIcons) <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">addLegendImage</span>(images <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#e6db74">&#34;http://leafletjs.com/examples/custom-icons/leaf-green.png&#34;</span>,
                            <span style="color:#e6db74">&#34;http://leafletjs.com/examples/custom-icons/leaf-red.png&#34;</span>),
                 labels <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#e6db74">&#39;Green&#39;</span>, <span style="color:#e6db74">&#39;Red&#39;</span>),width <span style="color:#f92672">=</span> <span style="color:#ae81ff">38</span>, height <span style="color:#f92672">=</span> <span style="color:#ae81ff">95</span>,
                 orientation <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;vertical&#39;</span>,
                 title <span style="color:#f92672">=</span> htmltools<span style="color:#f92672">::</span>tags<span style="color:#f92672">$</span><span style="color:#a6e22e">div</span>(<span style="color:#e6db74">&#39;Leaf&#39;</span>,
                                             style <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;font-size: 24px; text-align: center;&#39;</span>),
                 position <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;topright&#39;</span>)
</code></pre></div><p><img src="/img/leaflegend-01.png" alt=""></p>
<h1 id="creating-svg-map-symbols">Creating SVG Map Symbols</h1>
<p>A helper function is provided to create svg data URIs for commonly used symbols
&ndash; rect, circle, triangle, plus, cross, star and stadium. Beyond the named
arguments for styling the symbol, you can use <code>...</code> to pass arguments to
modify the svg. I would recommend taking a look at <a href="https://developer.mozilla.org/en-US/docs/Web/SVG">MDB Web Docs</a>
to see all the available options.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">redx <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">makeSymbol</span>(<span style="color:#e6db74">&#39;cross&#39;</span>, width <span style="color:#f92672">=</span> <span style="color:#ae81ff">100</span>, height <span style="color:#f92672">=</span> <span style="color:#ae81ff">100</span>, color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;black&#39;</span>, fillColor <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;red&#39;</span>,
           opacity <span style="color:#f92672">=</span> <span style="color:#ae81ff">.7</span>, fillOpacity <span style="color:#f92672">=</span> <span style="color:#ae81ff">.5</span>)
htmltools<span style="color:#f92672">::</span><span style="color:#a6e22e">img</span>(src <span style="color:#f92672">=</span> redx)
</code></pre></div><div>
<img src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20version%3D%221.1%22%20width%3D%22100%22%20height%3D%22100%22%3E%0A%20%20%3Cpolygon%20id%3D%22cross%22%20points%3D%2214.142135623731%2C0%200%2C14.142135623731%2035.857864376269%2C50%200%2C85.857864376269%2014.142135623731%2C100%2050%2C64.142135623731%2085.857864376269%2C100%20100%2C85.857864376269%2064.142135623731%2C50%20100%2C14.142135623731%2085.857864376269%2C0%2050%2C35.857864376269%2014.142135623731%2C0%22%20stroke%3D%22black%22%20fill%3D%22red%22%20stroke-opacity%3D%220.7%22%20fill-opacity%3D%220.5%22%3E%3C%2Fpolygon%3E%0A%3C%2Fsvg%3E"/>
</div>
<p>Images on disk can be mixed with the symbols and displayed. To make your own
symbol, create a character string with <code>data:image/svg+xml,&lt;svg&gt;...&lt;/svg&gt;</code> and
add the class &lsquo;svgURI&rsquo;.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">leaflet</span>(data <span style="color:#f92672">=</span> quakes1, width <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;100%&#39;</span>) <span style="color:#f92672">%&gt;%</span> <span style="color:#a6e22e">addTiles</span>() <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">addMarkers</span>(<span style="color:#f92672">~</span>long, <span style="color:#f92672">~</span>lat, icon <span style="color:#f92672">=</span> leafIcons) <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">addLegendImage</span>(images <span style="color:#f92672">=</span> <span style="color:#a6e22e">list</span>(<span style="color:#e6db74">&#34;http://leafletjs.com/examples/custom-icons/leaf-green.png&#34;</span>,
                               <span style="color:#e6db74">&#34;http://leafletjs.com/examples/custom-icons/leaf-red.png&#34;</span>,
                               redx),
                 labels <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#e6db74">&#39;Green&#39;</span>, <span style="color:#e6db74">&#39;Red&#39;</span>, <span style="color:#e6db74">&#39;Cross&#39;</span>), 
                 width <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#ae81ff">38</span>, <span style="color:#ae81ff">38</span>, <span style="color:#ae81ff">40</span>), 
                 height <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#ae81ff">95</span>, <span style="color:#ae81ff">95</span>, <span style="color:#ae81ff">40</span>),
                 orientation <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;vertical&#39;</span>,
                 title <span style="color:#f92672">=</span> htmltools<span style="color:#f92672">::</span>tags<span style="color:#f92672">$</span><span style="color:#a6e22e">div</span>(<span style="color:#e6db74">&#39;Leaf&#39;</span>,
                                             style <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;font-size: 24px; text-align: center;&#39;</span>),
                 position <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;topright&#39;</span>)
</code></pre></div><p><img src="/img/leaflegend-02.png" alt=""></p>
<p>The map symbols can be used on leaflet maps as well. Create a list of the items
and create them as icons as you would for image files or from icon libraries.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">shapes <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">c</span>(<span style="color:#e6db74">&#39;rect&#39;</span>, <span style="color:#e6db74">&#39;circle&#39;</span>, <span style="color:#e6db74">&#39;triangle&#39;</span>, <span style="color:#e6db74">&#39;plus&#39;</span>, <span style="color:#e6db74">&#39;cross&#39;</span>, <span style="color:#e6db74">&#39;star&#39;</span>)
symbols <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">setNames</span>(<span style="color:#a6e22e">Map</span>(f <span style="color:#f92672">=</span> makeSymbol
               ,shape <span style="color:#f92672">=</span> shapes
               ,fillColor <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#e6db74">&#39;blue&#39;</span>, <span style="color:#e6db74">&#39;red&#39;</span>, <span style="color:#e6db74">&#39;green&#39;</span>, <span style="color:#e6db74">&#39;yellow&#39;</span>, <span style="color:#e6db74">&#39;orange&#39;</span>, <span style="color:#e6db74">&#39;purple&#39;</span>)
               ,color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;black&#39;</span>
               ,opacity <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>
               ,fillOpacity <span style="color:#f92672">=</span> <span style="color:#ae81ff">.5</span>
               ,height <span style="color:#f92672">=</span> <span style="color:#ae81ff">24</span>
               ,width <span style="color:#f92672">=</span> <span style="color:#ae81ff">24</span>
               ,<span style="color:#e6db74">&#39;stroke-width&#39;</span> <span style="color:#f92672">=</span> <span style="color:#ae81ff">2</span>), shapes)
quakes[[<span style="color:#e6db74">&#39;symbol&#39;</span>]] <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">sample</span>(shapes, <span style="color:#a6e22e">nrow</span>(quakes), replace <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>)

<span style="color:#a6e22e">leaflet</span>(data <span style="color:#f92672">=</span> quakes<span style="color:#a6e22e">[sample</span>(<span style="color:#a6e22e">seq_len</span>(<span style="color:#a6e22e">nrow</span>(quakes)), <span style="color:#ae81ff">25</span>),], width <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;100%&#39;</span>) <span style="color:#f92672">%&gt;%</span> <span style="color:#a6e22e">addTiles</span>() <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">addMarkers</span>(
    <span style="color:#f92672">~</span> long,
    <span style="color:#f92672">~</span> lat,
    icon <span style="color:#f92672">=</span> <span style="color:#f92672">~</span> <span style="color:#a6e22e">icons</span>(
      iconUrl <span style="color:#f92672">=</span> symbols[symbol],
      iconWidth <span style="color:#f92672">=</span> <span style="color:#ae81ff">20</span>,
      iconHeight <span style="color:#f92672">=</span> <span style="color:#ae81ff">20</span>
    )
  ) <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">addLegendImage</span>(
    images <span style="color:#f92672">=</span> symbols,
    labels <span style="color:#f92672">=</span> shapes,
    width <span style="color:#f92672">=</span> <span style="color:#ae81ff">50</span>,
    height <span style="color:#f92672">=</span> <span style="color:#ae81ff">50</span>,
    orientation <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;vertical&#39;</span>,
    title <span style="color:#f92672">=</span> htmltools<span style="color:#f92672">::</span>tags<span style="color:#f92672">$</span><span style="color:#a6e22e">div</span>(<span style="color:#e6db74">&#39;Symbol&#39;</span>,
                                style <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;font-size: 24px; text-align: center;&#39;</span>),
    position <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;topright&#39;</span>
  )
</code></pre></div><p><img src="/img/leaflegend-03.png" alt=""></p>
<p><em>Update: Requires leaflegend &gt;= 1.0.0</em></p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">shapeColorPal <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">colorFactor</span>(<span style="color:#a6e22e">c</span>(<span style="color:#e6db74">&#39;blue&#39;</span>, <span style="color:#e6db74">&#39;red&#39;</span>, <span style="color:#e6db74">&#39;green&#39;</span>, 
                               <span style="color:#e6db74">&#39;yellow&#39;</span>, <span style="color:#e6db74">&#39;orange&#39;</span>, <span style="color:#e6db74">&#39;purple&#39;</span>),
                             shapes)
<span style="color:#a6e22e">leaflet</span>(data <span style="color:#f92672">=</span> quakes<span style="color:#a6e22e">[sample</span>(<span style="color:#a6e22e">seq_len</span>(<span style="color:#a6e22e">nrow</span>(quakes)), <span style="color:#ae81ff">25</span>),], width <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;100%&#39;</span>) <span style="color:#f92672">%&gt;%</span> 
  <span style="color:#a6e22e">addTiles</span>() <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">addSymbols</span>(
    lng <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>long,
    lat <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>lat,
    values <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>symbol, color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;black&#39;</span>, 
    fillColor <span style="color:#f92672">=</span> <span style="color:#f92672">~</span><span style="color:#a6e22e">shapeColorPal</span>(symbol),
    fillOpacity <span style="color:#f92672">=</span> <span style="color:#ae81ff">.5</span>,
    width <span style="color:#f92672">=</span> <span style="color:#ae81ff">24</span>,
    height <span style="color:#f92672">=</span> <span style="color:#ae81ff">24</span>
  ) <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">addLegendSymbol</span>(
    pal <span style="color:#f92672">=</span> shapeColorPal,
    values <span style="color:#f92672">=</span> <span style="color:#f92672">~</span>symbol,
    color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;black&#39;</span>,
    fillOpacity <span style="color:#f92672">=</span> <span style="color:#ae81ff">.5</span>,
    width <span style="color:#f92672">=</span> <span style="color:#ae81ff">50</span>,
    height <span style="color:#f92672">=</span> <span style="color:#ae81ff">50</span>,
    orientation <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;vertical&#39;</span>,
    title <span style="color:#f92672">=</span> htmltools<span style="color:#f92672">::</span>tags<span style="color:#f92672">$</span><span style="color:#a6e22e">div</span>(<span style="color:#e6db74">&#39;Symbol&#39;</span>,
                                style <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;font-size: 24px; text-align: center;&#39;</span>),
    position <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;topright&#39;</span>
  )
</code></pre></div><h1 id="customizing-leaflet-legends-with-palettes">Customizing Leaflet Legends with Palettes</h1>
<p>The <code>addLegend*</code> functions take palettes generated from the <em>leaflet</em> package
and uses them to create legends with greater flexibility. For instance,
using differently symbology for points is possible by specifying a
different shape. You can control the opacity of the outline and fill so that
it matches what is displayed on the map. Position the legend elements to
be horizontal or vertical and control the text styling of the title and the
label elements.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">binPal <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">colorBin</span>(<span style="color:#e6db74">&#39;Set1&#39;</span>, quakes<span style="color:#f92672">$</span>mag)
symbols <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">lapply</span>(<span style="color:#a6e22e">binPal</span>(quakes<span style="color:#f92672">$</span>mag)
                  ,makeSymbol
                  ,shape <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;triangle&#39;</span>
                  ,opacity <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>
                  ,fillOpacity <span style="color:#f92672">=</span> <span style="color:#ae81ff">.5</span>
                  ,height <span style="color:#f92672">=</span> <span style="color:#ae81ff">24</span>
                  ,width <span style="color:#f92672">=</span> <span style="color:#ae81ff">24</span>
                  ,<span style="color:#e6db74">&#39;stroke-width&#39;</span> <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>)
<span style="color:#a6e22e">leaflet</span>(width <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;100%&#39;</span>) <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">addTiles</span>() <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">addMarkers</span>(
    data <span style="color:#f92672">=</span> quakes,
    lat <span style="color:#f92672">=</span> <span style="color:#f92672">~</span> lat,
    lng <span style="color:#f92672">=</span> <span style="color:#f92672">~</span> long,
    icon <span style="color:#f92672">=</span> <span style="color:#f92672">~</span><span style="color:#a6e22e">icons</span>(
      iconUrl <span style="color:#f92672">=</span> symbols,
      iconWidth <span style="color:#f92672">=</span> <span style="color:#ae81ff">10</span>,
      iconHeight <span style="color:#f92672">=</span> <span style="color:#ae81ff">10</span>
    )
  ) <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">addLegendBin</span>(
    pal <span style="color:#f92672">=</span> binPal,
    values <span style="color:#f92672">=</span> quakes<span style="color:#f92672">$</span>mag,
    position <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;bottomleft&#39;</span>,
    title <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;horizontal&#39;</span>,
    shape <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;triangle&#39;</span>,
    opacity <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>,
    fillOpacity <span style="color:#f92672">=</span> <span style="color:#ae81ff">.2</span>,
    labelStyle <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;font-size: 18px; font-weight: bold;&#39;</span>,
    orientation <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;horizontal&#39;</span>,
    layerId <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;horizontal&#39;</span>
  ) <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">addLegendBin</span>(
    pal <span style="color:#f92672">=</span> binPal,
    values <span style="color:#f92672">=</span> quakes<span style="color:#f92672">$</span>mag,
    position <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;bottomright&#39;</span>,
    title <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;vertical&#39;</span>,
    shape <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;triangle&#39;</span>,
    opacity <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>,
    fillOpacity <span style="color:#f92672">=</span> <span style="color:#ae81ff">.2</span>,
    orientation <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;vertical&#39;</span>,
    layerId <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;vertical&#39;</span>
  ) <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">addLegend</span>(pal <span style="color:#f92672">=</span> binPal,
            values <span style="color:#f92672">=</span> quakes<span style="color:#f92672">$</span>mag,
            title <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;addLegend&#39;</span>,
            layerId <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;addLegend&#39;</span>)
</code></pre></div><p><img src="/img/leaflegend-04.png" alt=""></p>
<p>[<a href="https://cran.r-project.org/web/packages/leaflegend/index.html">CRAN</a>]
[<a href="https://github.com/tomroh/leaflegend">github</a>]</p>
]]></description>
        </item>
        
        <item>
            <title>Shiny in Production: App and Database Syncing</title>
            <link>https://roh.engineering/posts/2020/08/shiny-in-production-app-and-database-syncing/</link>
            <pubDate>Sat, 22 Aug 2020 00:00:00 +0000</pubDate>
            
            <guid>https://roh.engineering/posts/2020/08/shiny-in-production-app-and-database-syncing/</guid>
            <description><![CDATA[<p>When using shiny in production, often you will want to have some sort of
database interactions for storing and accessing data. The <code>DBI</code> package
provides an easy way to do the database interactions with a variety of
SQL database flavors. In this example, I&rsquo;m going to use a SQLite in memory
database for reproducibility. In practice, you will just switch to the code to
use a persistent database. Let&rsquo;s start by creating a table to right to.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">library</span>(RSQLite)
<span style="color:#a6e22e">library</span>(DBI)
con <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">dbConnect</span>(RSQLite<span style="color:#f92672">::</span><span style="color:#a6e22e">SQLite</span>(), <span style="color:#e6db74">&#34;:memory:&#34;</span>)
<span style="color:#a6e22e">dbExecute</span>(con, <span style="color:#e6db74">&#39;CREATE TABLE mytable (col1 int, col2 varchar(10));&#39;</span>)
</code></pre></div><pre><code>## [1] 0
</code></pre><p>Check that the table exists now.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">dbListTables</span>(con)
</code></pre></div><pre><code>## [1] &quot;mytable&quot;
</code></pre><p>Add a single row to the table to check that we can insert.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">dbExecute</span>(con, <span style="color:#e6db74">&#39;INSERT INTO mytable ([col1], [col2]) VALUES (1, &#34;b&#34;);&#34;&#39;</span>)
</code></pre></div><pre><code>## [1] 1
</code></pre><div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">dbGetQuery</span>(con, <span style="color:#e6db74">&#39;SELECT col1, col2 FROM mytable&#39;</span>)
</code></pre></div><pre><code>##   col1 col2
## 1    1    b
</code></pre><p>So now we have a table in the database and we can write to it. When the
shiny application loads, we will want to show the user what is in the table.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">mytableinshiny <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">reactive</span>({
  <span style="color:#a6e22e">dbGetQuery</span>(con, <span style="color:#e6db74">&#39;SELECT col1, col2 from mytable&#39;</span>)
})
<span style="color:#a6e22e">mytableinshiny</span>()
</code></pre></div><pre><code>##   col1 col2
## 1    1    b
</code></pre><p>This works great and now we can use the data from the database to do whatever
we need it to do in the shiny application. If we create the following
action, the function does the necessary side effect of writing to the database
but unless the user reloads the application <code>mytableinshiny</code> does not update
in the application.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">observeEvent</span>(input<span style="color:#f92672">$</span>writetodb, {
  sql <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">sqlInterpolate</span>(con, <span style="color:#e6db74">&#39;INSERT INTO mytable ([col1], [col2]) VALUES (col1, ?col2);&#34;&#39;</span>,
                        col1 <span style="color:#f92672">=</span> input<span style="color:#f92672">$</span>col1, col2 <span style="color:#f92672">=</span> input<span style="color:#f92672">$</span>col2)
  <span style="color:#a6e22e">dbExecute</span>(con, sql)
})
</code></pre></div><div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">mytableinshiny</span>()
</code></pre></div><pre><code>##   col1 col2
## 1    1    b
</code></pre><p>After the database insertion, we need a way to inform shiny to update the
reactive data.frame. We can use a <a href="https://github.com/daattali/advanced-shiny/tree/master/reactive-trigger">reactive trigger</a>
to &ldquo;push&rdquo; a button that lets shiny know that the database has changed and it
should re-execute the <code>SELECT</code> query.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">makereactivetrigger <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">function</span>() {
  rv <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">reactiveValues</span>(a <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>)
  <span style="color:#a6e22e">list</span>(
    depend <span style="color:#f92672">=</span> <span style="color:#a6e22e">function</span>() {
      rv<span style="color:#f92672">$</span>a
      <span style="color:#a6e22e">invisible</span>()
    },
    trigger <span style="color:#f92672">=</span> <span style="color:#a6e22e">function</span>() {
      rv<span style="color:#f92672">$</span>a <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">isolate</span>(rv<span style="color:#f92672">$</span>a <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>)
    }
  )
}
dbtrigger <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">makereactivetrigger</span>()
</code></pre></div><p>The trigger is now an object that has a couple of functions to pass messages
around. We need to set the reactive value to re-execute so add the <code>depend</code>
function and after the database interaction executes we add the <code>trigger</code>
function. Also, it&rsquo;s good practice to use <code>sqlInterpolate</code> to help prevent
sql injection attacks.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">mytableinshiny <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">reactive</span>({
  dbtrigger<span style="color:#f92672">$</span><span style="color:#a6e22e">depend</span>()
  <span style="color:#a6e22e">dbGetQuery</span>(con, <span style="color:#e6db74">&#39;SELECT col1, col2 from mytable&#39;</span>)
})
<span style="color:#a6e22e">observeEvent</span>(input<span style="color:#f92672">$</span>writetodb, {
  sql <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">sqlInterpolate</span>(con, <span style="color:#e6db74">&#39;INSERT INTO mytable ([col1], [col2]) VALUES (?col1, ?col2)&#39;</span>,
                        col1 <span style="color:#f92672">=</span> input<span style="color:#f92672">$</span>col1, col2 <span style="color:#f92672">=</span> input<span style="color:#f92672">$</span>col2)
  <span style="color:#a6e22e">dbExecute</span>(con, sql)
  dbtrigger<span style="color:#f92672">$</span><span style="color:#a6e22e">trigger</span>()
})
</code></pre></div><p>Within the app, we put the data in the shiny input forms and hit the write to
database action button when ready.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">mytableinshiny</span>()
</code></pre></div><pre><code>##   col1 col2
## 1    1    b
## 2    2    a
</code></pre><p>Now when the database is updated the shiny application syncs to what is in the
database after the insertion.</p>
<p>Here&rsquo;s a toy example to play with:</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">library</span>(shiny)
<span style="color:#a6e22e">library</span>(RSQLite)
<span style="color:#a6e22e">library</span>(DBI)
makereactivetrigger <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">function</span>() {
    rv <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">reactiveValues</span>(a <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>)
    <span style="color:#a6e22e">list</span>(
        depend <span style="color:#f92672">=</span> <span style="color:#a6e22e">function</span>() {
            rv<span style="color:#f92672">$</span>a
            <span style="color:#a6e22e">invisible</span>()
        },
        trigger <span style="color:#f92672">=</span> <span style="color:#a6e22e">function</span>() {
            rv<span style="color:#f92672">$</span>a <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">isolate</span>(rv<span style="color:#f92672">$</span>a <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>)
        }
    )
}
dbtrigger <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">makereactivetrigger</span>()
con <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">dbConnect</span>(RSQLite<span style="color:#f92672">::</span><span style="color:#a6e22e">SQLite</span>(), <span style="color:#e6db74">&#34;:memory:&#34;</span>)
<span style="color:#a6e22e">dbExecute</span>(con, <span style="color:#e6db74">&#39;CREATE TABLE mytable (col1 int, col2 varchar(10));&#39;</span>)
ui <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">fluidPage</span>(
    <span style="color:#a6e22e">numericInput</span>(<span style="color:#e6db74">&#39;col1&#39;</span>, <span style="color:#e6db74">&#39;col1&#39;</span>, value <span style="color:#f92672">=</span> <span style="color:#ae81ff">1L</span>, step <span style="color:#f92672">=</span> <span style="color:#ae81ff">1L</span>),
    <span style="color:#a6e22e">textInput</span>(<span style="color:#e6db74">&#39;col2&#39;</span>, <span style="color:#e6db74">&#39;col2&#39;</span>, value <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;a&#39;</span>),
    <span style="color:#a6e22e">actionButton</span>(<span style="color:#e6db74">&#39;writetodb&#39;</span>, <span style="color:#e6db74">&#39;Save&#39;</span>),
    <span style="color:#a6e22e">tableOutput</span>(<span style="color:#e6db74">&#39;dbtable&#39;</span>)
)
server <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">function</span>(input, output) {
    mytableinshiny <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">reactive</span>({
        dbtrigger<span style="color:#f92672">$</span><span style="color:#a6e22e">depend</span>()
        <span style="color:#a6e22e">dbGetQuery</span>(con, <span style="color:#e6db74">&#39;SELECT col1, col2 from mytable&#39;</span>)
    })
    <span style="color:#a6e22e">observeEvent</span>(input<span style="color:#f92672">$</span>writetodb, {
        sql <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">sqlInterpolate</span>(con, <span style="color:#e6db74">&#39;INSERT INTO mytable ([col1], [col2]) VALUES (?col1, ?col2)&#39;</span>,
                              col1 <span style="color:#f92672">=</span> input<span style="color:#f92672">$</span>col1, col2 <span style="color:#f92672">=</span> input<span style="color:#f92672">$</span>col2)
        <span style="color:#a6e22e">dbExecute</span>(con, sql)
        dbtrigger<span style="color:#f92672">$</span><span style="color:#a6e22e">trigger</span>()
    })
    output<span style="color:#f92672">$</span>dbtable <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">renderTable</span>({
        <span style="color:#a6e22e">mytableinshiny</span>()
    })
}
<span style="color:#a6e22e">shinyApp</span>(ui <span style="color:#f92672">=</span> ui, server <span style="color:#f92672">=</span> server)
</code></pre></div>]]></description>
        </item>
        
        <item>
            <title>Shiny: Add/Removing Modules Dynamically</title>
            <link>https://roh.engineering/posts/2020/02/shiny-add/removing-modules-dynamically/</link>
            <pubDate>Tue, 11 Feb 2020 00:00:00 +0000</pubDate>
            
            <guid>https://roh.engineering/posts/2020/02/shiny-add/removing-modules-dynamically/</guid>
            <description><![CDATA[<p><img src="https://i.imgur.com/F3s23ui.gif" alt=""></p>
<h4 id="introduction">Introduction</h4>
<p>Shiny modules provide a great way to organize and container-ize your code for
building complex Shiny applications as well as protecting namespace collisions.
I highly recommend starting with the excellent <a href="https://shiny.rstudio.com/articles/modules.html">documentation</a> from Rstudio.
In this post, I am going to cover how to implement modules with
insertUI/removeUI so that you DRY, clear server-side overhead, and encapsulate
duplicative-ish shiny input names in their own namespace.</p>
<p>Normally when developing an application, each input provides a unique parameter
for the output and it is specified by a unique ID. The example below illustrates
a shiny app that allows the end user to specify the variables for regression.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">library</span>(shiny)
<span style="color:#a6e22e">data</span>(mtcars)
cols <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">sort</span>(<span style="color:#a6e22e">unique</span>(<span style="color:#a6e22e">names</span>(mtcars)<span style="color:#a6e22e">[names</span>(mtcars) <span style="color:#f92672">!=</span> <span style="color:#e6db74">&#39;mpg&#39;</span>]))
ui <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">fluidPage</span>(
    <span style="color:#a6e22e">wellPanel</span>(
    <span style="color:#a6e22e">fluidRow</span>(
        <span style="color:#a6e22e">column</span>(<span style="color:#ae81ff">4</span>,
               tags<span style="color:#f92672">$</span><span style="color:#a6e22e">h3</span>(<span style="color:#e6db74">&#39;Build a Linear Model for MPG&#39;</span>),
               <span style="color:#a6e22e">selectInput</span>(<span style="color:#e6db74">&#39;vars&#39;</span>,
                           <span style="color:#e6db74">&#39;Select dependent variables&#39;</span>,
                           choices <span style="color:#f92672">=</span> cols,
                           selected <span style="color:#f92672">=</span> cols[1<span style="color:#f92672">:</span><span style="color:#ae81ff">2</span>],
                           multiple <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>)),
        <span style="color:#a6e22e">column</span>(<span style="color:#ae81ff">4</span>, <span style="color:#a6e22e">verbatimTextOutput</span>(<span style="color:#e6db74">&#39;lmSummary&#39;</span>)),
        <span style="color:#a6e22e">column</span>(<span style="color:#ae81ff">4</span>, <span style="color:#a6e22e">plotOutput</span>(<span style="color:#e6db74">&#39;diagnosticPlot&#39;</span>))
    )
  )
)
server <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">function</span>(input, output) {
    lmModel <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">reactive</span>({<span style="color:#a6e22e">lm</span>(<span style="color:#a6e22e">sprintf</span>(<span style="color:#e6db74">&#39;mpg ~ %s&#39;</span>, <span style="color:#a6e22e">paste</span>(input<span style="color:#f92672">$</span>vars, collapse <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;+&#39;</span>)),
                  data <span style="color:#f92672">=</span> mtcars)})
    output<span style="color:#f92672">$</span>lmSummary <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">renderPrint</span>({
        <span style="color:#a6e22e">summary</span>(<span style="color:#a6e22e">lmModel</span>())
    })

    output<span style="color:#f92672">$</span>diagnosticPlot <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">renderPlot</span>({
        <span style="color:#a6e22e">par</span>(mfrow <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#ae81ff">2</span>,<span style="color:#ae81ff">2</span>))
        <span style="color:#a6e22e">plot</span>(<span style="color:#a6e22e">lmModel</span>())
    })
}
<span style="color:#a6e22e">shinyApp</span>(ui <span style="color:#f92672">=</span> ui, server <span style="color:#f92672">=</span> server)
</code></pre></div><p>There is no need to worry about namespace collisions here because you can
directly control the unique-ness of each input control. Note: If you
accidentally duplicate the id, Shiny is not going to tell you that from the
R console. If you open up the browser devtools, you will find an error like
this:</p>
<p><img src="https://i.imgur.com/sNhZCjS.png" alt=""></p>
<h4 id="creating-insertuiremoveui-modules">Creating insertUI/removeUI Modules</h4>
<p>Now, one linear model is great to start, but I want to try out several
different models with different variables. I could select the variables,
take a screenshot of each model, and piece them all together later but I&rsquo;m
trying to make it much easier for the end user. Wrapping the app above into a
module requires a UI function. The <code>NS</code> function is a convenience function to
create a namespace for the input IDs. In short, when input IDs are created
later on they will be pre-fixed with lmModel<em>id</em>.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">lmUI <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">function</span>(id) {
  ns <span style="color:#f92672">&lt;-</span> shiny<span style="color:#f92672">::</span><span style="color:#a6e22e">NS</span>(id)
  shiny<span style="color:#f92672">::</span><span style="color:#a6e22e">uiOutput</span>(<span style="color:#a6e22e">ns</span>(<span style="color:#e6db74">&#34;lmModel&#34;</span>))
}
</code></pre></div><p>This particular module UI may look a bit sparse to other examples. The UI that
the end user sees is going to be generated later on with <code>renderUI</code>. All
that this UI needs to do is set the namespace.</p>
<p>Next, the server code needs to be wrapped into a server module. The UI and
server code is going to be combined for use with renderUI. I also added in a
delete button that will be the input for removing UI controls. The rendered
UI is also wrapped with a <em>div</em> id. To keep track of each UI Controls, I&rsquo;m
using <code>environment(ns)[['namespace']]</code> which is a fancy way to pull out the
namespace from <code>session$ns</code>. <code>environment</code> gets the environment (space to look
in for values; similar to namespace) of <code>ns</code> which is storing the namespace id.
Environments are an advanced concept in R which you can find details on at
from <a href="http://adv-r.had.co.nz/Environments.html">Advanced R</a> from Hadley Wickham
and also from <a href="https://cran.r-project.org/doc/manuals/r-release/R-lang.html#Environment-objects">R Language Definition</a></p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">lmModelModule <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">function</span>(input, output, session) {
  lmModel <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">reactive</span>({
    <span style="color:#a6e22e">lm</span>(<span style="color:#a6e22e">sprintf</span>(<span style="color:#e6db74">&#39;mpg ~ %s&#39;</span>,<span style="color:#a6e22e">paste</span>(input<span style="color:#f92672">$</span>vars, collapse <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;+&#39;</span>)), data <span style="color:#f92672">=</span> mtcars)
    })
  output[[<span style="color:#e6db74">&#39;lmModel&#39;</span>]] <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">renderUI</span>({
    ns <span style="color:#f92672">&lt;-</span> session<span style="color:#f92672">$</span>ns
    tags<span style="color:#f92672">$</span><span style="color:#a6e22e">div</span>(id <span style="color:#f92672">=</span> <span style="color:#a6e22e">environment</span>(ns)[[<span style="color:#e6db74">&#39;namespace&#39;</span>]],
    <span style="color:#a6e22e">tagList</span>(
      <span style="color:#a6e22e">wellPanel</span>(
        <span style="color:#a6e22e">fluidRow</span>(
            <span style="color:#a6e22e">column</span>(<span style="color:#ae81ff">3</span>,
                   tags<span style="color:#f92672">$</span><span style="color:#a6e22e">h3</span>(<span style="color:#e6db74">&#39;Build a Linear Model for MPG&#39;</span>),
                   <span style="color:#a6e22e">selectInput</span>(<span style="color:#a6e22e">ns</span>(<span style="color:#e6db74">&#39;vars&#39;</span>),
                               <span style="color:#e6db74">&#39;Select dependent variables&#39;</span>,
                               choices <span style="color:#f92672">=</span> cols,
                               selected <span style="color:#f92672">=</span> cols[1<span style="color:#f92672">:</span><span style="color:#ae81ff">2</span>],
                               multiple <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>)),
            <span style="color:#a6e22e">column</span>(<span style="color:#ae81ff">4</span>, 
                   <span style="color:#a6e22e">renderPrint</span>({<span style="color:#a6e22e">summary</span>(<span style="color:#a6e22e">lmModel</span>())})
            ),
            <span style="color:#a6e22e">column</span>(<span style="color:#ae81ff">4</span>, 
                   <span style="color:#a6e22e">renderPlot</span>({<span style="color:#a6e22e">par</span>(mfrow <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#ae81ff">2</span>,<span style="color:#ae81ff">2</span>))
                               <span style="color:#a6e22e">plot</span>(<span style="color:#a6e22e">lmModel</span>())})
                     ),
            <span style="color:#a6e22e">column</span>(<span style="color:#ae81ff">1</span>,
                   <span style="color:#a6e22e">actionButton</span>(<span style="color:#a6e22e">ns</span>(<span style="color:#e6db74">&#39;deleteButton&#39;</span>),
                                <span style="color:#e6db74">&#39;&#39;</span>,
                                icon <span style="color:#f92672">=</span> shiny<span style="color:#f92672">::</span><span style="color:#a6e22e">icon</span>(<span style="color:#e6db74">&#39;times&#39;</span>),
                                style <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;float: right&#39;</span>)
            )
        )
      )
    )
    )
  })
}
</code></pre></div><h4 id="dynamic-uiserver-logic">Dynamic UI/Server Logic</h4>
<p>The modules can be called just as functions can be called. For ease, just place
the module code at the top of the shiny application script outside of the
main server/ui functions. The main shiny functions below are even shorter than
the workhorse module functions. Even in a small application you can start to
see the benefit of &ldquo;modularizing&rdquo; code!</p>
<p>The majority of the code in server is just setting up handling for the module IDs.
The <code>actionButton</code> increments by 1 each time that it is clicked so I&rsquo;m using it
as an ID number. The <code>id</code> tag is doing double duty here: providing the namespace
for module UI and for the div tag so that we can remove it later on. After
calling the module, you will want to create an action that will respond to
deleting the module. The last <code>observeEvent</code> will create that action
and it will persist with the correct <code>id</code>.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">ui <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">fluidPage</span>(
    <span style="color:#a6e22e">br</span>(),
    <span style="color:#a6e22e">actionButton</span>(<span style="color:#e6db74">&#39;addButton&#39;</span>, <span style="color:#e6db74">&#39;&#39;</span>, icon <span style="color:#f92672">=</span> <span style="color:#a6e22e">icon</span>(<span style="color:#e6db74">&#39;plus&#39;</span>))
)
server <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">function</span>(input, output) {
    <span style="color:#a6e22e">observeEvent</span>(input<span style="color:#f92672">$</span>addButton, {
        i <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">sprintf</span>(<span style="color:#e6db74">&#39;%04d&#39;</span>, input<span style="color:#f92672">$</span>addButton)
        id <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">sprintf</span>(<span style="color:#e6db74">&#39;lmModel%s&#39;</span>, i)
        <span style="color:#a6e22e">insertUI</span>(
            selector <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;#addButton&#39;</span>,
            where <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;beforeBegin&#34;</span>,
            ui <span style="color:#f92672">=</span> <span style="color:#a6e22e">lmUI</span>(id)
        )
        <span style="color:#a6e22e">callModule</span>(lmModelModule, id)
        <span style="color:#a6e22e">observeEvent</span>(input[<span style="color:#a6e22e">[paste0</span>(id, <span style="color:#e6db74">&#39;-deleteButton&#39;</span>)]], {
            <span style="color:#a6e22e">removeUI</span>(selector <span style="color:#f92672">=</span> <span style="color:#a6e22e">sprintf</span>(<span style="color:#e6db74">&#39;#%s&#39;</span>, id))
            <span style="color:#a6e22e">remove_shiny_inputs</span>(id, input)
        })
    })
}
<span style="color:#a6e22e">shinyApp</span>(ui <span style="color:#f92672">=</span> ui, server <span style="color:#f92672">=</span> server)
</code></pre></div><h4 id="cleaning-up-server-side">Cleaning up Server Side</h4>
<p><code>removeUI</code> will delete the contents on the client side, but the inputs will
still exist on the server side. Currently, removing the inputs on the server
side is not implemented in the shiny package. A couple of work-arounds have been
provided <a href="https://github.com/rstudio/shiny/issues/2374">here</a> and
<a href="https://github.com/rstudio/shiny/issues/2439">here</a>.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">remove_shiny_inputs <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">function</span>(id, .input) {
  <span style="color:#a6e22e">invisible</span>(
    <span style="color:#a6e22e">lapply</span>(<span style="color:#a6e22e">grep</span>(id, <span style="color:#a6e22e">names</span>(.input), value <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>), <span style="color:#a6e22e">function</span>(i) {
      <span style="color:#a6e22e">.subset2</span>(.input, <span style="color:#e6db74">&#34;impl&#34;</span>)<span style="color:#f92672">$</span>.values<span style="color:#f92672">$</span><span style="color:#a6e22e">remove</span>(i)
    })
  )
}
</code></pre></div><p>I used the latter to pass that all important <code>id</code> to look up all inputs in
that namespace and remove them. Inputs are protected from directly using
<code>input[[inputName]] &lt;- NULL</code> to delete them. For the outputs on the server
side, I haven&rsquo;t been able to find that much documentation on what happens to it.
I know that they still exist as at least a named entry on the server side.
According to this closed <a href="https://github.com/rstudio/shiny/issues/1989">issue</a>,
it is possible to remove them, but it doesn&rsquo;t appear their name slots go away.
Debugging and using <code>outputOptions</code> still listed the output, but setting the
output to <code>NULL</code> will delete them from what the user sees on the shiny
application.</p>
<h4 id="final-thoughts">Final Thoughts</h4>
<p>Modules, insertUI, and removeUI have added some very impressive features to
Shiny. It has opened up a much more on-the-fly interface for Shiny
developers. I&rsquo;m hoping development around these ideas continue. My first crack at this, I didn&rsquo;t use the <code>NS</code> framework at all, but
essentially used the same method so there is more than one way to do this.
Using <code>NS</code> will save you leg work. Here is an example of my first attempt:</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">observeEvent</span>(input<span style="color:#f92672">$</span>add, {
  i <span style="color:#f92672">&lt;-</span> input<span style="color:#f92672">$</span>add
  id <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">sprintf</span>(<span style="color:#e6db74">&#39;%04d&#39;</span>, i)
  inputID <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">sprintf</span>(<span style="color:#e6db74">&#39;input-%s&#39;</span>, id)
  <span style="color:#a6e22e">insertUI</span>(
    selector <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;#add&#34;</span>,
    ui <span style="color:#f92672">=</span> tags<span style="color:#f92672">$</span><span style="color:#a6e22e">div</span>(id <span style="color:#f92672">=</span> inputID,
                  <span style="color:#a6e22e">numericInput</span>(id, <span style="color:#e6db74">&#39;A number&#39;</span>)
    )
  )
})
</code></pre></div><p>Possible enhancment: In the above code, I was using integers from the action button increment so that I could easily see that Shiny was doing what I expected it to
do. An enhancement would be to generate something like a guid so that you
wouldn&rsquo;t have to worry about what happens when multiple users in the same
app are clicking. This might not be needed if the action button increments are
per user per session. I still have some homework to do on the namespacing in
Shiny and client/server data persistence.</p>
]]></description>
        </item>
        
        <item>
            <title>SQL Server Schemas &amp; R Tip</title>
            <link>https://roh.engineering/posts/2019/10/sql-server-schemas-r-tip/</link>
            <pubDate>Sat, 19 Oct 2019 00:00:00 +0000</pubDate>
            
            <guid>https://roh.engineering/posts/2019/10/sql-server-schemas-r-tip/</guid>
            <description><![CDATA[<p>I ran into an issue the other day where I was tring to write a new table to a
SQL Server Database with a non-default schema. I did end up spending a bit of time debugging and researching so I wanted to share for anyone else that runs into the issue. Using the <code>DBI::Id</code> function,
allows you to specify the schema when you are trying to write a table to a SQL Server database.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">DBI<span style="color:#f92672">::</span><span style="color:#a6e22e">dbWriteTable</span>(con, 
                  DBI<span style="color:#f92672">::</span><span style="color:#a6e22e">Id</span>(schema <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;schema&#34;</span>, table <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;tablename&#34;</span>), 
                  df)
</code></pre></div><p>But the code above will return a strange error:</p>
<p><img src="https://i.imgur.com/vCK0fWK.png" alt=""></p>
<p>After some investigation I found a workaround to be able to write the table. For non-default schemas, a &ldquo;_&rdquo; needs to in the table name for it to work.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">DBI<span style="color:#f92672">::</span><span style="color:#a6e22e">dbWriteTable</span>(con, 
                  DBI<span style="color:#f92672">::</span><span style="color:#a6e22e">Id</span>(schema <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;schema&#34;</span>, table <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;tablename_&#34;</span>), 
                  df)
</code></pre></div><p>This really isn&rsquo;t ideal for naming conventions so using the t-sql command sp_rename will rename the table to what I originally wanted.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">DBI<span style="color:#f92672">::</span><span style="color:#a6e22e">dbWriteTable</span>(con, 
                  DBI<span style="color:#f92672">::</span><span style="color:#a6e22e">Id</span>(schema <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;schema&#34;</span>, table <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;tablename&#34;</span>), 
                  df)
DBI<span style="color:#f92672">::</span><span style="color:#a6e22e">dbGetQuery</span>(con, <span style="color:#e6db74">&#34;USE database;
</span><span style="color:#e6db74">EXEC sp_rename &#39;[schema].[tablename_]&#39;, &#39;tablename&#39;;&#34;</span>)
</code></pre></div><p>I ran into the same issues for overwriting tables as well but a workflow for doing the same is simply to use sp_rename a couple of times.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">DBI<span style="color:#f92672">::</span><span style="color:#a6e22e">dbGetQuery</span>(con, <span style="color:#e6db74">&#34;USE database;
</span><span style="color:#e6db74">EXEC sp_rename &#39;[schema].[tablename]&#39;, &#39;tablename_&#39;;&#34;</span>)
DBI<span style="color:#f92672">::</span><span style="color:#a6e22e">dbWriteTable</span>(con, 
                  DBI<span style="color:#f92672">::</span><span style="color:#a6e22e">Id</span>(schema <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;schema&#34;</span>, table <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;tablename_&#34;</span>), 
                  df, 
                  overwrite <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>)
DBI<span style="color:#f92672">::</span><span style="color:#a6e22e">dbGetQuery</span>(con, <span style="color:#e6db74">&#34;USE database;
</span><span style="color:#e6db74">EXEC sp_rename &#39;[schema].[tablename_]&#39;, &#39;tablename&#39;;&#34;</span>)
</code></pre></div>]]></description>
        </item>
        
        <item>
            <title>Setting Up Raspberry Pi Temperature/Humidity Sensors for Data Analysis in R</title>
            <link>https://roh.engineering/posts/2019/02/setting-up-raspberry-pi-temperature/humidity-sensors-for-data-analysis-in-r/</link>
            <pubDate>Thu, 21 Feb 2019 00:00:00 +0000</pubDate>
            
            <guid>https://roh.engineering/posts/2019/02/setting-up-raspberry-pi-temperature/humidity-sensors-for-data-analysis-in-r/</guid>
            <description><![CDATA[<p>This tutorial is going to cover how to set up a temperature/humidity sensor with
a raspberry pi. You will learn how to setup the sensor, a MYSQL server, and
connect to the databse remotely in R. I will also do exploratory
data analysis in R with the stored readings. A little bit of familiarity with linux, mysql servers,
soldering skills, and R is helpful but not mandatory. The materials required
are:</p>
<ul>
<li>Raspberry Pi with standard setup (SD card, case, etc.)</li>
<li>Adafruit AM2302 (wired DHT22) temperature-humidity sensor</li>
<li>Soldering Iron</li>
<li>Female Pin Headers</li>
<li>Small piece of wood</li>
</ul>
<p><img src="https://i.imgur.com/LmpZ8RE.jpg" alt="Materials to be used"></p>
<p><em>Materials to be used</em></p>
<p><img src="https://i.imgur.com/hhEagAf.jpg" alt="Final Product"></p>
<p><em>Final Product</em></p>
<p>I mostly followed the tutorial found <a href="https://www.instructables.com/id/Raspberry-Pi-Temperature-Humidity-Network-Monitor/">here</a>.
The majority of the work in this post is not using R. Instead of rebuilding
everything, I wanted to build off of content that has made and sensor readings
are handled a bit better by a low level language (C is used here).</p>
<h1 id="install-wiringpi">Install wiringPi</h1>
<p>We are going to start with the assumption that you have already set up the
raspberry pi and soldered the sensor to the GPIO. An excellent repository already
exists at <a href="http://wiringpi.com/">http://wiringpi.com/</a>. It provides a C interface
to the GPIO that will prevent us from having to write any of the low level code.
I&rsquo;m going to SSH into my headless pi and install the wiringPi program with the
following commands. In the examples, you can build and run a program to check
if you are getting good readings.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">git clone git://git.drogon.net/wiringPi
cd wiringPi
./build
cd examples
make rht03
./rht03
</code></pre></div><p>You should see readings from the sensor now. Type <code>CTRL+c</code> to quit the
program.</p>
<h1 id="set-up-a-mysql-server">Set up a MYSQL Server</h1>
<p>In this step we are going to install MYSQL server and create some security
around it. When you see &lsquo;username&rsquo; or &lsquo;password&rsquo; those are meant for you to
replace with your own credentials. Instead of only using root to access
the server with elevated priviliges, I am going to grant all privileges to
a different user, but only when on the &lsquo;localhost&rsquo;, Essentially, you need to
remote in currently to access the server with your &lsquo;user&rsquo; credentials. Last,
log back into the server with your new user identity for the next step.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">sudo apt-get install mysql-server
sudo apt-get install default-libmysqlclient-dev
sudo mysql_secure_installation
sudo mysql
GRANT ALL PRIVILEGES ON *.* TO <span style="color:#e6db74">&#39;username&#39;</span>@<span style="color:#e6db74">&#39;localhost&#39;</span> IDENTIFIED BY <span style="color:#e6db74">&#39;password&#39;</span>;
<span style="color:#ae81ff">\q</span>
mysql -u <span style="color:#e6db74">&#39;username&#39;</span> -p
</code></pre></div><h1 id="set-up-a-database">Set up a Database</h1>
<p>Now, let&rsquo;s create a database and a table with the time in UNIX integer time and
two other columns for the sensor readings that we want to record.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-sql" data-lang="sql"><span style="color:#66d9ef">create</span> <span style="color:#66d9ef">database</span> Monitoring;
use Monitoring;
<span style="color:#66d9ef">create</span> <span style="color:#66d9ef">table</span> Climate (ComputerTime INTEGER UNSIGNED,Temperature DECIMAL(<span style="color:#ae81ff">5</span>,<span style="color:#ae81ff">1</span>), Humidity DECIMAL(<span style="color:#ae81ff">5</span>,<span style="color:#ae81ff">1</span>));
</code></pre></div><h1 id="run-the-program-to-read-and-write-data">Run the program to read and write data</h1>
<p>You will need to download this file:</p>
<p><a href="https://cdn.instructables.com/ORIG/FV1/SE8A/HOSLXFJA/FV1SE8AHOSLXFJA.c">th.c</a></p>
<p>Change the <code>'root'</code> and <code>'password'</code>
credentials to match the user that you set up earlier. You will need to copy
over the Makefile and change some flags so that the program knows where to
find some of the drivers that it needs.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">cp wiringPi/examples/Makefile ~/raspberrypi/monitor/Makefile
sudo nano ~/raspberrypi/monitor/Makefile
</code></pre></div><p>Add the following lines to the file:</p>
<pre><code>INCLUDE = -I/usr/local/include,/usr/include/mysql
LDFLAGS = -L/usr/local/lib,/usr/lib/arm-linux-gnueabihf -lmysqlclient -lpthread -lz -lm -lrt -ldl
</code></pre><p>Compile the program:</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">make ~/raspberrypi/monintor/th
</code></pre></div><p>You will now run the program that you altered and compiled. Use the <code>&amp;</code> to
run the program continuously in the background. The program will write the
temperature and humidity every 60 seconds to the database.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">./raspberrypi/monitor/th &amp;
</code></pre></div><h1 id="set-up-r">Set up R</h1>
<p>This step is optional but good to have for troubleshooting. Later, I will be
connecting remotely on my laptop instead of working in R on the raspberry pi.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">sudo apt-get install r-base
sudo su - -e <span style="color:#e6db74">&#39;install.packages(&#34;DBI&#34;, &#34;RMariaDB&#34;)&#39;</span>
</code></pre></div><h1 id="check-database-connection-and-query">Check Database Connection and Query</h1>
<p>After a couple hours, you should have a good amount of data. I&rsquo;m going to be
connecting from my laptop so I&rsquo;ll need to set up my user credentials with
privileges to access over my LAN which to cover all ip addresses that get
assigned use the <code>%</code> (wildcard) at the end of <code>192.168.1</code> (your LAN is
already set to use this ip address numbering system).</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-sql" data-lang="sql"><span style="color:#66d9ef">GRANT</span> <span style="color:#66d9ef">ALL</span> <span style="color:#66d9ef">PRIVILEGES</span> <span style="color:#66d9ef">on</span> <span style="color:#f92672">*</span>.<span style="color:#f92672">*</span> <span style="color:#66d9ef">TO</span> <span style="color:#e6db74">&#39;user&#39;</span><span style="color:#f92672">@</span><span style="color:#e6db74">&#39;192.168.1.%&#39;</span> IDENTIFIED <span style="color:#66d9ef">BY</span> <span style="color:#e6db74">&#39;password&#39;</span>;
FLUSH <span style="color:#66d9ef">PRIVILEGES</span>;
<span style="color:#960050;background-color:#1e0010">\</span>q
</code></pre></div><p>Let&rsquo;s make sure that the server has a port that we can access. If it&rsquo;s not
already in the <code>my.conf</code> file, open up the file with a text editor.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">sudo nano /etc/mysql/my.cnf
</code></pre></div><p>Add the following lines to the file which opens up the default port 3306 for
the mysql server and then bind to current IP address.</p>
<pre><code>[msqld]
port=3306
bind-address=0.0.0.0
</code></pre><p>Restart the service for the changes to take effect.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">sudo service mysql restart
</code></pre></div><p>You can log off the machine now. We don&rsquo;t need to do anything else on the
raspberry pi for now.</p>
<h1 id="access-the-data-remotely">Access the Data Remotely</h1>
<p>From RStudio on my laptop (while connected to my LAN), we&rsquo;re going to open
a connection to the database. You can specify the host as a DNS name that
can be set up on your router&rsquo;s administration portal or you can specify the
IP address. I would recommend making the IP address static if you plan on
using that method going forward. Since we stored the timestamp in UNIX
integer form, we can convert it to POSIXct knowing that the origin of UNIX
time is the start of the year 1970.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">library</span>(DBI)
<span style="color:#a6e22e">library</span>(ggplot2)
<span style="color:#a6e22e">library</span>(trstyles) <span style="color:#75715e"># optional package for my styling of ggplot2 plots</span>

con <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">dbConnect</span>(RMariaDB<span style="color:#f92672">::</span><span style="color:#a6e22e">MariaDB</span>(), host <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;sensorpi&#39;</span>, 
                 user <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;pi&#39;</span>, password <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;password&#39;</span>,
                 dbname <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;Monitoring&#39;</span>)
query <span style="color:#f92672">&lt;-</span> <span style="color:#e6db74">&#39;SELECT ComputerTime, Temperature, Humidity FROM Climate&#39;</span>
readings <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">dbGetQuery</span>(con, query)
readings[[<span style="color:#e6db74">&#39;ComputerTime&#39;</span>]] <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">as.POSIXct</span>(readings[[<span style="color:#e6db74">&#39;ComputerTime&#39;</span>]], 
                                         origin <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;1970-01-01 00:00:00&#39;</span>)
</code></pre></div><h1 id="plot-the-data">Plot the Data</h1>
<p>Now that we have the data, let&rsquo;s plot temperature against time to see what has
been going on.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">ggplot</span>(readings) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">geom_line</span>(<span style="color:#a6e22e">aes</span>(ComputerTime, Temperature)) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">scale_y_continuous</span>(name <span style="color:#f92672">=</span> <span style="color:#a6e22e">expression</span>(<span style="color:#e6db74">&#39;Temperature (&#39;</span><span style="color:#f92672">*</span>degree<span style="color:#f92672">*</span><span style="color:#e6db74">&#39;C)&#39;</span>),
                     sec.axis <span style="color:#f92672">=</span> <span style="color:#a6e22e">sec_axis</span>(<span style="color:#f92672">~</span>.*9<span style="color:#f92672">/</span><span style="color:#ae81ff">5+32</span>, 
                                         name <span style="color:#f92672">=</span> 
                                           <span style="color:#a6e22e">expression</span>(<span style="color:#e6db74">&#39;Temperature (&#39;</span><span style="color:#f92672">*</span>degree<span style="color:#f92672">*</span><span style="color:#e6db74">&#39;F)&#39;</span>))) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">scale_x_datetime</span>(name <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;&#39;</span>, date_breaks <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;2 days&#39;</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">theme_tr</span>(base_size <span style="color:#f92672">=</span> <span style="color:#ae81ff">18</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">theme</span>(axis.text.x <span style="color:#f92672">=</span> <span style="color:#a6e22e">element_text</span>(angle <span style="color:#f92672">=</span> <span style="color:#ae81ff">90</span>, vjust <span style="color:#f92672">=</span> <span style="color:#ae81ff">.5</span>))
</code></pre></div><p>It looks good for the most part, but we definitely have some outlier readings.
I can see probably outliers at 30 degrees Celsius. I&rsquo;m going to cut those off
and take a second look.</p>
<p><img src="https://i.imgur.com/VXXtKQS.png" alt=""></p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">readings[[<span style="color:#e6db74">&#39;Temperature&#39;</span>]][readings[[<span style="color:#e6db74">&#39;Temperature&#39;</span>]] <span style="color:#f92672">&gt;</span> <span style="color:#ae81ff">30</span>] <span style="color:#f92672">&lt;-</span> <span style="color:#66d9ef">NA</span>
<span style="color:#a6e22e">ggplot</span>(readings) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">geom_line</span>(<span style="color:#a6e22e">aes</span>(ComputerTime, Temperature)) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">scale_y_continuous</span>(name <span style="color:#f92672">=</span> <span style="color:#a6e22e">expression</span>(<span style="color:#e6db74">&#39;Temperature (&#39;</span><span style="color:#f92672">*</span>degree<span style="color:#f92672">*</span><span style="color:#e6db74">&#39;C)&#39;</span>),
                     sec.axis <span style="color:#f92672">=</span> <span style="color:#a6e22e">sec_axis</span>(<span style="color:#f92672">~</span>.*9<span style="color:#f92672">/</span><span style="color:#ae81ff">5+32</span>, 
                                         name <span style="color:#f92672">=</span> 
                                           <span style="color:#a6e22e">expression</span>(<span style="color:#e6db74">&#39;Temperature (&#39;</span><span style="color:#f92672">*</span>degree<span style="color:#f92672">*</span><span style="color:#e6db74">&#39;F)&#39;</span>))) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">scale_x_datetime</span>(name <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;&#39;</span>, date_breaks <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;2 days&#39;</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">theme_tr</span>(base_size <span style="color:#f92672">=</span> <span style="color:#ae81ff">18</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">theme</span>(axis.text.x <span style="color:#f92672">=</span> <span style="color:#a6e22e">element_text</span>(angle <span style="color:#f92672">=</span> <span style="color:#ae81ff">90</span>, vjust <span style="color:#f92672">=</span> <span style="color:#ae81ff">.5</span>))
</code></pre></div><p><img src="https://i.imgur.com/OrfoUUG.png" alt=""></p>
<p>You can see some patterns already existing within the data. Given how the
weather patterns have been, adding in some outside temperature readings would
provide some more insight into what is going on. I&rsquo;ll dive into some more
analysis in another post.</p>
<p>We can do the same for the relative humidity.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">ggplot</span>(readings) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">geom_line</span>(<span style="color:#a6e22e">aes</span>(ComputerTime, Humidity), color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;#9D5863&#39;</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">scale_y_continuous</span>(name <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;Relative Humidity (Rh)&#39;</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">scale_x_datetime</span>(name <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;&#39;</span>, date_breaks <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;2 days&#39;</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">theme_tr</span>(base_size <span style="color:#f92672">=</span> <span style="color:#ae81ff">18</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">theme</span>(axis.text.x <span style="color:#f92672">=</span> <span style="color:#a6e22e">element_text</span>(angle <span style="color:#f92672">=</span> <span style="color:#ae81ff">90</span>, vjust <span style="color:#f92672">=</span> <span style="color:#ae81ff">.5</span>))
</code></pre></div><p><img src="https://i.imgur.com/h4DUvD8.png" alt=""></p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">readings[[<span style="color:#e6db74">&#39;Humidity&#39;</span>]][readings[[<span style="color:#e6db74">&#39;Humidity&#39;</span>]] <span style="color:#f92672">&gt;</span> <span style="color:#ae81ff">50</span>] <span style="color:#f92672">&lt;-</span> <span style="color:#66d9ef">NA</span>
<span style="color:#a6e22e">ggplot</span>(readings) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">geom_line</span>(<span style="color:#a6e22e">aes</span>(ComputerTime, Humidity), color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;#9D5863&#39;</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">scale_y_continuous</span>(name <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;Relative Humidity (Rh)&#39;</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">scale_x_datetime</span>(name <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;&#39;</span>, date_breaks <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;2 days&#39;</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">theme_tr</span>(base_size <span style="color:#f92672">=</span> <span style="color:#ae81ff">18</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">theme</span>(axis.text.x <span style="color:#f92672">=</span> <span style="color:#a6e22e">element_text</span>(angle <span style="color:#f92672">=</span> <span style="color:#ae81ff">90</span>, vjust <span style="color:#f92672">=</span> <span style="color:#ae81ff">.5</span>))
</code></pre></div><p><img src="https://i.imgur.com/wd1QyxE.png" alt=""></p>
<p>And that&rsquo;s it. You have your very own indoor climate monitoring system and
time series data to play around with at home.</p>
]]></description>
        </item>
        
        <item>
            <title>Shiny App: Drive Time Isochrones</title>
            <link>https://roh.engineering/posts/2018/11/shiny-app-drive-time-isochrones/</link>
            <pubDate>Mon, 05 Nov 2018 00:00:00 +0000</pubDate>
            
            <guid>https://roh.engineering/posts/2018/11/shiny-app-drive-time-isochrones/</guid>
            <description><![CDATA[<p>The <a href="http://project-osrm.org/">Open Source Routing Machine</a> project is an excellent
resource for computing routing and travel time estimates for road networks. It is
an open source library that has a demo server to run API requests to.
I&rsquo;ll only be using one of the services (isochrones which I&rsquo;ll explain below)
in this blog post. To access the API there is a wonderful R package <a href="https://cran.r-project.org/web/packages/osrm/index.html">osrm</a> that simplifies
the necessary code.</p>
<p>For various urban/transportation planning or market analysis, one will probably be interested
in the possible areas that can be reached by road within a certain amount of time. A
representation of that is called an isochrone. An isochrone is a spatial object
typically a polygon or multipolygon that shows a geographic region that can reach
a point within the specified travel time parameters. Programmatically in R,
all we need to do is specific the latitude and longtitude of interest and the
travel time.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">library</span>(osrm)
<span style="color:#a6e22e">osrmIsochrone</span>(<span style="color:#a6e22e">c</span>(<span style="color:#ae81ff">-95.9345</span>,<span style="color:#ae81ff">41.2565</span>), breaks <span style="color:#f92672">=</span> <span style="color:#ae81ff">10</span>)
</code></pre></div><p>The <code>osrm</code> package has some options behind the scenes that are preset for you.
The call above has set the server to the demo server (you can set up your own server
for reliability) and it has set the mode of transportation to &ldquo;driving&rdquo;. To
change the profile, you have to adjust the option &ldquo;osrm.profile&rdquo;. I&rsquo;ve been able to use
&ldquo;driving&rdquo;, &ldquo;bike&rdquo;, and &ldquo;walk&rdquo; so far. You can find more documentation here:
<a href="http://project-osrm.org/docs/v5.15.2/api/#general-options">OSRM Documentation</a> and
<a href="https://github.com/rCarto/osrm">osrm Github</a>.</p>
<p>I&rsquo;ve created a shiny app to show an example of building a sharp
interface for end users to easily specify the parameters and download the
geojson or shapefile for other uses. The app is in showcase mode (code is at the bottom)
so you can see what else is going on behind the scenes with the <code>sf</code> and <code>leaflet</code> package.</p>
<iframe src="https://troh.shinyapps.io/osrmIsochrone/" frameborder=0 width="100%" height=800px></iframe>
<p><a href="https://troh.shinyapps.io/osrmIsochrone/">Link to application</a></p>
]]></description>
        </item>
        
        <item>
            <title>Introduction to Geospatial Analysis in R</title>
            <link>https://roh.engineering/posts/2018/09/introduction-to-geospatial-analysis-in-r/</link>
            <pubDate>Sun, 30 Sep 2018 00:00:00 +0000</pubDate>
            
            <guid>https://roh.engineering/posts/2018/09/introduction-to-geospatial-analysis-in-r/</guid>
            <description><![CDATA[<p>Slides from my presentation at Heartland Developer Conference in La Vista, NE.</p>
<iframe src="rgis-tutorial/rgis_tutorial_website.html" width="672" height="600"></iframe>
]]></description>
        </item>
        
        <item>
            <title>Shiny Gadget: Fit Distributions</title>
            <link>https://roh.engineering/posts/2018/09/shiny-gadget-fit-distributions/</link>
            <pubDate>Sun, 02 Sep 2018 00:00:00 +0000</pubDate>
            
            <guid>https://roh.engineering/posts/2018/09/shiny-gadget-fit-distributions/</guid>
            <description><![CDATA[<p>The &lsquo;Fit Distributions&rsquo; shiny gadget allows easy automated diagnostics for
fitting univariate distributions. It reads in numeric vectors in the global
environment, and uses MLE to estimate the parameters of the selected distributions.
The visual outputs are GOF statistics, density plot, pp-plot, and qq-plot. You
can also adjust the number of bins for the histogram. It currently only supports continuous distributions.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">install.packages</span>(<span style="color:#e6db74">&#39;fitur&#39;</span>)

<span style="color:#a6e22e">library</span>(fitur)
<span style="color:#a6e22e">library</span>(actuar)
x <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">rnorm</span>(<span style="color:#ae81ff">1000</span>)
y <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">rweibull</span>(<span style="color:#ae81ff">1000</span>, <span style="color:#ae81ff">1</span>)
df <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">dataframe</span>(x, y)
fitur<span style="color:#f92672">::</span><span style="color:#a6e22e">fit_dist_addin</span>()
</code></pre></div><br>
<p><a href="https://imgur.com/5tTmzJ1"><img src="https://i.imgur.com/5tTmzJ1.gif" title="source: imgur.com"></a></p>
]]></description>
        </item>
        
        <item>
            <title>fitur 0.6.1 Release</title>
            <link>https://roh.engineering/posts/2018/09/fitur-0.6.1-release/</link>
            <pubDate>Sat, 01 Sep 2018 00:00:00 +0000</pubDate>
            
            <guid>https://roh.engineering/posts/2018/09/fitur-0.6.1-release/</guid>
            <description><![CDATA[<h1 id="fitur-061">fitur 0.6.1</h1>
<ul>
<li>
<p>shiny gadget for fitting univariate distributions has been added</p>
</li>
<li>
<p>added test function for distfun objects</p>
</li>
<li>
<p>diagnostic plots now have better checks for distfun objects and lists of
distfun objects</p>
</li>
</ul>
<p>fitur on <a href="https://cran.r-project.org/web/packages/fitur/index.html">CRAN</a></p>
]]></description>
        </item>
        
        <item>
            <title>fitur 0.6.0 Release</title>
            <link>https://roh.engineering/posts/2018/08/fitur-0.6.0-release/</link>
            <pubDate>Sun, 05 Aug 2018 00:00:00 +0000</pubDate>
            
            <guid>https://roh.engineering/posts/2018/08/fitur-0.6.0-release/</guid>
            <description><![CDATA[<ul>
<li>
<p>Adding continuous distribution testing functions Kolmogorov-Smirnov, Anderson-Darling, and Cramer-Von Mises</p>
</li>
<li>
<p>S3 methods have now been added for distfit objects</p>
</li>
<li>
<p>Code reformatting and cleanup</p>
</li>
</ul>
<p>fitur on <a href="https://cran.r-project.org/web/packages/fitur/index.html">CRAN</a></p>
<h2 id="continuous-distribution-gof-tests">Continuous Distribution GOF Tests</h2>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">library</span>(fitur)
</code></pre></div><pre><code>## Warning: replacing previous import 'vctrs::data_frame' by 'tibble::data_frame'
## when loading 'dplyr'
</code></pre><div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">x <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">rgamma</span>(<span style="color:#ae81ff">100</span>, <span style="color:#ae81ff">1</span>, <span style="color:#ae81ff">1</span>)
fit <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">fit_univariate</span>(x, <span style="color:#e6db74">&#39;gamma&#39;</span>)
<span style="color:#a6e22e">ks_test</span>(fit, x)
</code></pre></div><pre><code>## 
## 	One-sample Kolmogorov-Smirnov test
## 
## data:  x
## D = 0.043386, p-value = 0.9918
## alternative hypothesis: two-sided
</code></pre><div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">ad_test</span>(fit, x)
</code></pre></div><pre><code>## 
## 	Anderson-Darling test of goodness-of-fit
## 	Null hypothesis: distribution 'distfun[[2]]'
## 	Parameters assumed to be fixed
## 
## data:  x
## An = 0.27471, p-value = 0.9558
</code></pre><div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">cvm_test</span>(fit, x)
</code></pre></div><pre><code>## 
## 	Cramer-von Mises test of goodness-of-fit
## 	Null hypothesis: distribution 'distfun[[2]]'
## 	Parameters assumed to be fixed
## 
## data:  x
## omega2 = 0.034495, p-value = 0.9599
</code></pre>]]></description>
        </item>
        
        <item>
            <title>Speed Up Shiny Coding with Data</title>
            <link>https://roh.engineering/posts/2018/06/speed-up-shiny-coding-with-data/</link>
            <pubDate>Wed, 20 Jun 2018 00:00:00 +0000</pubDate>
            
            <guid>https://roh.engineering/posts/2018/06/speed-up-shiny-coding-with-data/</guid>
            <description><![CDATA[<h1 id="introduction">Introduction</h1>
<p>In this excercise, I&rsquo;m going to show how to automate some aspects of coding in
<a href="https://cran.r-project.org/web/packages/shiny/index.html">shiny</a> to speed up development. Traditionally, in user interface development, one has to explicitly
type out each individual input argument. For small applications, this is
justified and probably isn&rsquo;t worth the time to automate the task. The first
part goes over using <a href="https://en.wikipedia.org/wiki/Functional_programming">functional programming</a>
to loop through data and utilize its
characteristics to create the inputs. These same concepts will be used in the
second part to do the same with the outputs of in the server file that one
wants to manipulate. This requires a little more tweaking because of the nature
of the logic in shiny, but you will see how greatly you can reduce the amount of
code that needs to be written.</p>
<h1 id="looping-inputs">Looping Inputs</h1>
<p>Below I&rsquo;m using the <strong>diamonds</strong> dataset from the <a href="https://cran.r-project.org/web/packages/ggplot2/index.html">ggplot2</a> package.
This dataset has several different data types in the <code>data.frame</code> where you can
use base R functions to find the data types. Using control logic, it is easy to
specify different shiny input funtions that you will only have to write once. I&rsquo;ve
included the <strong>id</strong> argument as a way to name the inputs and be able to call
them later. <code>mapply</code> allows me to apply the <code>build_shiny_input</code> function to
each column in the <code>data.frame</code> and tag the input with the name. Hint: When
using mapply on shiny inputs, you need to specify <code>SIMPLIFY = FALSE</code>.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">library</span>(shiny)
<span style="color:#a6e22e">library</span>(shinythemes)
<span style="color:#a6e22e">library</span>(ggplot2)
<span style="color:#a6e22e">library</span>(trstyles) <span style="color:#75715e"># to run code replace theme_tr()</span>
<span style="color:#a6e22e">data</span>(<span style="color:#e6db74">&#34;diamonds&#34;</span>)
<span style="color:#a6e22e">set.seed</span>(<span style="color:#ae81ff">311</span>)
diamonds[[<span style="color:#e6db74">&#39;randomGroups&#39;</span>]] <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">sample</span>(<span style="color:#a6e22e">as.character</span>(<span style="color:#ae81ff">1</span><span style="color:#f92672">:</span><span style="color:#ae81ff">5</span>), 
                                     <span style="color:#a6e22e">nrow</span>(diamonds), 
                                     replace <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>)
build_shiny_input <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">function</span>(x, id) {
  <span style="color:#a6e22e">if </span>(<span style="color:#a6e22e">is.double</span>(x)) {
    <span style="color:#a6e22e">sliderInput</span>(id, id, min <span style="color:#f92672">=</span> <span style="color:#a6e22e">min</span>(x), max <span style="color:#f92672">=</span> <span style="color:#a6e22e">max</span>(x), value <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#a6e22e">min</span>(x), <span style="color:#a6e22e">max</span>(x)))
  } else <span style="color:#a6e22e">if </span>(<span style="color:#a6e22e">is.ordered</span>(x)) {
    <span style="color:#a6e22e">selectInput</span>(id, id, choices <span style="color:#f92672">=</span> <span style="color:#a6e22e">unique</span>(<span style="color:#a6e22e">sort</span>(x)),
                selected <span style="color:#f92672">=</span> <span style="color:#a6e22e">as.character</span>(<span style="color:#a6e22e">unique</span>(<span style="color:#a6e22e">sort</span>(x))), multiple <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>)
  } else <span style="color:#a6e22e">if </span>(<span style="color:#a6e22e">is.factor</span>(x) <span style="color:#f92672">|</span> <span style="color:#a6e22e">is.character</span>(x)) {
    <span style="color:#a6e22e">checkboxGroupInput</span>(id, id, choices <span style="color:#f92672">=</span> <span style="color:#a6e22e">sort</span>(<span style="color:#a6e22e">unique</span>(x)),
                       selected <span style="color:#f92672">=</span> <span style="color:#a6e22e">sort</span>(<span style="color:#a6e22e">unique</span>(x)))
  } else <span style="color:#a6e22e">if </span>(<span style="color:#a6e22e">is.integer</span>(x)) {
    <span style="color:#a6e22e">sliderInput</span>(id, id, value <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#a6e22e">min</span>(x),<span style="color:#a6e22e">max</span>(x)), 
                step <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>, min <span style="color:#f92672">=</span> <span style="color:#a6e22e">min</span>(x), max <span style="color:#f92672">=</span> <span style="color:#a6e22e">max</span>(x))
  } else {
    <span style="color:#66d9ef">NULL</span>
  }
}
shinyInputs <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">mapply</span>(diamonds, 
                      id <span style="color:#f92672">=</span> <span style="color:#a6e22e">names</span>(diamonds), 
                      FUN <span style="color:#f92672">=</span> build_shiny_input,
                      SIMPLIFY <span style="color:#f92672">=</span> <span style="color:#66d9ef">FALSE</span>)
</code></pre></div><h1 id="ui">UI</h1>
<p>The above code can be rendered outside of the UI allowing the app to only have
to render it once. Now I can put all 11 of the shiny inputs with one line of
code which greatly reduces the complexity seen in the <code>ui</code>.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">ui <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">fluidPage</span>(theme <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;flatly&#39;</span>,
   
   <span style="color:#a6e22e">titlePanel</span>(<span style="color:#e6db74">&#34;Dynamic Shiny UI&#34;</span>),
   
   <span style="color:#a6e22e">sidebarLayout</span>(
      <span style="color:#a6e22e">sidebarPanel</span>(
         <span style="color:#a6e22e">tagList</span>(shinyInputs)
      ),
      
      <span style="color:#a6e22e">mainPanel</span>(
         <span style="color:#a6e22e">h5</span>(<span style="color:#e6db74">&#34;Generated Inputs&#34;</span>),
         <span style="color:#a6e22e">textOutput</span>(<span style="color:#e6db74">&#34;inputNames&#34;</span>),
         <span style="color:#a6e22e">h5</span>(<span style="color:#e6db74">&#34;Generated Outputs&#34;</span>),
         <span style="color:#a6e22e">uiOutput</span>(<span style="color:#e6db74">&#34;plots&#34;</span>)
         
      )
   )
)
</code></pre></div><p>The next part is a little trickier. You can once again specify different plot
types based on the data type from the <strong>diamonds</strong> dataset. I&rsquo;m using the
<code>tagList</code> function to encapsulate the plot and break tags. I&rsquo;m using a little
bit of <a href="">rlang</a> magic as well to convert the text id to a symbol and evaluating
in the <code>geom_</code> call.</p>
<h1 id="looping-outputs">Looping Outputs</h1>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">render_plot_data <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">function</span>(inputName, shinyInput) {
  x <span style="color:#f92672">&lt;-</span> diamonds[[inputName]]
  <span style="color:#a6e22e">if </span>(<span style="color:#a6e22e">is.double</span>(x)) {
    i <span style="color:#f92672">&lt;-</span> x <span style="color:#f92672">&gt;=</span> shinyInput[[inputName]][1] <span style="color:#f92672">&amp;</span> x <span style="color:#f92672">&lt;=</span> shinyInput[[inputName]][2]
    g <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">ggplot</span>(diamonds[i, ]) <span style="color:#f92672">+</span>
      <span style="color:#a6e22e">geom_density</span>(<span style="color:#a6e22e">aes</span>(<span style="color:#f92672">!!</span><span style="color:#a6e22e">sym</span>(inputName))) <span style="color:#f92672">+</span>
      <span style="color:#a6e22e">theme_tr</span>() <span style="color:#f92672">+</span>
      <span style="color:#a6e22e">theme</span>(panel.background <span style="color:#f92672">=</span> <span style="color:#a6e22e">element_rect</span>(fill <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;transparent&#39;</span>),
            plot.background <span style="color:#f92672">=</span> <span style="color:#a6e22e">element_rect</span>(fill <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;transparent&#39;</span>,
                                           color <span style="color:#f92672">=</span> <span style="color:#66d9ef">NA</span>))
    <span style="color:#a6e22e">tagList</span>(<span style="color:#a6e22e">renderPlot</span>(g), <span style="color:#a6e22e">br</span>())
  } else <span style="color:#a6e22e">if </span>(<span style="color:#a6e22e">is.character</span>(x) <span style="color:#f92672">|</span> <span style="color:#a6e22e">is.factor</span>(x)) {
    i <span style="color:#f92672">&lt;-</span> x <span style="color:#f92672">%in%</span> shinyInput[[inputName]]
    g <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">ggplot</span>(diamonds[i, ]) <span style="color:#f92672">+</span>
      <span style="color:#a6e22e">geom_bar</span>(<span style="color:#a6e22e">aes</span>(<span style="color:#f92672">!!</span><span style="color:#a6e22e">sym</span>(inputName))) <span style="color:#f92672">+</span>
      <span style="color:#a6e22e">theme_tr</span>() <span style="color:#f92672">+</span>
      <span style="color:#a6e22e">theme</span>(panel.background <span style="color:#f92672">=</span> <span style="color:#a6e22e">element_rect</span>(fill <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;transparent&#39;</span>),
            plot.background <span style="color:#f92672">=</span> <span style="color:#a6e22e">element_rect</span>(fill <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;transparent&#39;</span>,
                                           color <span style="color:#f92672">=</span> <span style="color:#66d9ef">NA</span>))
    <span style="color:#a6e22e">tagList</span>(<span style="color:#a6e22e">renderPlot</span>(g), <span style="color:#a6e22e">br</span>())
  } else <span style="color:#66d9ef">NULL</span>
}
</code></pre></div><h1 id="server">Server</h1>
<p>To show that the input naming ids worked. The first part just renders the ids
of the shiny inputs into text. <code>renderUI</code> can be used to not only create
dynamic inputs but dynamic outputs as well. Using <code>lapply</code> now, you only need
to pass in the shiny input id to be able to call to it in the <code>render_plot_data</code>
function. Once again, you see how much you are able to hide the underlying
complexity in the <code>server</code>.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">server <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">function</span>(input, output) {
   reactDiamonds <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">reactive</span>({
     <span style="color:#a6e22e">names</span>(input)
   })
   output<span style="color:#f92672">$</span>inputNames <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">renderText</span>(<span style="color:#a6e22e">reactDiamonds</span>())
   <span style="color:#a6e22e">observe</span>({
     output<span style="color:#f92672">$</span>plots <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">renderUI</span>({
       <span style="color:#a6e22e">lapply</span>(<span style="color:#a6e22e">names</span>(input),
              shinyInput <span style="color:#f92672">=</span> input,
              render_plot_data)
     })
   })
}
</code></pre></div><h1 id="end-product">End Product</h1>
<p>And thats it! With just a little bit of code, you can do some powerful things
with <code>shiny</code>. Let the data do the work. Resources for learning more are listed below with the full code
to try out as well. Here&rsquo;s a snapshot of the end product:</p>
<p><a href="https://imgur.com/QJtWS4e"><img src="https://i.imgur.com/QJtWS4e.gif" title="source: imgur.com" /></a></p>
<h1 id="further-reading">Further Reading</h1>
<p><a href="https://shiny.rstudio.com/gallery/creating-a-ui-from-a-loop.html">Creating a UI from a loop</a></p>
<p><a href="https://stackoverflow.com/questions/31686773/shiny-dynamic-number-of-output-elements-plots">Shiny Dynamic Number of Output Element Plots</a></p>
<h1 id="full-code">Full Code</h1>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">library</span>(shiny)
<span style="color:#a6e22e">library</span>(shinythemes)
<span style="color:#a6e22e">library</span>(ggplot2)
<span style="color:#a6e22e">data</span>(<span style="color:#e6db74">&#34;diamonds&#34;</span>)
<span style="color:#a6e22e">set.seed</span>(<span style="color:#ae81ff">311</span>)
diamonds[[<span style="color:#e6db74">&#39;randomGroups&#39;</span>]] <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">sample</span>(<span style="color:#a6e22e">as.character</span>(<span style="color:#ae81ff">1</span><span style="color:#f92672">:</span><span style="color:#ae81ff">5</span>), 
                                     <span style="color:#a6e22e">nrow</span>(diamonds), 
                                     replace <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>)

build_shiny_input <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">function</span>(x, id) {
  <span style="color:#a6e22e">if </span>(<span style="color:#a6e22e">is.double</span>(x)) {
    <span style="color:#a6e22e">sliderInput</span>(id, id, min <span style="color:#f92672">=</span> <span style="color:#a6e22e">min</span>(x), max <span style="color:#f92672">=</span> <span style="color:#a6e22e">max</span>(x), value <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#a6e22e">min</span>(x), <span style="color:#a6e22e">max</span>(x)))
  } else <span style="color:#a6e22e">if </span>(<span style="color:#a6e22e">is.ordered</span>(x)) {
    <span style="color:#a6e22e">selectInput</span>(id, id, choices <span style="color:#f92672">=</span> <span style="color:#a6e22e">unique</span>(<span style="color:#a6e22e">sort</span>(x)),
                selected <span style="color:#f92672">=</span> <span style="color:#a6e22e">as.character</span>(<span style="color:#a6e22e">unique</span>(<span style="color:#a6e22e">sort</span>(x))), multiple <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>)
  } else <span style="color:#a6e22e">if </span>(<span style="color:#a6e22e">is.factor</span>(x) <span style="color:#f92672">|</span> <span style="color:#a6e22e">is.character</span>(x)) {
    <span style="color:#a6e22e">checkboxGroupInput</span>(id, id, choices <span style="color:#f92672">=</span> <span style="color:#a6e22e">sort</span>(<span style="color:#a6e22e">unique</span>(x)),
                       selected <span style="color:#f92672">=</span> <span style="color:#a6e22e">sort</span>(<span style="color:#a6e22e">unique</span>(x)))
  } else <span style="color:#a6e22e">if </span>(<span style="color:#a6e22e">is.integer</span>(x)) {
    <span style="color:#a6e22e">sliderInput</span>(id, id, value <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#a6e22e">min</span>(x),<span style="color:#a6e22e">max</span>(x)), 
                step <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>, min <span style="color:#f92672">=</span> <span style="color:#a6e22e">min</span>(x), max <span style="color:#f92672">=</span> <span style="color:#a6e22e">max</span>(x))
  } else {
    <span style="color:#66d9ef">NULL</span>
  }
}

render_plot_data <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">function</span>(inputName, shinyInput) {
  x <span style="color:#f92672">&lt;-</span> diamonds[[inputName]]
  <span style="color:#a6e22e">if </span>(<span style="color:#a6e22e">is.double</span>(x)) {
    i <span style="color:#f92672">&lt;-</span> x <span style="color:#f92672">&gt;=</span> shinyInput[[inputName]][1] <span style="color:#f92672">&amp;</span> x <span style="color:#f92672">&lt;=</span> shinyInput[[inputName]][2]
    g <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">ggplot</span>(diamonds[i, ]) <span style="color:#f92672">+</span>
      <span style="color:#a6e22e">geom_density</span>(<span style="color:#a6e22e">aes</span>(<span style="color:#f92672">!!</span><span style="color:#a6e22e">sym</span>(inputName))) <span style="color:#f92672">+</span>
      <span style="color:#a6e22e">theme_bw</span>() <span style="color:#f92672">+</span>
      <span style="color:#a6e22e">theme</span>(panel.background <span style="color:#f92672">=</span> <span style="color:#a6e22e">element_rect</span>(fill <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;transparent&#39;</span>),
            plot.background <span style="color:#f92672">=</span> <span style="color:#a6e22e">element_rect</span>(fill <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;transparent&#39;</span>,
                                           color <span style="color:#f92672">=</span> <span style="color:#66d9ef">NA</span>))
    <span style="color:#a6e22e">tagList</span>(<span style="color:#a6e22e">renderPlot</span>(g), <span style="color:#a6e22e">br</span>())
  } else <span style="color:#a6e22e">if </span>(<span style="color:#a6e22e">is.character</span>(x) <span style="color:#f92672">|</span> <span style="color:#a6e22e">is.factor</span>(x)) {
    i <span style="color:#f92672">&lt;-</span> x <span style="color:#f92672">%in%</span> shinyInput[[inputName]]
    g <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">ggplot</span>(diamonds[i, ]) <span style="color:#f92672">+</span>
      <span style="color:#a6e22e">geom_bar</span>(<span style="color:#a6e22e">aes</span>(<span style="color:#f92672">!!</span><span style="color:#a6e22e">sym</span>(inputName))) <span style="color:#f92672">+</span>
      <span style="color:#a6e22e">theme_bw</span>() <span style="color:#f92672">+</span>
      <span style="color:#a6e22e">theme</span>(panel.background <span style="color:#f92672">=</span> <span style="color:#a6e22e">element_rect</span>(fill <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;transparent&#39;</span>),
            plot.background <span style="color:#f92672">=</span> <span style="color:#a6e22e">element_rect</span>(fill <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;transparent&#39;</span>,
                                           color <span style="color:#f92672">=</span> <span style="color:#66d9ef">NA</span>))
    <span style="color:#a6e22e">tagList</span>(<span style="color:#a6e22e">renderPlot</span>(g), <span style="color:#a6e22e">br</span>())
  } else <span style="color:#66d9ef">NULL</span>
}

shinyInputs <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">mapply</span>(diamonds, 
                      id <span style="color:#f92672">=</span> <span style="color:#a6e22e">names</span>(diamonds), 
                      FUN <span style="color:#f92672">=</span> build_shiny_input,
                      SIMPLIFY <span style="color:#f92672">=</span> <span style="color:#66d9ef">FALSE</span>)

ui <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">fluidPage</span>(theme <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;flatly&#39;</span>,
   
   <span style="color:#a6e22e">titlePanel</span>(<span style="color:#e6db74">&#34;Dynamic Shiny UI&#34;</span>),
   
   <span style="color:#a6e22e">sidebarLayout</span>(
      <span style="color:#a6e22e">sidebarPanel</span>(
         <span style="color:#a6e22e">tagList</span>(shinyInputs)
      ),
      
      <span style="color:#a6e22e">mainPanel</span>(
         <span style="color:#a6e22e">h3</span>(<span style="color:#e6db74">&#34;Generated Inputs&#34;</span>),
         <span style="color:#a6e22e">textOutput</span>(<span style="color:#e6db74">&#34;inputNames&#34;</span>),
         <span style="color:#a6e22e">uiOutput</span>(<span style="color:#e6db74">&#34;plots&#34;</span>)
         
      )
   )
)

server <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">function</span>(input, output) {
   reactDiamonds <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">reactive</span>({
     <span style="color:#a6e22e">names</span>(input)
   })
   output<span style="color:#f92672">$</span>inputNames <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">renderText</span>(<span style="color:#a6e22e">reactDiamonds</span>())
   <span style="color:#a6e22e">observe</span>({
     output<span style="color:#f92672">$</span>plots <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">renderUI</span>({
       <span style="color:#a6e22e">lapply</span>(<span style="color:#a6e22e">names</span>(input),
              shinyInput <span style="color:#f92672">=</span> input,
              render_plot_data)
     })
   })
}

<span style="color:#a6e22e">shinyApp</span>(ui <span style="color:#f92672">=</span> ui, server <span style="color:#f92672">=</span> server)
</code></pre></div>]]></description>
        </item>
        
        <item>
            <title>Animating a Monte Carlo Simulation</title>
            <link>https://roh.engineering/posts/2018/05/animating-a-monte-carlo-simulation/</link>
            <pubDate>Sat, 19 May 2018 00:00:00 +0000</pubDate>
            
            <guid>https://roh.engineering/posts/2018/05/animating-a-monte-carlo-simulation/</guid>
            <description><![CDATA[<h1 id="introduction">Introduction</h1>
<p>Oftentimes, I run into difficulty trying to explain some of the concepts of
statistical sampling with audiences that either have very limited or no
understanding of statistics. Given that the majority of communication of analysis
has to be digested in a 1-2 hour meeting, data visualization typically is the
best route for communicating my methods.</p>
<p>One such case is unboxing how sampling works based on your presumed population
and using that sampling to build a monte carlo simulation. I&rsquo;m a big fan of
interactive visualizations or animations that break down in detail the
underpinnings of an analysis. The basis of this post is to demonstrate
using <a href="https://cran.r-project.org/web/packages/ggplot2/index.html">ggplot2</a>
to construct the frames of the animation and
<a href="http://www.imagemagick.org/script/index.php">ImageMagick</a> to combine the frames
into a gif of a simple monte carlo simulation.</p>
<h1 id="generate-the-data">Generate the Data</h1>
<p>First, I&rsquo;m going to use base R&rsquo;s random sampling functions for the Poisson and
the Negative Binomial to generate samples given the presumed parameters. The
numbers are then added together to show a very basic monte carlo simulation.
In addition, a &ldquo;slice&rdquo; of the data is taken that I&rsquo;m going to use later to break
down each step of the simulation.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">library</span>(ggplot2)
<span style="color:#a6e22e">library</span>(trstyles)
<span style="color:#a6e22e">library</span>(dplyr)
<span style="color:#a6e22e">library</span>(tidyr)
<span style="color:#a6e22e">set.seed</span>(<span style="color:#ae81ff">82</span>)
n <span style="color:#f92672">&lt;-</span> <span style="color:#ae81ff">10000</span>
mcHist <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">data_frame</span>(Poisson <span style="color:#f92672">=</span> <span style="color:#a6e22e">rpois</span>(n, <span style="color:#ae81ff">3</span>), 
                  NegBinom <span style="color:#f92672">=</span> <span style="color:#a6e22e">rnbinom</span>(n, <span style="color:#ae81ff">5</span>, <span style="color:#ae81ff">.5</span>)) <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">mutate</span>(Simulation <span style="color:#f92672">=</span> Poisson <span style="color:#f92672">+</span> NegBinom) <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">gather</span>(Distribution, Value) <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">mutate</span>(Distribution <span style="color:#f92672">=</span> <span style="color:#a6e22e">sub</span>(<span style="color:#e6db74">&#34;NegBinom&#34;</span>, <span style="color:#e6db74">&#34;Negative Binomial&#34;</span>, Distribution))

mcSample <span style="color:#f92672">&lt;-</span> mcHist <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">group_by</span>(Distribution) <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">slice</span>(<span style="color:#ae81ff">1</span><span style="color:#f92672">:</span><span style="color:#ae81ff">200</span>) <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">gather</span>(Distribution, Value) <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">group_by</span>(Distribution) <span style="color:#f92672">%&gt;%</span>
  <span style="color:#a6e22e">mutate</span>(rowNum <span style="color:#f92672">=</span> <span style="color:#a6e22e">row_number</span>(Distribution))

<span style="color:#a6e22e">lapply</span>(<span style="color:#a6e22e">split</span>(mcHist[[<span style="color:#e6db74">&#39;Value&#39;</span>]], mcHist[[<span style="color:#e6db74">&#39;Distribution&#39;</span>]]), summary)
</code></pre></div><pre><code>$`Negative Binomial`
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  0.000   3.000   4.000   5.017   7.000  25.000 

$Poisson
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  0.000   2.000   3.000   2.991   4.000  12.000 

$Simulation
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  0.000   5.000   8.000   8.008  10.000  29.000 
</code></pre><h1 id="histogram-of-expected-results">Histogram of Expected Results</h1>
<p>The background image that I want to show is what is the theoretical model that we
are moving towards. I created a large sample of 10,000 so that random number
generators will give a close approximation of the population (the presumed
distributions). I chose discrete distributions above so that it will be easy to
plot histograms without having to worry about the bin widths. With a little
tweaking using <code>facet_grid</code> and <code>geom_text</code>, I can lay out each distribution and
annotate the calculation.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">g <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">ggplot</span>(mcHist) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">geom_histogram</span>(<span style="color:#a6e22e">aes</span>(Value, ..density.., color <span style="color:#f92672">=</span> Distribution), 
                 binwidth <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>, alpha <span style="color:#f92672">=</span> <span style="color:#ae81ff">.3</span>, fill <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;transparent&#34;</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">scale_color_tr</span>(guide <span style="color:#f92672">=</span> <span style="color:#66d9ef">FALSE</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">facet_grid</span>(<span style="color:#f92672">~</span>Distribution) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">theme_tr</span>() <span style="color:#f92672">+</span> 
  <span style="color:#a6e22e">coord_cartesian</span>(ylim <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#ae81ff">0</span>, <span style="color:#ae81ff">.23</span>)) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">labs</span>(x <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;&#34;</span>, y <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;Frequency&#34;</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">theme</span>(panel.grid <span style="color:#f92672">=</span> <span style="color:#a6e22e">element_blank</span>(), 
        strip.text <span style="color:#f92672">=</span> <span style="color:#a6e22e">element_text</span>(size <span style="color:#f92672">=</span> <span style="color:#ae81ff">16</span>, hjust  <span style="color:#f92672">=</span> <span style="color:#ae81ff">0.1</span>),
        axis.text.x <span style="color:#f92672">=</span> <span style="color:#a6e22e">element_blank</span>()) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">geom_text</span>(x <span style="color:#f92672">=</span> <span style="color:#a6e22e">rep</span>(<span style="color:#ae81ff">21</span>, <span style="color:#ae81ff">3</span><span style="color:#f92672">*</span>n), y <span style="color:#f92672">=</span> <span style="color:#a6e22e">rep</span>(<span style="color:#ae81ff">.1</span>, <span style="color:#ae81ff">3</span><span style="color:#f92672">*</span>n), 
            label <span style="color:#f92672">=</span> <span style="color:#a6e22e">rep</span>(<span style="color:#a6e22e">c</span>(<span style="color:#e6db74">&#34;+&#34;</span>, <span style="color:#e6db74">&#34;=&#34;</span>, <span style="color:#e6db74">&#34;&#34;</span>), each <span style="color:#f92672">=</span> n), size <span style="color:#f92672">=</span> <span style="color:#ae81ff">24</span>)
g
</code></pre></div><p><img src="https://i.imgur.com/rxS8tPR.jpg" alt=""></p>
<h1 id="create-frames-for-animation">Create Frames for Animation</h1>
<p>Now that I have my starting frame to show each individual sample, I am going to
use <code>geom_dotplot</code> to plot over the histogram. To help track the simulation moving
through time, the latest sample will be colored red. The <code>for</code> loop iterates
over each row number, filters to the current state of the simulation, and
updates what is to be plotted. Then the handy <code>ggsave</code> saves each frame for the
animated gif.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">for </span>(i in <span style="color:#ae81ff">1</span><span style="color:#f92672">:</span><span style="color:#a6e22e">length</span>(<span style="color:#a6e22e">unique</span>(mcSample<span style="color:#f92672">$</span>rowNum))) {
  dataUpdate <span style="color:#f92672">&lt;-</span> mcSample <span style="color:#f92672">%&gt;%</span>
    <span style="color:#a6e22e">group_by</span>(Distribution) <span style="color:#f92672">%&gt;%</span>
    <span style="color:#a6e22e">filter</span>(rowNum <span style="color:#f92672">%in%</span> <span style="color:#ae81ff">1</span><span style="color:#f92672">:</span>i) <span style="color:#f92672">%&gt;%</span>
    <span style="color:#a6e22e">group_by</span>(Distribution) <span style="color:#f92672">%&gt;%</span>
    <span style="color:#a6e22e">mutate</span>(Last <span style="color:#f92672">=</span> rowNum <span style="color:#f92672">==</span> i)
  gUpdate <span style="color:#f92672">&lt;-</span> g <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">geom_dotplot</span>(data <span style="color:#f92672">=</span> dataUpdate,
               <span style="color:#a6e22e">aes</span>(Value, fill <span style="color:#f92672">=</span> Last), color <span style="color:#f92672">=</span> <span style="color:#66d9ef">NA</span>, 
               binwidth <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>, method <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;histodot&#34;</span>,
               dotsize <span style="color:#f92672">=</span> <span style="color:#ae81ff">.6</span>) <span style="color:#f92672">+</span>
    <span style="color:#a6e22e">scale_fill_manual</span>(guide <span style="color:#f92672">=</span> <span style="color:#66d9ef">FALSE</span>, values <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#e6db74">&#34;black&#34;</span>, <span style="color:#e6db74">&#34;red&#34;</span>)) 
  <span style="color:#75715e">#gUpdate  </span>
  <span style="color:#a6e22e">ggsave</span>(filename <span style="color:#f92672">=</span> <span style="color:#a6e22e">paste0</span>(<span style="color:#e6db74">&#39;frames/plot&#39;</span>, <span style="color:#a6e22e">sprintf</span>(<span style="color:#e6db74">&#34;%03d&#34;</span>,i) , <span style="color:#e6db74">&#39;.jpg&#39;</span>),
         plot <span style="color:#f92672">=</span> gUpdate, device <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;jpeg&#39;</span>)
}
</code></pre></div><h1 id="convert-using-imagemagick">Convert Using ImageMagick</h1>
<p>All the heavy lifting is over now. I just need to use <code>ImageMagick</code> to process the
frames and convert to a gif. You can use a call to the command line here, but my
personal preference is to just switch to the command line. <code>ImageMagick</code> is a
standalone utility software that you will need to install separately from R.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">convert -delay <span style="color:#ae81ff">20</span> -loop <span style="color:#ae81ff">0</span> *.jpg ../mcsim_animation.gif
</code></pre></div><p><img src="https://i.imgur.com/ZoYOIr5.gif" alt=""></p>
<p>I now have an animation that I can use to explain my distribution assumptions
and show how each sample updates the model. It&rsquo;s pretty clear over time that
the sampling will eventually converge to the theoretical model.</p>
]]></description>
        </item>
        
        <item>
            <title>PE Industrial Engineer Reference Sheet</title>
            <link>https://roh.engineering/posts/2018/05/pe-industrial-engineer-reference-sheet/</link>
            <pubDate>Wed, 09 May 2018 00:00:00 +0000</pubDate>
            
            <guid>https://roh.engineering/posts/2018/05/pe-industrial-engineer-reference-sheet/</guid>
            <description><![CDATA[<p>You contribute to the reference sheet here: <a href="https://github.com/tomroh/pe_ise_prep">https://github.com/tomroh/pe_ise_prep</a>.</p>
<h1 id="systems-definition-analysis-and-design">Systems Definition, Analysis, and Design</h1>
<h2 id="system-analysis-and-design-tools">System Analysis and Design Tools</h2>
<h3 id="cause-effect-diagram-fishbone">Cause-Effect Diagram (Fishbone)</h3>
<div style="background-color: white; border-radius: 20px;">
<p><img src="/img/fishbone.png" alt=""></p>
</div>
<h3 id="pareto-analysis">Pareto Analysis</h3>
<p>80% of the items represent 20% of the sales or 20% of the items represent 80% of
the cost. This law is a rule of thumb.</p>
<p><img src="https://roh.engineering/posts/2018/05/pe-industrial-engineer-reference-sheet/index_files/figure-html/unnamed-chunk-1-1.png" width="672" style="display: block; margin: auto;" /></p>
<h3 id="operation-process-chart">Operation Process Chart</h3>
<p>The operation process chart only has Operations and Inspections.</p>
<h3 id="flow-process-chart">Flow Process Chart</h3>
<p>The flow process chart forces a more detailed look at a system.</p>
<div style="background-color: white; border-radius: 20px;">
<p><img src="/img/flow_process_symbols.png" alt="ASME standard set of process chart symbols"></p>
</div>
<h3 id="affinity-diagram">Affinity Diagram</h3>
<p>organizes a large number of ideas into their natural relationships</p>
<h3 id="left-hand-right-hand-chart">Left Hand Right Hand Chart</h3>
<p>Shows when each hand is busy and idle. It is sometimes called a simo chart.</p>
<h2 id="modeling-techniques">Modeling Techniques</h2>
<h3 id="queueing-models">Queueing Models</h3>
<h5 id="littles--law"><code>$$Little's \: Law$$</code></h5>
<hr>
<p><code>$$L = \lambda W$$</code></p>
<h5 id="mmckquad-queue"><code>\(M/M/c/K\quad Queue\)</code></h5>
<hr>
<p><strong>Effective vs. Offered Load:</strong></p>
<p><code>$$\lambda_{eff} = \lambda(1-\pi_m)$$</code></p>
<p><strong>Waiting Time Law:</strong></p>
<p><code>$$L = \sum_{n=0}^Mn\pi_n$$</code>
<code>$$L_q = \sum_{n=c+1}^{c-1}(n-c)\pi_n$$</code></p>
<p><strong>Probability of n arrivals by time t:</strong></p>
<p><code>$$P[N(t)=n]=\frac{(\lambda t)^ne^{-\lambda t}}{n!}$$</code></p>
<h5 id="mm1inftyquad-queue"><code>\(M/M/1/\infty\quad Queue\)</code></h5>
<hr>
<p><strong>Probability of customers in system:</strong></p>
<p><code>$$\pi_0=1-\rho$$</code>
<code>$$\pi_n=\rho^n(1-\rho)$$</code>
<code>$$L = \frac{\rho}{1-\rho}$$</code>
<code>$$L_q = L-\rho=\frac{\rho^2}{1-\rho}$$</code></p>
<h5 id="mg1inftyquad-queue"><code>\(M/G/1/\infty\quad Queue\)</code></h5>
<hr>
<p><strong>Pollaczek-Khintchine Formula:</strong></p>
<p><code>$$L = L_q+\rho=\frac{\rho^2+\lambda^2\sigma^2}{2(1-\rho)}+\rho$$</code></p>
<h5 id="mmcmquad-queue"><code>\(M/M/c/M\quad Queue\)</code></h5>
<hr>
<p><code>$$D = \sum_{n=0}^{c-1}\frac{\rho^n}{n!}+\frac{\rho^c}{c!}[\frac{1-(\rho/c)^{M-c+1}}{1-\rho/c}]$$</code>
<code>$$\pi_0=\frac{1}{D}$$</code></p>
<p><code>$$\pi_n= \begin{cases}  \frac{\rho^n}{n!}\pi_0, \quad \text{n&lt;c} \\ \frac{\rho^n}{c!c^{n-c}}\pi_0, \quad {n\geq c}  \end{cases}$$</code></p>
<p><code>$$L_q=\pi_0\bigg(\frac{\rho^{c+1}}{(c-1)!(c-\rho)^2}\bigg) \bigg[1-\big(\frac{\rho}{c}\big)^{M-c}-(M-c)\big(\frac{\rho}{c}\big)^{M-c}\big(1-\frac{\rho}{c}\big)\bigg],\quad \rho\neq c$$</code></p>
<p><code>$$L_q=\pi_0\bigg(\frac{\rho^c (M-c)(M-c+1)}{2c!}\bigg),\quad \rho=c$$</code></p>
<p><code>$$L_q=\pi_0\bigg(\frac{\rho^{c+1}}{(c-1)!(c-\rho)^2}\bigg),\quad c=\infty$$</code></p>
<h5 id="mmcinfty-quad-queue"><code>\(M/M/C/\infty \quad Queue\)</code></h5>
<hr>
<p><strong>C = 1</strong></p>
<p><code>$$P_0=1-\rho ,\quad L_q=\frac{\rho^2}{1-\rho}$$</code></p>
<p><strong>C = 2</strong></p>
<p><code>$$P_0=\frac{(1-\rho)}{(1=\rho}, \quad L_q = \frac{2\rho^3}{(1-\rho^2)}$$</code></p>
<p><strong>C = 3</strong></p>
<p><code>$$P_0 = \frac{2(1-\rho)}{2+4\rho+3\rho^2}, \quad \frac{9\rho^4}{2+2\rho-\rho^2-3\rho^3}$$</code></p>
<h3 id="model-verification">Model Verification</h3>
<p>A model has been verified if a range of models produce similar results on the
same situation</p>
<h3 id="model-validation">Model Validation</h3>
<p>A model has been validated if a range of results produce similar results on
the same situation</p>
<h3 id="bottleneck-analysis">Bottleneck Analysis</h3>
<p>Optimize the process that is the bottleneck, then re-evaulate the bottleneck and
repeat.</p>
<p style="page-break-before: always">
<h1 id="facilities-engineering-and-planning">Facilities Engineering and Planning</h1>
<h2 id="peopleequipment-requirements">People/Equipment Requirements</h2>
<p><code>$$M_j = \sum_{i=1}^{n} \frac{P_{ij}T_{ij}}{C_{ij}}$$</code>
<code>$$M_j = \textrm{number of machines/people} \\ P = \textrm{production rate} \\ T = \textrm{production time} \\ C = \textrm{production period} \\ n = \textrm{number of products}$$</code></p>
<h2 id="material-handling">Material Handling</h2>
<p><strong>Euclidian:</strong></p>
<p><code>$$d = \sqrt{(x_2-x_1)^2+(y_2-y_1)^2}$$</code></p>
<p>To optimize material flow:</p>
<p><code>$$min\quad \sum_{i=1}^mw_i[(x-a_i)^2+(y-b_i)]^{\frac{1}{2}}$$</code>
If there are 4 locations with equal weight, the optimal location is the facility
within a triangle of the other facilities. If there is no such facility,
the optimal location is at the intersection of two lines.</p>
<p>When the weighted costs are proportional to the square of the Euclidean distance,
it is called the &lsquo;gravity&rsquo; problem.</p>
<p><code>$$min\quad \sum_{i=1}^mw_i[(x-a_i)^2+(y-b_i)^2]$$</code></p>
<p><code>$$x = \frac{\sum_{i=1}^mw_ia_i}{\sum_{i=1}^mw_i}$$</code>
<code>$$y = \frac{\sum_{i=1}^mw_ib_i}{\sum_{i=1}^mw_i}$$</code></p>
<p><strong>Manhattan:</strong></p>
<p><code>$$|x_2-x_1| + |y_2-y_1|$$</code></p>
<p>To optimize flow:</p>
<p><code>$$min\quad \sum_{i=1}^m w_i(|x-a_1|+|y-b_i|)$$</code></p>
<p>The x value is the median of the location x-coordinates.
The y value is the median of the location y-coordinates.</p>
<p><strong>Chebyshev (simultaneous x and y movement)</strong></p>
<p><code>$$max(|x_2-x_1|,|y_2-y_1|)$$</code></p>
<h2 id="relationship-chart">Relationship Chart</h2>
<table>
<thead>
<tr>
<th style="text-align:left">Code</th>
<th style="text-align:left">Closeness</th>
<th style="text-align:left">Rank</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">A</td>
<td style="text-align:left">Absolutely Necessary</td>
<td style="text-align:left">0.95</td>
</tr>
<tr>
<td style="text-align:left">E</td>
<td style="text-align:left">Especially Important</td>
<td style="text-align:left">0.85</td>
</tr>
<tr>
<td style="text-align:left">I</td>
<td style="text-align:left">Important</td>
<td style="text-align:left">0.7</td>
</tr>
<tr>
<td style="text-align:left">O</td>
<td style="text-align:left">Ordinary Closeness</td>
<td style="text-align:left">0.5</td>
</tr>
<tr>
<td style="text-align:left">U</td>
<td style="text-align:left">Unimportant</td>
<td style="text-align:left">0</td>
</tr>
<tr>
<td style="text-align:left">X</td>
<td style="text-align:left">Not desirable</td>
<td style="text-align:left">-</td>
</tr>
</tbody>
</table>
<p style="page-break-before: always">
<h1 id="supply-chain-logistics">Supply Chain Logistics</h1>
<h2 id="forecasting-methods">Forecasting Methods</h2>
<h3 id="moving-average">Moving Average</h3>
<p><code>$$\hat{d}_t = \frac{\sum_{i=1}^{n}d_{t-i}}{n}$$</code></p>
<h3 id="exponentially-weighted-moving-average">Exponentially Weighted Moving Average</h3>
<p><code>$$\hat{d}_t = \alpha d_{t-1}+(1-\alpha)\hat{d}_{t-1},\quad 0 \leq \alpha( \textrm{smoothing constant})\leq1 \\ d_{t-1} \text{ = actual demand, } \hat{d}_{t-1} \text{ = forecasted demand}$$</code></p>
<h2 id="production-planning-methods">Production Planning Methods</h2>
<p><strong>Systems to compute Master Production and Ordering Plan</strong></p>
<p>Material Requirements Planning (MRP)</p>
<p>Manufacturing Resource Planning (MRPII)</p>
<h2 id="engineering-economics">Engineering Economics</h2>
<p><code>$$\bigg(\frac{F}{P}\bigg)= (1+i)^N, \quad  \bigg(\frac{P}{F}\bigg)= \frac{1}{(1+i)^N}  \\ \bigg(\frac{F}{A}\bigg)= \frac{(1+i)^N-1}{i}, \quad \bigg(\frac{P}{A}\bigg)= \frac{(1+i)^N-1}{i(1+i)^N}  \\ \bigg(\frac{A}{F}\bigg)= \frac{i}{(1+i)^N-1}, \quad \bigg(\frac{A}{P}\bigg)= \frac{i(1+i)^N}{(1+i)^N-1}  \\ \bigg(\frac{P}{G}\bigg)=\frac{1}{i}\bigg[\frac{(1+i)^N-1}{i(1+i)^N}-\frac{N}{(1+i)^N} \bigg], \quad \bigg(\frac{A}{G}\bigg)=\frac{1}{i}-\frac{N}{(1+i)^N-1}$$</code></p>
<p>*Denominator is current value and Numerator is desired conversion</p>
<p><strong>Depreciation</strong></p>
<p>Modified Accelerated Cost Recovery System (MACRS) - See Tables</p>
<p><code>$$\text{Straight Line (SL) - } \frac{1}{n}$$</code></p>
<h2 id="production-scheduling-methods">Production Scheduling Methods</h2>
<p><strong>Makespan</strong></p>
<p>the time it takes from the start of the first job until the end of the last job</p>
<p><strong>Scheduling Sequence</strong></p>
<ol>
<li>Earliest Due Date - order jobs by due date</li>
<li>Shortest Processing Time - order jobs by processing time</li>
<li>Critical Ratio - divide time remaining until due date by time left on the
machine, order by smallest critical ratio</li>
</ol>
<p><strong>Johnson&rsquo;s Optimal Rule for Two Machines</strong></p>
<ol>
<li>Find the shortest processsing times and arbitrarily break ties</li>
<li>If the shortest processing time is on Machine A, schedule immediately. If the
shortest processing time is on Machine B, schedule it as late as possible.</li>
<li>Eliminate the last job scheduled on the list and repeat step 1-2.</li>
</ol>
<h2 id="inventory-management-and-control">Inventory Management and Control</h2>
<h3 id="economic-order-quantity">Economic Order Quantity</h3>
<p><code>$$Q^*=\sqrt{\frac{2C_pD}{h}R} \\ R = \frac{1}{1-\frac{D}{P}},\quad\textrm{R=1, when replenishment is instaneous} \\ D=\textrm{demand},P=\textrm{production rate},C_p=\textrm{cost per order},h=\textrm{holding cost}$$</code></p>
<h3 id="economic-manufacturing-quantity">Economic Manufacturing Quantity</h3>
<p>Use the equation above with R not equal to 1.</p>
<h3 id="with-shortage-costs">With shortage costs</h3>
<p><code>$$Q^* = \sqrt{\frac{2C_pD}{h}R\big(\frac{h+z}{z}\big)} \\ z = \textrm{shortage cost}$$</code></p>
<p><code>$$M^*=\sqrt{\frac{2C_pD(1-\frac{D}{P})h}{z(h+z)}} \\ M = \textrm{allowed shortage}$$</code></p>
<h3 id="carrying-cost">Carrying Cost</h3>
<p><code>$$C_T=\frac{hQ}{2}\big(1-\frac{D}{P}\big)+CD+C_p\frac{D}{Q}$$</code></p>
<h3 id="probabilistic-inventory-and-production-models">Probabilistic Inventory and Production Models</h3>
<p><code>$$F_D(x=y^*)\ge\frac{p-c}{p+h} \\ F_D = \textrm{CDF} \\ x = \textrm{units on hand}, y^*=\textrm{optimal order quantity}, p = \textrm{loss of potential revenue},\\ h = \textrm{loss in value from holding}, c = \textrm{unit acquisition cost}$$</code></p>
<h2 id="distribution-methods">Distribution Methods</h2>
<p><strong>Transhipment:</strong></p>
<p>The intermediary storage</p>
<h3 id="transportation-problem">Transportation Problem</h3>
<p><code>$$min \quad \sum_{i=1}^m \sum_{j=1}^nx_{ij}c_{ij} \\ \sum_{j=1}^nx_{ij}=s_i, n = 1, 2, ..., m \\ \sum_{i=1}^mx_{ij}=d_j, m = 1, 2, ..., n$$</code></p>
<h3 id="storage-and-warehousing-methods">Storage and Warehousing Methods</h3>
<ol>
<li>Dedicated Storage
<ul>
<li>easy to retrieve items</li>
<li>Sum of maximum of each product</li>
</ul>
</li>
<li>Random Storage
<ul>
<li>more efficient use of space</li>
<li>Maximum of the sums of all products</li>
</ul>
</li>
</ol>
<h2 id="transportation-modes">Transportation Modes</h2>
<ol>
<li>Variable Path
<ul>
<li>truck, vehicle anything that does not have one fixed path</li>
<li>versatility</li>
</ul>
</li>
<li>Fixed Path
<ul>
<li>conveyor</li>
<li>tied to one path</li>
</ul>
</li>
</ol>
<h2 id="assignment-problem">Assignment Problem</h2>
<p><strong>Hungarian Procedure:</strong></p>
<ol>
<li>Subtract the minimum of the row from all elements in the row</li>
<li>Substract the minimum of the column from all elements in the columns</li>
<li>Try to make a valid assignment using the zero elements, if all assigments
cannot be made proceed to next step</li>
<li>Cover all zeroes with the minimal number of lines</li>
<li>From each uncovered element subtract the minimum of the uncovered <em>y</em>,
add <em>y</em> to each intersection element. Go to step 3.</li>
<li>Transfer the assignment plan to the original cost table.</li>
</ol>
<p style="page-break-before: always">
<h1 id="work-design">Work Design</h1>
<h2 id="controls">Controls</h2>
<p>An administrative control are training, policies, or procedures.</p>
<p>An engineering control is a physical modification to mitigate hazards.</p>
<h2 id="noise-dose">Noise Dose</h2>
<p><strong>Dose</strong></p>
<p><code>$$D=100*\big(\frac{C_1}{T_1}+\frac{C_2}{T_2}+...+\frac{C_n}{T_n}\big)\le 100$$</code></p>
<p><strong>Time Weighted Average</strong></p>
<p><code>$$TWA=16.61log_{10}\big(\frac{D}{100}\big)+90$$</code></p>
<h2 id="exposure">Exposure</h2>
<p><strong>Time Weighted Concentration</strong></p>
<p><code>$$TWA=\frac{\sum_{i=1}^nC_iT_i}{\sum_{i=1}^nT_i}$$</code></p>
<h2 id="taylor-tool-life">Taylor Tool Life</h2>
<p><code>$$VT^n=C \\ V = \textrm{speed surface feet per minute} \\ T = \textrm{tool life in minutes} \\ C,n = \textrm{constants that depend on material and tool}$$</code></p>
<h2 id="work-sampling">Work Sampling</h2>
<p><code>$$D = Z_{\alpha/2}\sqrt{\frac{p(-1-p)}{n}}, \quad Z_{\alpha/2}\sqrt{\frac{1-p}{pn}} \\ p = \textrm{proportion of observed time} \\ D = \textrm{absolute error} \\ R = \textrm{relative error} = \frac{D}{p} \\ n = \textrm{sample size}$$</code></p>
<h2 id="sample-size">Sample Size</h2>
<p><code>$$E = \frac{z_{\frac{\alpha}{2}}\sigma}{\sqrt{n}}$$</code></p>
<p><code>$$n = \bigg( \frac{z_{\frac{\alpha}{2}}\sigma}{E} \bigg)^2$$</code></p>
<h2 id="critical-path-method">Critical Path Method</h2>
<p><code>$$T = \sum_{(i,j)\in CP}d_{ij}$$</code></p>
<h2 id="standard-time">Standard Time</h2>
<p><code>$$\textrm{Observed Time * Pace Rating * (1 + personal time allowance) * (1 + fatigue allowance)}$$</code></p>
<h2 id="recommended-weight-limit">Recommended Weight Limit</h2>
<p>Units are pounds and inches.</p>
<p><code>$$RWL = 51\cdot (\frac{10}{H})\cdot (1-.0075|V-30|)\cdot (.82+\frac{1.8}{D})\cdot (1-.0032A)\cdot FM \cdot CM \\ \textrm{H = horizontal location of the load forward of the midpoint of the ankles} \\ \textrm{V = vertical location of the load} \\ \textrm{D = Vertical travel distance between the origin and the destination} \\ \textrm{A=angle of asymmetry between hands and feet} \\ \textrm{FM = frequency multiplier (from table)} \\ \textrm{CM = coupling mulitiplier (from table)}$$</code></p>
<h2 id="learning-curve">Learning Curve</h2>
<p><code>$$y=kx^n, n=\frac{log_{e}\phi}{log_{e}(2)} \\ \phi=\textrm{learning ratio}=\frac{T(2N)}{T(N)}, \textrm{T(N) = time to produce Nth unit} \\ \textrm{y= time to produce xth unit, k = time to produce first unit, x = cumulative number of units produced}$$</code></p>
<p><strong>Total Learning Time:</strong></p>
<p><code>$$T=k\frac{[(x_2+\frac{1}{2})^{n+1}-(x_1+\frac{1}{2})^{n+1}]}{n+1}$$</code></p>
<p><strong>Remission Line:</strong></p>
<p><code>$$y=k+\frac{(k-s)(x-1)}{1-x_s}$$</code></p>
<p style="page-break-before: always">
<h1 id="quality-control">Quality Control</h1>
<h2 id="statistical-process-control">Statistical Process Control</h2>
<h3 id="x--r-chart">X &amp; R-Chart</h3>
<p><code>$$UCL = D_4\bar{R} \\ CL = \bar{R} \\ LCL = D_3\bar{R}$$</code></p>
<p><code>$$UCL = \bar{\bar{X}}+A_2\bar{R} \\ CL = \bar{\bar{X}} \\ LCL = \bar{\bar{X}}-A_2\bar{R}$$</code></p>
<h3 id="x--s-chart">X &amp; S-Chart</h3>
<p><code>$$UCL=B_4\bar{S} \\ CL = \bar{X} \\ LCL = B_3\bar{S}$$</code></p>
<p><code>$$UCL = \bar{\bar{X}} + A_3\bar{S} \\ CL = \bar{\bar{X}} \\ LCL = \bar{\bar{X}}-A_3\bar{S}$$</code></p>
<h3 id="p-chart">P-Chart</h3>
<p><code>$$UCL = \bar{p}+3\sqrt{\frac{\bar{p}(1-\bar{p})}{n}} \\ CL = \bar{p} \\ LCL = \bar{p} - 3\sqrt{\frac{\bar{p}(1-\bar{p})}{n}}$$</code></p>
<h3 id="c-chart">C-Chart</h3>
<p><code>$$UCL = \bar{c}+3\sqrt{\bar{c}} \\ CL = \bar{c} \\ LCL = \bar{c}-3\sqrt{\bar{c}}$$</code></p>
<h3 id="tests-for-out-of-control">Tests for Out of Control</h3>
<ol>
<li>A single point falls outside three sigma control limits</li>
<li>Two out of three successive points fall on the same side of and more than two
sigma units from the center line</li>
<li>Four out of five successive points fall on the same side of and more than
one sigma unit from the center line</li>
<li>Eight successive points fall on the same side of the center line</li>
</ol>
<h2 id="control-vs-capability">Control vs. Capability</h2>
<p>In control if it is within natural variability</p>
<p>Is capable if it is entirely within specification</p>
<h2 id="process-capability">Process Capability</h2>
<p><strong>Actual Capability:</strong></p>
<p><code>$$C_{pk}=min\bigg(\frac{\mu-LSL}{3\sigma},\frac{USL-\mu}{3\sigma}\bigg)$$</code></p>
<p><strong>Potential Capability:</strong></p>
<p><code>$$C_p = \frac{USL-LSL}{6\sigma}$$</code></p>
<h2 id="reliability-analysis">Reliability Analysis</h2>
<p><strong>Series:</strong></p>
<p><code>$$R = \prod_{i=1}^n P_i$$</code></p>
<p><strong>Parallel:</strong></p>
<p>$$R = 1-\prod_{i=1}^n (1-P_i) $$</p>
<p><strong>Hazard Function</strong></p>
<p><code>$$h(x)=\frac{f(x)}{R(x)} \\ f(x) \text{ = density function, } R(x) \text{ = survival function}$$</code></p>
<p><strong>Exponential</strong>
<code>$$h(x)=\lambda$$</code></p>
<p><strong>Weibull</strong>
<code>$$h(x)=\frac{\beta}{\alpha}\big(\frac{x}{\alpha}\big)^{\beta-1}$$</code></p>
<p><strong>Mean Time to Failure</strong></p>
<p><code>$$\frac{1}{\lambda}, \\ \lambda \text{ = constant failure rate}$$</code></p>
<h2 id="six-sigma">Six Sigma</h2>
<!-- html table generated in R 4.0.3 by xtable 1.8-4 package -->
<!-- Wed Feb 17 21:22:45 2021 -->
<table border='2' cellpadding='15' cellpadding='5' rules ='all' width ='100%'>
<tr> <th> `\(\sigma\)` </th> <th> Defects per Million </th>  </tr>
  <tr> <td align="center"> 1.00 </td> <td align="center"> 158655.254 </td> </tr>
  <tr> <td align="center"> 1.50 </td> <td align="center"> 66807.201 </td> </tr>
  <tr> <td align="center"> 2.00 </td> <td align="center"> 22750.132 </td> </tr>
  <tr> <td align="center"> 2.50 </td> <td align="center"> 6209.665 </td> </tr>
  <tr> <td align="center"> 3.00 </td> <td align="center"> 1349.898 </td> </tr>
  <tr> <td align="center"> 3.50 </td> <td align="center"> 232.629 </td> </tr>
  <tr> <td align="center"> 4.00 </td> <td align="center"> 31.671 </td> </tr>
  <tr> <td align="center"> 4.50 </td> <td align="center"> 3.398 </td> </tr>
  <tr> <td align="center"> 5.00 </td> <td align="center"> 0.287 </td> </tr>
  <tr> <td align="center"> 5.50 </td> <td align="center"> 0.019 </td> </tr>
  <tr> <td align="center"> 6.00 </td> <td align="center"> 0.001 </td> </tr>
   </table>
<p style="page-break-before: always">
<h1 id="statistics">Statistics</h1>
<h2 id="normal-distribution">Normal Distribution</h2>
<p><strong>z-score</strong></p>
<p><code>$$z=\frac{x-\mu}{\sigma}$$</code></p>
<p><strong>Confidence Interval</strong></p>
<p><code>$$\bar{x}\pm\frac{z_{\alpha/2} \sigma}{\sqrt{n}}$$</code></p>
<p><strong>Two-means comparison:</strong></p>
<p><code>$$z_0=\frac{\bar{x}_1-\bar{x}_2}{\sqrt{\frac{\sigma_1^2}{n_1}+\frac{\sigma_2^2}{n_2}}}$$</code></p>
<h2 id="student-t-distribution">student-t Distribution</h2>
<p><strong>t-score:</strong></p>
<p><code>$$t=\frac{\bar{x}-\mu}{\frac{s}{\sqrt{n}}}$$</code></p>
<p><strong>Confidence Interval</strong></p>
<p><code>$$\bar{x}\pm\frac{t_{\alpha/2,n-1}s}{\sqrt{n}}$$</code></p>
<p><strong>Two-means comparison:</strong></p>
<p><code>$$t_0=\frac{\bar{x}_1-\bar{x}_2}{\sqrt{\frac{s_1^2}{n_1}+\frac{s_2^2}{n_2}}}$$</code></p>
<p><strong>df for Two Sample t-test:</strong></p>
<p><code>$$df=\frac{\big(\frac{s_1^2}{n_1}+\frac{s_2^2}{n_2}\big)^2}{\frac{(\frac{s_1^2}{n_1})^2}{n_1-1}+{\frac{(\frac{s_1^2}{n_1})^2}{n_1-1}}}$$</code>
<strong>Paired t-test:</strong></p>
<p><code>$$t_0 = \frac{\bar{d}-0}{\frac{s_d}{\sqrt{n}}}$$</code></p>
<h2 id="hypothesis-testing">Hypothesis Testing</h2>
<p><img src="https://roh.engineering/posts/2018/05/pe-industrial-engineer-reference-sheet/index_files/figure-html/unnamed-chunk-3-1.png" width="672" style="display: block; margin: auto;" /></p>
<!-- html table generated in R 4.0.3 by xtable 1.8-4 package -->
<!-- Wed Feb 17 21:22:46 2021 -->
<table border='2' cellpadding='15' cellpadding='5' rules ='all' width ='100%'>
<caption align="top"> Error Table </caption>
<tr> <th>   </th> <th> `\(H_0 \text{ is true}\)` </th> <th> `\(H_0 \text{ is false}\)` </th>  </tr>
  <tr> <td align="center"> `\(\text{Accept } H_0\)` </td> <td align="center"> Correct </td> <td align="center"> Type II Error </td> </tr>
  <tr> <td align="center"> `\(\text{Reject } H_0\)` </td> <td align="center"> Type I Error </td> <td align="center"> Correct </td> </tr>
   </table>
<h2 id="chi-squared-goodness-of-fit">Chi-Squared Goodness of Fit</h2>
<p><code>$$\chi^2=\sum_{j=1}^k\frac{(O_j-E_j)^2}{E_j}$$</code></p>
<h2 id="linear-regression">Linear Regression</h2>
<p><code>$$SSR=\sum_{i=1}^n(\hat{y}_i-\bar{y})^2$$</code></p>
<p><code>$$SSE = \sum_{i=1}^n(y_i-\hat{y}_i)^2$$</code></p>
<p><code>$$SST = \sum_{i=1}^n(y_i-\bar{y})^2$$</code></p>
<p><code>$$R^2=\frac{SSR}{SST} = 1-\frac{SSE}{SST}$$</code></p>
<h2 id="anova">ANOVA</h2>
<p><code>$$SSA+SSE=SST$$</code></p>
<p><strong>One-Way</strong></p>
<p>Given Treatment A:</p>
<p><code>$$SSA+SSE=SST$$</code></p>
<table>
<thead>
<tr>
<th style="text-align:left">SS</th>
<th style="text-align:left">df</th>
<th style="text-align:left">MS</th>
<th style="text-align:left">F</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">SSA</td>
<td style="text-align:left">a-1</td>
<td style="text-align:left">SSA/dfA</td>
<td style="text-align:left">MSA/MSE</td>
</tr>
<tr>
<td style="text-align:left">SSE</td>
<td style="text-align:left">a(n-1)</td>
<td style="text-align:left">SSE/dfE</td>
<td style="text-align:left"></td>
</tr>
<tr>
<td style="text-align:left">SST</td>
<td style="text-align:left">an-1</td>
<td style="text-align:left"></td>
<td style="text-align:left"></td>
</tr>
</tbody>
</table>
<p><strong>Two-Way</strong></p>
<p>Given treatment factors A &amp; B:</p>
<p><code>$$SST=SSA+SSB+SSAB+SSE$$</code></p>
<table>
<thead>
<tr>
<th style="text-align:left">SS</th>
<th style="text-align:left">df</th>
<th style="text-align:left">MS</th>
<th style="text-align:left">F</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">SSA</td>
<td style="text-align:left">a-1</td>
<td style="text-align:left">SSA/dfA</td>
<td style="text-align:left">MSA/MSE</td>
</tr>
<tr>
<td style="text-align:left">SSB</td>
<td style="text-align:left">b-1</td>
<td style="text-align:left">SSB/dfB</td>
<td style="text-align:left">MSB/MSE</td>
</tr>
<tr>
<td style="text-align:left">SSAB</td>
<td style="text-align:left">(a-1)(b-1)</td>
<td style="text-align:left">SSAB/dfAB</td>
<td style="text-align:left">MSAB/MSE</td>
</tr>
<tr>
<td style="text-align:left">SSE</td>
<td style="text-align:left">ab(n-1)</td>
<td style="text-align:left">SSE/dfE</td>
<td style="text-align:left"></td>
</tr>
<tr>
<td style="text-align:left">SST</td>
<td style="text-align:left">abn-1</td>
<td style="text-align:left"></td>
<td style="text-align:left"></td>
</tr>
</tbody>
</table>
<h2 id="bayesian-analysis">Bayesian Analysis</h2>
<p><strong>Bayes' Theorem</strong></p>
<p><code>$$P(A|B)=\frac{P(B|A)P(A)}{P(B)}=\frac{P(B|A)P(A)}{P(B|A)P(A)+P(B|A^\prime)P(A^\prime)}$$</code></p>
<p style="page-break-before: always">
<h2 id="distributions">Distributions</h2>
<!-- html table generated in R 4.0.3 by xtable 1.8-4 package -->
<!-- Wed Feb 17 21:22:46 2021 -->
<table border='2' cellpadding='15' cellpadding='5' rules ='all' width ='100%'>
<caption align="top"> Discrete </caption>
<tr> <th> Distribution </th> <th> pmf </th> <th> cdf </th> <th> mean </th> <th> variance </th> <th> parameters </th>  </tr>
  <tr> <td align="center"> Binomial </td> <td align="center"> `\(\binom{n}{x}p^x(1-p)^{n-x}\)` </td> <td align="center"> `\(\sum_{i=0}^{\lfloor x \rfloor}\binom{n}{i}p^i(1-p)^{n-i}\)` </td> <td align="center"> `\(np\)` </td> <td align="center"> `\(np(1-p)\)` </td> <td align="center"> `\(\text{n = number of trials} \\ \text{p = success probability}\)` </td> </tr>
  <tr> <td align="center"> Discrete Uniform </td> <td align="center"> `\(\frac{1}{b-a+1}\)` </td> <td align="center"> `\(\frac{\lfloor x \rfloor - a + 1}{b-a+1}\)` </td> <td align="center"> `\(\frac{a+b}{2}\)` </td> <td align="center"> `\(\frac{(b-a+1)^2-1}{12}\)` </td> <td align="center"> `\(\text{a = minimum} \\ \text{b = maximum}\)` </td> </tr>
  <tr> <td align="center"> Poisson </td> <td align="center"> `\(\frac{\lambda^x e^{-\lambda}}{x!}\)` </td> <td align="center"> `\(e^{-\lambda}\sum_{i=0}^{\lfloor x \rfloor}\frac{\lambda^i}{i!}\)` </td> <td align="center"> `\(\lambda\)` </td> <td align="center"> `\(\lambda\)` </td> <td align="center"> `\(\lambda\text{ = rate}\)` </td> </tr>
  <tr> <td align="center"> Geometric </td> <td align="center"> `\(p(1-p)^{x}\)` </td> <td align="center"> `\(1-(1-p)^{x+1}\)` </td> <td align="center"> `\(\frac{1-p}{p}\)` </td> <td align="center"> `\(\frac{1-p}{p^2}\)` </td> <td align="center"> `\(\text{k = number of trials} \\ \text{p = success probability}\)` </td> </tr>
  <tr> <td align="center"> Negative Binomial </td> <td align="center"> `\(\binom{k+x-1}{x}p^k(1-p)^x\)` </td> <td align="center"> `\(-\)` </td> <td align="center"> `\(\frac{k(1-p)}{p}\)` </td> <td align="center"> `\(\frac{k(1-p)}{p^2}\)` </td> <td align="center"> `\(\text{k = number of successes}\\ \text{p = success probability}\)` </td> </tr>
   </table>
<!-- html table generated in R 4.0.3 by xtable 1.8-4 package -->
<!-- Wed Feb 17 21:22:46 2021 -->
<table border='2' cellpadding='15' cellpadding='5' rules ='all' width ='100%'>
<caption align="top"> Continuous </caption>
<tr> <th> Distribution </th> <th> pdf </th> <th> cdf </th> <th> mean </th> <th> variance </th> <th> parameters </th>  </tr>
  <tr> <td align="center"> Uniform </td> <td align="center"> `\(\frac{1}{b-a}\)` </td> <td align="center"> `\(\frac{x-a}{b-a}\)` </td> <td align="center"> `\(\frac{a+b}{2}\)` </td> <td align="center"> `\(\frac{(b-a)^2}{12}\)` </td> <td align="center"> `\(\text{a = minimum} \\ \text{b = maximum}\)` </td> </tr>
  <tr> <td align="center"> Exponential </td> <td align="center"> `\(\lambda e^{-\lambda x}\)` </td> <td align="center"> `\(1-e^{-\lambda x}\)` </td> <td align="center"> `\(\frac{1}{\lambda}\)` </td> <td align="center"> `\(\frac{1}{\lambda^2}\)` </td> <td align="center"> `\(\lambda \text{ = rate}\)` </td> </tr>
  <tr> <td align="center"> Normal </td> <td align="center"> `\(\frac{1}{\sqrt{2\pi \sigma^2}}e^{-\frac{(x-\mu)^2}{2\sigma^2}}\)` </td> <td align="center"> `\(\frac{1}{2}\big[1+erf\big(\frac{x-\mu}{\sigma\sqrt{2}}\big)\big]\)` </td> <td align="center"> `\(\mu\)` </td> <td align="center"> `\(\sigma^2\)` </td> <td align="center"> `\(\mu \text{ = mean} \\ \sigma^2 \text{ = variance}\)` </td> </tr>
  <tr> <td align="center"> PERT beta </td> <td align="center"> `\(-\)` </td> <td align="center"> `\(-\)` </td> <td align="center"> `\(\frac{a+4m+b}{6}\)` </td> <td align="center"> `\(\frac{(b-a)^2}{36}\)` </td> <td align="center"> `\(\text{a = 1st percentile} \\ \text{b = 99th percentile} \\ \text{m = mode}\)` </td> </tr>
  <tr> <td align="center"> Triangular </td> <td align="center"> $\begin{cases} \frac{(x-a)^2}{(b-a)(c-a)},\quad a\le x\le c \\  1-\frac{(b-x)^2}{(b-a)(b-c)},\quad c<x\le b
\end{cases}$ </td> <td align="center"> $\begin{cases} \frac{(x-a)^2}{(b-a)(c-a)},\quad a\le x\le c \\ 1-\frac{(b-x)^2}{(b-a)(b-c)}, \quad c<x\le b
\end{cases}$ </td> <td align="center"> `\(\frac{a+b+c}{3}\)` </td> <td align="center"> `\(\frac{a^2+m^2+b^2-ca-ab-cb}{18}\)` </td> <td align="center"> `\(\text{a = minimum} \\ \text{b = maximum} \\ \text{c = mode}\)` </td> </tr>
  <tr> <td align="center"> Gamma </td> <td align="center"> `\(\frac{\beta^\alpha}{\Gamma(\alpha)}x^{\alpha-1}e^{-\beta x}\)` </td> <td align="center"> `\(\frac{1}{\Gamma(\alpha)}\gamma(\alpha,\beta x)\)` </td> <td align="center"> `\(\alpha\beta\)` </td> <td align="center"> `\(\alpha\beta^2\)` </td> <td align="center"> `\(\alpha \text{ = shape} \\ \beta \text{ = scale}\)` </td> </tr>
  <tr> <td align="center"> Weibull </td> <td align="center"> `\(\frac{\beta}{\alpha}\binom{x}{\alpha}^{\beta-1}e^{-{(\frac{x}{\alpha}})^\beta}\)` </td> <td align="center"> `\(1-e^{-(\frac{x}{\alpha})^\beta}\)` </td> <td align="center"> `\(-\)` </td> <td align="center"> `\(-\)` </td> <td align="center"> `\(-\)` </td> </tr>
  <tr> <td align="center"> Lognormal </td> <td align="center"> `\(\frac{1}{x\sigma\sqrt{2\pi}}e^{\frac{(ln x-\mu)^2}{2\sigma^2}}\)` </td> <td align="center"> `\(\frac{1}{2}+ \frac{1}{2} erf \big[ \frac{ln x-\mu}{\sigma\sqrt{2}}\big]\)` </td> <td align="center"> `\(e^{\mu+\frac{\sigma^2}{2}}\)` </td> <td align="center"> `\([e^{\sigma^2}-1] e^{2\mu+\sigma^2}\)` </td> <td align="center"> `\(\mu\text{ = mean} \\ \sigma^2 \text{ = variance}\)` </td> </tr>
   </table>
<p style="page-break-before: always">
<h2 id="textfactors-for-control-charts"><code>\(\text{Factors for Control Charts}\)</code></h2>
<!-- html table generated in R 4.0.3 by xtable 1.8-4 package -->
<!-- Wed Feb 17 21:22:47 2021 -->
<table border='2' cellpadding='15' cellpadding='5' rules ='all' width ='100%'>
<caption align="top"> Table 1: Factors for Calculating Limits for Variable Control Charts </caption>
<tr> <th> `\(n\)` </th> <th> `\(A\)` </th> <th> `\(A_2\)` </th> <th> `\(A_3\)` </th> <th> `\(c_4\)` </th> <th> `\(B_3\)` </th> <th> `\(B_4\)` </th> <th> `\(B_5\)` </th> <th> `\(B_6\)` </th> <th> `\(d_2\)` </th> <th> `\(d_2^{-1}\)` </th> <th> `\(d_3\)` </th> <th> `\(D_1\)` </th> <th> `\(D_2\)` </th> <th> `\(D_3\)` </th> <th> `\(D_4\)` </th>  </tr>
  <tr> <td align="center">    2 </td> <td align="center"> 2.121 </td> <td align="center"> 1.880 </td> <td align="center"> 2.659 </td> <td align="center"> 0.798 </td> <td align="center"> 0.000 </td> <td align="center"> 3.267 </td> <td align="center"> 0.000 </td> <td align="center"> 2.606 </td> <td align="center"> 1.128 </td> <td align="center"> 0.886 </td> <td align="center"> 0.853 </td> <td align="center"> 0.000 </td> <td align="center"> 3.686 </td> <td align="center"> 0.000 </td> <td align="center"> 3.267 </td> </tr>
  <tr> <td align="center">    3 </td> <td align="center"> 1.732 </td> <td align="center"> 1.023 </td> <td align="center"> 1.954 </td> <td align="center"> 0.886 </td> <td align="center"> 0.000 </td> <td align="center"> 2.568 </td> <td align="center"> 0.000 </td> <td align="center"> 2.276 </td> <td align="center"> 1.693 </td> <td align="center"> 0.591 </td> <td align="center"> 0.888 </td> <td align="center"> 0.000 </td> <td align="center"> 4.358 </td> <td align="center"> 0.000 </td> <td align="center"> 2.575 </td> </tr>
  <tr> <td align="center">    4 </td> <td align="center"> 1.500 </td> <td align="center"> 0.729 </td> <td align="center"> 1.628 </td> <td align="center"> 0.921 </td> <td align="center"> 0.000 </td> <td align="center"> 2.266 </td> <td align="center"> 0.000 </td> <td align="center"> 2.088 </td> <td align="center"> 2.059 </td> <td align="center"> 0.486 </td> <td align="center"> 0.880 </td> <td align="center"> 0.000 </td> <td align="center"> 4.698 </td> <td align="center"> 0.000 </td> <td align="center"> 2.282 </td> </tr>
  <tr> <td align="center">    5 </td> <td align="center"> 1.342 </td> <td align="center"> 0.577 </td> <td align="center"> 1.427 </td> <td align="center"> 0.940 </td> <td align="center"> 0.000 </td> <td align="center"> 2.089 </td> <td align="center"> 0.000 </td> <td align="center"> 1.964 </td> <td align="center"> 2.326 </td> <td align="center"> 0.430 </td> <td align="center"> 0.864 </td> <td align="center"> 0.000 </td> <td align="center"> 4.918 </td> <td align="center"> 0.000 </td> <td align="center"> 2.114 </td> </tr>
  <tr> <td align="center">    6 </td> <td align="center"> 1.225 </td> <td align="center"> 0.483 </td> <td align="center"> 1.287 </td> <td align="center"> 0.952 </td> <td align="center"> 0.030 </td> <td align="center"> 1.970 </td> <td align="center"> 0.029 </td> <td align="center"> 1.874 </td> <td align="center"> 2.534 </td> <td align="center"> 0.395 </td> <td align="center"> 0.848 </td> <td align="center"> 0.000 </td> <td align="center"> 5.079 </td> <td align="center"> 0.000 </td> <td align="center"> 2.004 </td> </tr>
  <tr> <td align="center">    7 </td> <td align="center"> 1.134 </td> <td align="center"> 0.419 </td> <td align="center"> 1.182 </td> <td align="center"> 0.959 </td> <td align="center"> 0.118 </td> <td align="center"> 1.882 </td> <td align="center"> 0.113 </td> <td align="center"> 1.806 </td> <td align="center"> 2.704 </td> <td align="center"> 0.370 </td> <td align="center"> 0.833 </td> <td align="center"> 0.205 </td> <td align="center"> 5.204 </td> <td align="center"> 0.076 </td> <td align="center"> 1.924 </td> </tr>
  <tr> <td align="center">    8 </td> <td align="center"> 1.061 </td> <td align="center"> 0.373 </td> <td align="center"> 1.099 </td> <td align="center"> 0.965 </td> <td align="center"> 0.185 </td> <td align="center"> 1.815 </td> <td align="center"> 0.179 </td> <td align="center"> 1.751 </td> <td align="center"> 2.847 </td> <td align="center"> 0.351 </td> <td align="center"> 0.820 </td> <td align="center"> 0.388 </td> <td align="center"> 5.307 </td> <td align="center"> 0.136 </td> <td align="center"> 1.864 </td> </tr>
  <tr> <td align="center">    9 </td> <td align="center"> 1.000 </td> <td align="center"> 0.337 </td> <td align="center"> 1.032 </td> <td align="center"> 0.969 </td> <td align="center"> 0.239 </td> <td align="center"> 1.761 </td> <td align="center"> 0.232 </td> <td align="center"> 1.707 </td> <td align="center"> 2.970 </td> <td align="center"> 0.337 </td> <td align="center"> 0.808 </td> <td align="center"> 0.547 </td> <td align="center"> 5.394 </td> <td align="center"> 0.184 </td> <td align="center"> 1.816 </td> </tr>
  <tr> <td align="center">   10 </td> <td align="center"> 0.949 </td> <td align="center"> 0.308 </td> <td align="center"> 0.975 </td> <td align="center"> 0.973 </td> <td align="center"> 0.284 </td> <td align="center"> 1.716 </td> <td align="center"> 0.276 </td> <td align="center"> 1.669 </td> <td align="center"> 3.078 </td> <td align="center"> 0.325 </td> <td align="center"> 0.797 </td> <td align="center"> 0.686 </td> <td align="center"> 5.469 </td> <td align="center"> 0.223 </td> <td align="center"> 1.777 </td> </tr>
  <tr> <td align="center">   11 </td> <td align="center"> 0.905 </td> <td align="center"> 0.285 </td> <td align="center"> 0.927 </td> <td align="center"> 0.975 </td> <td align="center"> 0.321 </td> <td align="center"> 1.679 </td> <td align="center"> 0.313 </td> <td align="center"> 1.637 </td> <td align="center"> 3.173 </td> <td align="center"> 0.315 </td> <td align="center"> 0.787 </td> <td align="center"> 0.811 </td> <td align="center"> 5.535 </td> <td align="center"> 0.256 </td> <td align="center"> 1.744 </td> </tr>
  <tr> <td align="center">   12 </td> <td align="center"> 0.866 </td> <td align="center"> 0.266 </td> <td align="center"> 0.886 </td> <td align="center"> 0.978 </td> <td align="center"> 0.354 </td> <td align="center"> 1.646 </td> <td align="center"> 0.346 </td> <td align="center"> 1.610 </td> <td align="center"> 3.258 </td> <td align="center"> 0.307 </td> <td align="center"> 0.778 </td> <td align="center"> 0.923 </td> <td align="center"> 5.594 </td> <td align="center"> 0.283 </td> <td align="center"> 1.717 </td> </tr>
  <tr> <td align="center">   13 </td> <td align="center"> 0.832 </td> <td align="center"> 0.249 </td> <td align="center"> 0.850 </td> <td align="center"> 0.979 </td> <td align="center"> 0.382 </td> <td align="center"> 1.618 </td> <td align="center"> 0.374 </td> <td align="center"> 1.585 </td> <td align="center"> 3.336 </td> <td align="center"> 0.300 </td> <td align="center"> 0.770 </td> <td align="center"> 1.025 </td> <td align="center"> 5.647 </td> <td align="center"> 0.307 </td> <td align="center"> 1.693 </td> </tr>
  <tr> <td align="center">   14 </td> <td align="center"> 0.802 </td> <td align="center"> 0.235 </td> <td align="center"> 0.817 </td> <td align="center"> 0.981 </td> <td align="center"> 0.406 </td> <td align="center"> 1.594 </td> <td align="center"> 0.399 </td> <td align="center"> 1.563 </td> <td align="center"> 3.407 </td> <td align="center"> 0.293 </td> <td align="center"> 0.763 </td> <td align="center"> 1.118 </td> <td align="center"> 5.696 </td> <td align="center"> 0.328 </td> <td align="center"> 1.672 </td> </tr>
  <tr> <td align="center">   15 </td> <td align="center"> 0.775 </td> <td align="center"> 0.223 </td> <td align="center"> 0.789 </td> <td align="center"> 0.982 </td> <td align="center"> 0.428 </td> <td align="center"> 1.572 </td> <td align="center"> 0.421 </td> <td align="center"> 1.544 </td> <td align="center"> 3.472 </td> <td align="center"> 0.288 </td> <td align="center"> 0.756 </td> <td align="center"> 1.203 </td> <td align="center"> 5.740 </td> <td align="center"> 0.347 </td> <td align="center"> 1.653 </td> </tr>
  <tr> <td align="center">   16 </td> <td align="center"> 0.750 </td> <td align="center"> 0.212 </td> <td align="center"> 0.763 </td> <td align="center"> 0.984 </td> <td align="center"> 0.448 </td> <td align="center"> 1.552 </td> <td align="center"> 0.440 </td> <td align="center"> 1.526 </td> <td align="center"> 3.532 </td> <td align="center"> 0.283 </td> <td align="center"> 0.750 </td> <td align="center"> 1.282 </td> <td align="center"> 5.782 </td> <td align="center"> 0.363 </td> <td align="center"> 1.637 </td> </tr>
  <tr> <td align="center">   17 </td> <td align="center"> 0.728 </td> <td align="center"> 0.203 </td> <td align="center"> 0.739 </td> <td align="center"> 0.985 </td> <td align="center"> 0.466 </td> <td align="center"> 1.534 </td> <td align="center"> 0.458 </td> <td align="center"> 1.511 </td> <td align="center"> 3.588 </td> <td align="center"> 0.279 </td> <td align="center"> 0.744 </td> <td align="center"> 1.356 </td> <td align="center"> 5.820 </td> <td align="center"> 0.378 </td> <td align="center"> 1.622 </td> </tr>
  <tr> <td align="center">   18 </td> <td align="center"> 0.707 </td> <td align="center"> 0.194 </td> <td align="center"> 0.718 </td> <td align="center"> 0.985 </td> <td align="center"> 0.482 </td> <td align="center"> 1.518 </td> <td align="center"> 0.475 </td> <td align="center"> 1.496 </td> <td align="center"> 3.640 </td> <td align="center"> 0.275 </td> <td align="center"> 0.739 </td> <td align="center"> 1.424 </td> <td align="center"> 5.856 </td> <td align="center"> 0.391 </td> <td align="center"> 1.609 </td> </tr>
  <tr> <td align="center">   19 </td> <td align="center"> 0.688 </td> <td align="center"> 0.187 </td> <td align="center"> 0.698 </td> <td align="center"> 0.986 </td> <td align="center"> 0.497 </td> <td align="center"> 1.503 </td> <td align="center"> 0.490 </td> <td align="center"> 1.483 </td> <td align="center"> 3.689 </td> <td align="center"> 0.271 </td> <td align="center"> 0.733 </td> <td align="center"> 1.489 </td> <td align="center"> 5.889 </td> <td align="center"> 0.404 </td> <td align="center"> 1.596 </td> </tr>
  <tr> <td align="center">   20 </td> <td align="center"> 0.671 </td> <td align="center"> 0.180 </td> <td align="center"> 0.680 </td> <td align="center"> 0.987 </td> <td align="center"> 0.510 </td> <td align="center"> 1.490 </td> <td align="center"> 0.504 </td> <td align="center"> 1.470 </td> <td align="center"> 3.735 </td> <td align="center"> 0.268 </td> <td align="center"> 0.729 </td> <td align="center"> 1.549 </td> <td align="center"> 5.921 </td> <td align="center"> 0.415 </td> <td align="center"> 1.585 </td> </tr>
  <tr> <td align="center">   21 </td> <td align="center"> 0.655 </td> <td align="center"> 0.173 </td> <td align="center"> 0.663 </td> <td align="center"> 0.988 </td> <td align="center"> 0.523 </td> <td align="center"> 1.477 </td> <td align="center"> 0.516 </td> <td align="center"> 1.459 </td> <td align="center"> 3.778 </td> <td align="center"> 0.265 </td> <td align="center"> 0.724 </td> <td align="center"> 1.606 </td> <td align="center"> 5.951 </td> <td align="center"> 0.425 </td> <td align="center"> 1.575 </td> </tr>
  <tr> <td align="center">   22 </td> <td align="center"> 0.640 </td> <td align="center"> 0.167 </td> <td align="center"> 0.647 </td> <td align="center"> 0.988 </td> <td align="center"> 0.534 </td> <td align="center"> 1.466 </td> <td align="center"> 0.528 </td> <td align="center"> 1.448 </td> <td align="center"> 3.819 </td> <td align="center"> 0.262 </td> <td align="center"> 0.720 </td> <td align="center"> 1.660 </td> <td align="center"> 5.979 </td> <td align="center"> 0.435 </td> <td align="center"> 1.565 </td> </tr>
  <tr> <td align="center">   23 </td> <td align="center"> 0.626 </td> <td align="center"> 0.162 </td> <td align="center"> 0.633 </td> <td align="center"> 0.989 </td> <td align="center"> 0.545 </td> <td align="center"> 1.455 </td> <td align="center"> 0.539 </td> <td align="center"> 1.438 </td> <td align="center"> 3.858 </td> <td align="center"> 0.259 </td> <td align="center"> 0.716 </td> <td align="center"> 1.711 </td> <td align="center"> 6.006 </td> <td align="center"> 0.443 </td> <td align="center"> 1.557 </td> </tr>
  <tr> <td align="center">   24 </td> <td align="center"> 0.612 </td> <td align="center"> 0.157 </td> <td align="center"> 0.619 </td> <td align="center"> 0.989 </td> <td align="center"> 0.555 </td> <td align="center"> 1.445 </td> <td align="center"> 0.549 </td> <td align="center"> 1.429 </td> <td align="center"> 3.895 </td> <td align="center"> 0.257 </td> <td align="center"> 0.712 </td> <td align="center"> 1.759 </td> <td align="center"> 6.032 </td> <td align="center"> 0.452 </td> <td align="center"> 1.548 </td> </tr>
  <tr> <td align="center">   25 </td> <td align="center"> 0.600 </td> <td align="center"> 0.153 </td> <td align="center"> 0.606 </td> <td align="center"> 0.990 </td> <td align="center"> 0.565 </td> <td align="center"> 1.435 </td> <td align="center"> 0.559 </td> <td align="center"> 1.420 </td> <td align="center"> 3.931 </td> <td align="center"> 0.254 </td> <td align="center"> 0.708 </td> <td align="center"> 1.805 </td> <td align="center"> 6.056 </td> <td align="center"> 0.459 </td> <td align="center"> 1.541 </td> </tr>
   </table>
<p style="page-break-before: always">
<h2 id="textnormal-distribution"><code>\(\text{Normal Distribution}\)</code></h2>
<p><img src="https://roh.engineering/posts/2018/05/pe-industrial-engineer-reference-sheet/index_files/figure-html/unnamed-chunk-7-1.png" width="192" style="display: block; margin: auto;" /></p>
<!-- html table generated in R 4.0.3 by xtable 1.8-4 package -->
<!-- Wed Feb 17 21:22:47 2021 -->
<table border='2' cellpadding='15' cellpadding='5' rules ='all' width ='100%'>
<caption align="top"> Table 2: Cumulative Probabilities of the Standard Normal Distribution, `\(X \sim N(0,1)\)` </caption>
<tr> <th> z </th> <th> 0 </th> <th> 0.01 </th> <th> 0.02 </th> <th> 0.03 </th> <th> 0.04 </th> <th> 0.05 </th> <th> 0.06 </th> <th> 0.07 </th> <th> 0.08 </th> <th> 0.09 </th>  </tr>
  <tr> <td align="center"> 0.0 </td> <td align="center"> 0.5000 </td> <td align="center"> 0.5040 </td> <td align="center"> 0.5080 </td> <td align="center"> 0.5120 </td> <td align="center"> 0.5160 </td> <td align="center"> 0.5199 </td> <td align="center"> 0.5239 </td> <td align="center"> 0.5279 </td> <td align="center"> 0.5319 </td> <td align="center"> 0.5359 </td> </tr>
  <tr> <td align="center"> 0.1 </td> <td align="center"> 0.5398 </td> <td align="center"> 0.5438 </td> <td align="center"> 0.5478 </td> <td align="center"> 0.5517 </td> <td align="center"> 0.5557 </td> <td align="center"> 0.5596 </td> <td align="center"> 0.5636 </td> <td align="center"> 0.5675 </td> <td align="center"> 0.5714 </td> <td align="center"> 0.5753 </td> </tr>
  <tr> <td align="center"> 0.2 </td> <td align="center"> 0.5793 </td> <td align="center"> 0.5832 </td> <td align="center"> 0.5871 </td> <td align="center"> 0.5910 </td> <td align="center"> 0.5948 </td> <td align="center"> 0.5987 </td> <td align="center"> 0.6026 </td> <td align="center"> 0.6064 </td> <td align="center"> 0.6103 </td> <td align="center"> 0.6141 </td> </tr>
  <tr> <td align="center"> 0.3 </td> <td align="center"> 0.6179 </td> <td align="center"> 0.6217 </td> <td align="center"> 0.6255 </td> <td align="center"> 0.6293 </td> <td align="center"> 0.6331 </td> <td align="center"> 0.6368 </td> <td align="center"> 0.6406 </td> <td align="center"> 0.6443 </td> <td align="center"> 0.6480 </td> <td align="center"> 0.6517 </td> </tr>
  <tr> <td align="center"> 0.4 </td> <td align="center"> 0.6554 </td> <td align="center"> 0.6591 </td> <td align="center"> 0.6628 </td> <td align="center"> 0.6664 </td> <td align="center"> 0.6700 </td> <td align="center"> 0.6736 </td> <td align="center"> 0.6772 </td> <td align="center"> 0.6808 </td> <td align="center"> 0.6844 </td> <td align="center"> 0.6879 </td> </tr>
  <tr> <td align="center"> 0.5 </td> <td align="center"> 0.6915 </td> <td align="center"> 0.6950 </td> <td align="center"> 0.6985 </td> <td align="center"> 0.7019 </td> <td align="center"> 0.7054 </td> <td align="center"> 0.7088 </td> <td align="center"> 0.7123 </td> <td align="center"> 0.7157 </td> <td align="center"> 0.7190 </td> <td align="center"> 0.7224 </td> </tr>
  <tr> <td align="center"> 0.6 </td> <td align="center"> 0.7257 </td> <td align="center"> 0.7291 </td> <td align="center"> 0.7324 </td> <td align="center"> 0.7357 </td> <td align="center"> 0.7389 </td> <td align="center"> 0.7422 </td> <td align="center"> 0.7454 </td> <td align="center"> 0.7486 </td> <td align="center"> 0.7517 </td> <td align="center"> 0.7549 </td> </tr>
  <tr> <td align="center"> 0.7 </td> <td align="center"> 0.7580 </td> <td align="center"> 0.7611 </td> <td align="center"> 0.7642 </td> <td align="center"> 0.7673 </td> <td align="center"> 0.7704 </td> <td align="center"> 0.7734 </td> <td align="center"> 0.7764 </td> <td align="center"> 0.7794 </td> <td align="center"> 0.7823 </td> <td align="center"> 0.7852 </td> </tr>
  <tr> <td align="center"> 0.8 </td> <td align="center"> 0.7881 </td> <td align="center"> 0.7910 </td> <td align="center"> 0.7939 </td> <td align="center"> 0.7967 </td> <td align="center"> 0.7995 </td> <td align="center"> 0.8023 </td> <td align="center"> 0.8051 </td> <td align="center"> 0.8078 </td> <td align="center"> 0.8106 </td> <td align="center"> 0.8133 </td> </tr>
  <tr> <td align="center"> 0.9 </td> <td align="center"> 0.8159 </td> <td align="center"> 0.8186 </td> <td align="center"> 0.8212 </td> <td align="center"> 0.8238 </td> <td align="center"> 0.8264 </td> <td align="center"> 0.8289 </td> <td align="center"> 0.8315 </td> <td align="center"> 0.8340 </td> <td align="center"> 0.8365 </td> <td align="center"> 0.8389 </td> </tr>
  <tr> <td align="center"> 1.0 </td> <td align="center"> 0.8413 </td> <td align="center"> 0.8438 </td> <td align="center"> 0.8461 </td> <td align="center"> 0.8485 </td> <td align="center"> 0.8508 </td> <td align="center"> 0.8531 </td> <td align="center"> 0.8554 </td> <td align="center"> 0.8577 </td> <td align="center"> 0.8599 </td> <td align="center"> 0.8621 </td> </tr>
  <tr> <td align="center"> 1.1 </td> <td align="center"> 0.8643 </td> <td align="center"> 0.8665 </td> <td align="center"> 0.8686 </td> <td align="center"> 0.8708 </td> <td align="center"> 0.8729 </td> <td align="center"> 0.8749 </td> <td align="center"> 0.8770 </td> <td align="center"> 0.8790 </td> <td align="center"> 0.8810 </td> <td align="center"> 0.8830 </td> </tr>
  <tr> <td align="center"> 1.2 </td> <td align="center"> 0.8849 </td> <td align="center"> 0.8869 </td> <td align="center"> 0.8888 </td> <td align="center"> 0.8907 </td> <td align="center"> 0.8925 </td> <td align="center"> 0.8944 </td> <td align="center"> 0.8962 </td> <td align="center"> 0.8980 </td> <td align="center"> 0.8997 </td> <td align="center"> 0.9015 </td> </tr>
  <tr> <td align="center"> 1.3 </td> <td align="center"> 0.9032 </td> <td align="center"> 0.9049 </td> <td align="center"> 0.9066 </td> <td align="center"> 0.9082 </td> <td align="center"> 0.9099 </td> <td align="center"> 0.9115 </td> <td align="center"> 0.9131 </td> <td align="center"> 0.9147 </td> <td align="center"> 0.9162 </td> <td align="center"> 0.9177 </td> </tr>
  <tr> <td align="center"> 1.4 </td> <td align="center"> 0.9192 </td> <td align="center"> 0.9207 </td> <td align="center"> 0.9222 </td> <td align="center"> 0.9236 </td> <td align="center"> 0.9251 </td> <td align="center"> 0.9265 </td> <td align="center"> 0.9279 </td> <td align="center"> 0.9292 </td> <td align="center"> 0.9306 </td> <td align="center"> 0.9319 </td> </tr>
  <tr> <td align="center"> 1.5 </td> <td align="center"> 0.9332 </td> <td align="center"> 0.9345 </td> <td align="center"> 0.9357 </td> <td align="center"> 0.9370 </td> <td align="center"> 0.9382 </td> <td align="center"> 0.9394 </td> <td align="center"> 0.9406 </td> <td align="center"> 0.9418 </td> <td align="center"> 0.9429 </td> <td align="center"> 0.9441 </td> </tr>
  <tr> <td align="center"> 1.6 </td> <td align="center"> 0.9452 </td> <td align="center"> 0.9463 </td> <td align="center"> 0.9474 </td> <td align="center"> 0.9484 </td> <td align="center"> 0.9495 </td> <td align="center"> 0.9505 </td> <td align="center"> 0.9515 </td> <td align="center"> 0.9525 </td> <td align="center"> 0.9535 </td> <td align="center"> 0.9545 </td> </tr>
  <tr> <td align="center"> 1.7 </td> <td align="center"> 0.9554 </td> <td align="center"> 0.9564 </td> <td align="center"> 0.9573 </td> <td align="center"> 0.9582 </td> <td align="center"> 0.9591 </td> <td align="center"> 0.9599 </td> <td align="center"> 0.9608 </td> <td align="center"> 0.9616 </td> <td align="center"> 0.9625 </td> <td align="center"> 0.9633 </td> </tr>
  <tr> <td align="center"> 1.8 </td> <td align="center"> 0.9641 </td> <td align="center"> 0.9649 </td> <td align="center"> 0.9656 </td> <td align="center"> 0.9664 </td> <td align="center"> 0.9671 </td> <td align="center"> 0.9678 </td> <td align="center"> 0.9686 </td> <td align="center"> 0.9693 </td> <td align="center"> 0.9699 </td> <td align="center"> 0.9706 </td> </tr>
  <tr> <td align="center"> 1.9 </td> <td align="center"> 0.9713 </td> <td align="center"> 0.9719 </td> <td align="center"> 0.9726 </td> <td align="center"> 0.9732 </td> <td align="center"> 0.9738 </td> <td align="center"> 0.9744 </td> <td align="center"> 0.9750 </td> <td align="center"> 0.9756 </td> <td align="center"> 0.9761 </td> <td align="center"> 0.9767 </td> </tr>
  <tr> <td align="center"> 2.0 </td> <td align="center"> 0.9772 </td> <td align="center"> 0.9778 </td> <td align="center"> 0.9783 </td> <td align="center"> 0.9788 </td> <td align="center"> 0.9793 </td> <td align="center"> 0.9798 </td> <td align="center"> 0.9803 </td> <td align="center"> 0.9808 </td> <td align="center"> 0.9812 </td> <td align="center"> 0.9817 </td> </tr>
  <tr> <td align="center"> 2.1 </td> <td align="center"> 0.9821 </td> <td align="center"> 0.9826 </td> <td align="center"> 0.9830 </td> <td align="center"> 0.9834 </td> <td align="center"> 0.9838 </td> <td align="center"> 0.9842 </td> <td align="center"> 0.9846 </td> <td align="center"> 0.9850 </td> <td align="center"> 0.9854 </td> <td align="center"> 0.9857 </td> </tr>
  <tr> <td align="center"> 2.2 </td> <td align="center"> 0.9861 </td> <td align="center"> 0.9864 </td> <td align="center"> 0.9868 </td> <td align="center"> 0.9871 </td> <td align="center"> 0.9875 </td> <td align="center"> 0.9878 </td> <td align="center"> 0.9881 </td> <td align="center"> 0.9884 </td> <td align="center"> 0.9887 </td> <td align="center"> 0.9890 </td> </tr>
  <tr> <td align="center"> 2.3 </td> <td align="center"> 0.9893 </td> <td align="center"> 0.9896 </td> <td align="center"> 0.9898 </td> <td align="center"> 0.9901 </td> <td align="center"> 0.9904 </td> <td align="center"> 0.9906 </td> <td align="center"> 0.9909 </td> <td align="center"> 0.9911 </td> <td align="center"> 0.9913 </td> <td align="center"> 0.9916 </td> </tr>
  <tr> <td align="center"> 2.4 </td> <td align="center"> 0.9918 </td> <td align="center"> 0.9920 </td> <td align="center"> 0.9922 </td> <td align="center"> 0.9925 </td> <td align="center"> 0.9927 </td> <td align="center"> 0.9929 </td> <td align="center"> 0.9931 </td> <td align="center"> 0.9932 </td> <td align="center"> 0.9934 </td> <td align="center"> 0.9936 </td> </tr>
  <tr> <td align="center"> 2.5 </td> <td align="center"> 0.9938 </td> <td align="center"> 0.9940 </td> <td align="center"> 0.9941 </td> <td align="center"> 0.9943 </td> <td align="center"> 0.9945 </td> <td align="center"> 0.9946 </td> <td align="center"> 0.9948 </td> <td align="center"> 0.9949 </td> <td align="center"> 0.9951 </td> <td align="center"> 0.9952 </td> </tr>
  <tr> <td align="center"> 2.6 </td> <td align="center"> 0.9953 </td> <td align="center"> 0.9955 </td> <td align="center"> 0.9956 </td> <td align="center"> 0.9957 </td> <td align="center"> 0.9959 </td> <td align="center"> 0.9960 </td> <td align="center"> 0.9961 </td> <td align="center"> 0.9962 </td> <td align="center"> 0.9963 </td> <td align="center"> 0.9964 </td> </tr>
  <tr> <td align="center"> 2.7 </td> <td align="center"> 0.9965 </td> <td align="center"> 0.9966 </td> <td align="center"> 0.9967 </td> <td align="center"> 0.9968 </td> <td align="center"> 0.9969 </td> <td align="center"> 0.9970 </td> <td align="center"> 0.9971 </td> <td align="center"> 0.9972 </td> <td align="center"> 0.9973 </td> <td align="center"> 0.9974 </td> </tr>
  <tr> <td align="center"> 2.8 </td> <td align="center"> 0.9974 </td> <td align="center"> 0.9975 </td> <td align="center"> 0.9976 </td> <td align="center"> 0.9977 </td> <td align="center"> 0.9977 </td> <td align="center"> 0.9978 </td> <td align="center"> 0.9979 </td> <td align="center"> 0.9979 </td> <td align="center"> 0.9980 </td> <td align="center"> 0.9981 </td> </tr>
  <tr> <td align="center"> 2.9 </td> <td align="center"> 0.9981 </td> <td align="center"> 0.9982 </td> <td align="center"> 0.9982 </td> <td align="center"> 0.9983 </td> <td align="center"> 0.9984 </td> <td align="center"> 0.9984 </td> <td align="center"> 0.9985 </td> <td align="center"> 0.9985 </td> <td align="center"> 0.9986 </td> <td align="center"> 0.9986 </td> </tr>
  <tr> <td align="center"> 3.0 </td> <td align="center"> 0.9987 </td> <td align="center"> 0.9987 </td> <td align="center"> 0.9987 </td> <td align="center"> 0.9988 </td> <td align="center"> 0.9988 </td> <td align="center"> 0.9989 </td> <td align="center"> 0.9989 </td> <td align="center"> 0.9989 </td> <td align="center"> 0.9990 </td> <td align="center"> 0.9990 </td> </tr>
  <tr> <td align="center"> 3.1 </td> <td align="center"> 0.9990 </td> <td align="center"> 0.9991 </td> <td align="center"> 0.9991 </td> <td align="center"> 0.9991 </td> <td align="center"> 0.9992 </td> <td align="center"> 0.9992 </td> <td align="center"> 0.9992 </td> <td align="center"> 0.9992 </td> <td align="center"> 0.9993 </td> <td align="center"> 0.9993 </td> </tr>
  <tr> <td align="center"> 3.2 </td> <td align="center"> 0.9993 </td> <td align="center"> 0.9993 </td> <td align="center"> 0.9994 </td> <td align="center"> 0.9994 </td> <td align="center"> 0.9994 </td> <td align="center"> 0.9994 </td> <td align="center"> 0.9994 </td> <td align="center"> 0.9995 </td> <td align="center"> 0.9995 </td> <td align="center"> 0.9995 </td> </tr>
  <tr> <td align="center"> 3.3 </td> <td align="center"> 0.9995 </td> <td align="center"> 0.9995 </td> <td align="center"> 0.9995 </td> <td align="center"> 0.9996 </td> <td align="center"> 0.9996 </td> <td align="center"> 0.9996 </td> <td align="center"> 0.9996 </td> <td align="center"> 0.9996 </td> <td align="center"> 0.9996 </td> <td align="center"> 0.9997 </td> </tr>
  <tr> <td align="center"> 3.4 </td> <td align="center"> 0.9997 </td> <td align="center"> 0.9997 </td> <td align="center"> 0.9997 </td> <td align="center"> 0.9997 </td> <td align="center"> 0.9997 </td> <td align="center"> 0.9997 </td> <td align="center"> 0.9997 </td> <td align="center"> 0.9997 </td> <td align="center"> 0.9997 </td> <td align="center"> 0.9998 </td> </tr>
   </table>
<p style="page-break-before: always">
<h2 id="t-text-distribution"><code>\(t \text{ Distribution}\)</code></h2>
<p><img src="https://roh.engineering/posts/2018/05/pe-industrial-engineer-reference-sheet/index_files/figure-html/unnamed-chunk-8-1.png" width="192" style="display: block; margin: auto;" /></p>
<!-- html table generated in R 4.0.3 by xtable 1.8-4 package -->
<!-- Wed Feb 17 21:22:47 2021 -->
<table border='2' cellpadding='15' cellpadding='5' rules ='all' width ='100%'>
<caption align="top"> Table 3: Percentiles of the *t* Distribution </caption>
<tr> <th> `\(v \big\backslash \alpha\)` </th> <th> 0.1 </th> <th> 0.05 </th> <th> 0.025 </th> <th> 0.01 </th> <th> 0.005 </th>  </tr>
  <tr> <td align="center"> 1 </td> <td align="center"> 3.0777 </td> <td align="center"> 6.3138 </td> <td align="center"> 12.7062 </td> <td align="center"> 31.8205 </td> <td align="center"> 63.6567 </td> </tr>
  <tr> <td align="center"> 2 </td> <td align="center"> 1.8856 </td> <td align="center"> 2.9200 </td> <td align="center"> 4.3027 </td> <td align="center"> 6.9646 </td> <td align="center"> 9.9248 </td> </tr>
  <tr> <td align="center"> 3 </td> <td align="center"> 1.6377 </td> <td align="center"> 2.3534 </td> <td align="center"> 3.1824 </td> <td align="center"> 4.5407 </td> <td align="center"> 5.8409 </td> </tr>
  <tr> <td align="center"> 4 </td> <td align="center"> 1.5332 </td> <td align="center"> 2.1318 </td> <td align="center"> 2.7764 </td> <td align="center"> 3.7469 </td> <td align="center"> 4.6041 </td> </tr>
  <tr> <td align="center"> 5 </td> <td align="center"> 1.4759 </td> <td align="center"> 2.0150 </td> <td align="center"> 2.5706 </td> <td align="center"> 3.3649 </td> <td align="center"> 4.0321 </td> </tr>
  <tr> <td align="center"> 6 </td> <td align="center"> 1.4398 </td> <td align="center"> 1.9432 </td> <td align="center"> 2.4469 </td> <td align="center"> 3.1427 </td> <td align="center"> 3.7074 </td> </tr>
  <tr> <td align="center"> 7 </td> <td align="center"> 1.4149 </td> <td align="center"> 1.8946 </td> <td align="center"> 2.3646 </td> <td align="center"> 2.9980 </td> <td align="center"> 3.4995 </td> </tr>
  <tr> <td align="center"> 8 </td> <td align="center"> 1.3968 </td> <td align="center"> 1.8595 </td> <td align="center"> 2.3060 </td> <td align="center"> 2.8965 </td> <td align="center"> 3.3554 </td> </tr>
  <tr> <td align="center"> 9 </td> <td align="center"> 1.3830 </td> <td align="center"> 1.8331 </td> <td align="center"> 2.2622 </td> <td align="center"> 2.8214 </td> <td align="center"> 3.2498 </td> </tr>
  <tr> <td align="center"> 10 </td> <td align="center"> 1.3722 </td> <td align="center"> 1.8125 </td> <td align="center"> 2.2281 </td> <td align="center"> 2.7638 </td> <td align="center"> 3.1693 </td> </tr>
  <tr> <td align="center"> 11 </td> <td align="center"> 1.3634 </td> <td align="center"> 1.7959 </td> <td align="center"> 2.2010 </td> <td align="center"> 2.7181 </td> <td align="center"> 3.1058 </td> </tr>
  <tr> <td align="center"> 12 </td> <td align="center"> 1.3562 </td> <td align="center"> 1.7823 </td> <td align="center"> 2.1788 </td> <td align="center"> 2.6810 </td> <td align="center"> 3.0545 </td> </tr>
  <tr> <td align="center"> 13 </td> <td align="center"> 1.3502 </td> <td align="center"> 1.7709 </td> <td align="center"> 2.1604 </td> <td align="center"> 2.6503 </td> <td align="center"> 3.0123 </td> </tr>
  <tr> <td align="center"> 14 </td> <td align="center"> 1.3450 </td> <td align="center"> 1.7613 </td> <td align="center"> 2.1448 </td> <td align="center"> 2.6245 </td> <td align="center"> 2.9768 </td> </tr>
  <tr> <td align="center"> 15 </td> <td align="center"> 1.3406 </td> <td align="center"> 1.7531 </td> <td align="center"> 2.1314 </td> <td align="center"> 2.6025 </td> <td align="center"> 2.9467 </td> </tr>
  <tr> <td align="center"> 16 </td> <td align="center"> 1.3368 </td> <td align="center"> 1.7459 </td> <td align="center"> 2.1199 </td> <td align="center"> 2.5835 </td> <td align="center"> 2.9208 </td> </tr>
  <tr> <td align="center"> 17 </td> <td align="center"> 1.3334 </td> <td align="center"> 1.7396 </td> <td align="center"> 2.1098 </td> <td align="center"> 2.5669 </td> <td align="center"> 2.8982 </td> </tr>
  <tr> <td align="center"> 18 </td> <td align="center"> 1.3304 </td> <td align="center"> 1.7341 </td> <td align="center"> 2.1009 </td> <td align="center"> 2.5524 </td> <td align="center"> 2.8784 </td> </tr>
  <tr> <td align="center"> 19 </td> <td align="center"> 1.3277 </td> <td align="center"> 1.7291 </td> <td align="center"> 2.0930 </td> <td align="center"> 2.5395 </td> <td align="center"> 2.8609 </td> </tr>
  <tr> <td align="center"> 20 </td> <td align="center"> 1.3253 </td> <td align="center"> 1.7247 </td> <td align="center"> 2.0860 </td> <td align="center"> 2.5280 </td> <td align="center"> 2.8453 </td> </tr>
  <tr> <td align="center"> 21 </td> <td align="center"> 1.3232 </td> <td align="center"> 1.7207 </td> <td align="center"> 2.0796 </td> <td align="center"> 2.5176 </td> <td align="center"> 2.8314 </td> </tr>
  <tr> <td align="center"> 22 </td> <td align="center"> 1.3212 </td> <td align="center"> 1.7171 </td> <td align="center"> 2.0739 </td> <td align="center"> 2.5083 </td> <td align="center"> 2.8188 </td> </tr>
  <tr> <td align="center"> 23 </td> <td align="center"> 1.3195 </td> <td align="center"> 1.7139 </td> <td align="center"> 2.0687 </td> <td align="center"> 2.4999 </td> <td align="center"> 2.8073 </td> </tr>
  <tr> <td align="center"> 24 </td> <td align="center"> 1.3178 </td> <td align="center"> 1.7109 </td> <td align="center"> 2.0639 </td> <td align="center"> 2.4922 </td> <td align="center"> 2.7969 </td> </tr>
  <tr> <td align="center"> 25 </td> <td align="center"> 1.3163 </td> <td align="center"> 1.7081 </td> <td align="center"> 2.0595 </td> <td align="center"> 2.4851 </td> <td align="center"> 2.7874 </td> </tr>
  <tr> <td align="center"> 26 </td> <td align="center"> 1.3150 </td> <td align="center"> 1.7056 </td> <td align="center"> 2.0555 </td> <td align="center"> 2.4786 </td> <td align="center"> 2.7787 </td> </tr>
  <tr> <td align="center"> 27 </td> <td align="center"> 1.3137 </td> <td align="center"> 1.7033 </td> <td align="center"> 2.0518 </td> <td align="center"> 2.4727 </td> <td align="center"> 2.7707 </td> </tr>
  <tr> <td align="center"> 28 </td> <td align="center"> 1.3125 </td> <td align="center"> 1.7011 </td> <td align="center"> 2.0484 </td> <td align="center"> 2.4671 </td> <td align="center"> 2.7633 </td> </tr>
  <tr> <td align="center"> 29 </td> <td align="center"> 1.3114 </td> <td align="center"> 1.6991 </td> <td align="center"> 2.0452 </td> <td align="center"> 2.4620 </td> <td align="center"> 2.7564 </td> </tr>
  <tr> <td align="center"> 30 </td> <td align="center"> 1.3104 </td> <td align="center"> 1.6973 </td> <td align="center"> 2.0423 </td> <td align="center"> 2.4573 </td> <td align="center"> 2.7500 </td> </tr>
  <tr> <td align="center"> Inf </td> <td align="center"> 1.2816 </td> <td align="center"> 1.6449 </td> <td align="center"> 1.9600 </td> <td align="center"> 2.3263 </td> <td align="center"> 2.5758 </td> </tr>
   </table>
<p style="page-break-before: always">
<h2 id="chi2-text-distribution"><code>\(\chi^2 \text{ Distribution}\)</code></h2>
<p><img src="https://roh.engineering/posts/2018/05/pe-industrial-engineer-reference-sheet/index_files/figure-html/unnamed-chunk-9-1.png" width="192" style="display: block; margin: auto;" /></p>
<!-- html table generated in R 4.0.3 by xtable 1.8-4 package -->
<!-- Wed Feb 17 21:22:48 2021 -->
<table border='2' cellpadding='15' cellpadding='5' rules ='all' width ='100%'>
<caption align="top"> Table 4: Percentiles of the `\(\chi^2\)` Distribution </caption>
<tr> <th> `\(v \big\backslash \alpha\)` </th> <th> 0.995 </th> <th> 0.99 </th> <th> 0.975 </th> <th> 0.95 </th> <th> 0.9 </th> <th> 0.75 </th> <th> 0.5 </th> <th> 0.25 </th> <th> 0.1 </th> <th> 0.05 </th> <th> 0.025 </th> <th> 0.01 </th> <th> 0.005 </th> <th> 0.001 </th>  </tr>
  <tr> <td align="center"> 1 </td> <td align="center"> 0.00 </td> <td align="center"> 0.00 </td> <td align="center"> 0.00 </td> <td align="center"> 0.00 </td> <td align="center"> 0.02 </td> <td align="center"> 0.10 </td> <td align="center"> 0.45 </td> <td align="center"> 1.32 </td> <td align="center"> 2.71 </td> <td align="center"> 3.84 </td> <td align="center"> 5.02 </td> <td align="center"> 6.63 </td> <td align="center"> 7.88 </td> <td align="center"> 10.83 </td> </tr>
  <tr> <td align="center"> 2 </td> <td align="center"> 0.01 </td> <td align="center"> 0.02 </td> <td align="center"> 0.05 </td> <td align="center"> 0.10 </td> <td align="center"> 0.21 </td> <td align="center"> 0.58 </td> <td align="center"> 1.39 </td> <td align="center"> 2.77 </td> <td align="center"> 4.61 </td> <td align="center"> 5.99 </td> <td align="center"> 7.38 </td> <td align="center"> 9.21 </td> <td align="center"> 10.60 </td> <td align="center"> 13.82 </td> </tr>
  <tr> <td align="center"> 3 </td> <td align="center"> 0.07 </td> <td align="center"> 0.11 </td> <td align="center"> 0.22 </td> <td align="center"> 0.35 </td> <td align="center"> 0.58 </td> <td align="center"> 1.21 </td> <td align="center"> 2.37 </td> <td align="center"> 4.11 </td> <td align="center"> 6.25 </td> <td align="center"> 7.81 </td> <td align="center"> 9.35 </td> <td align="center"> 11.34 </td> <td align="center"> 12.84 </td> <td align="center"> 16.27 </td> </tr>
  <tr> <td align="center"> 4 </td> <td align="center"> 0.21 </td> <td align="center"> 0.30 </td> <td align="center"> 0.48 </td> <td align="center"> 0.71 </td> <td align="center"> 1.06 </td> <td align="center"> 1.92 </td> <td align="center"> 3.36 </td> <td align="center"> 5.39 </td> <td align="center"> 7.78 </td> <td align="center"> 9.49 </td> <td align="center"> 11.14 </td> <td align="center"> 13.28 </td> <td align="center"> 14.86 </td> <td align="center"> 18.47 </td> </tr>
  <tr> <td align="center"> 5 </td> <td align="center"> 0.41 </td> <td align="center"> 0.55 </td> <td align="center"> 0.83 </td> <td align="center"> 1.15 </td> <td align="center"> 1.61 </td> <td align="center"> 2.67 </td> <td align="center"> 4.35 </td> <td align="center"> 6.63 </td> <td align="center"> 9.24 </td> <td align="center"> 11.07 </td> <td align="center"> 12.83 </td> <td align="center"> 15.09 </td> <td align="center"> 16.75 </td> <td align="center"> 20.52 </td> </tr>
  <tr> <td align="center"> 6 </td> <td align="center"> 0.68 </td> <td align="center"> 0.87 </td> <td align="center"> 1.24 </td> <td align="center"> 1.64 </td> <td align="center"> 2.20 </td> <td align="center"> 3.45 </td> <td align="center"> 5.35 </td> <td align="center"> 7.84 </td> <td align="center"> 10.64 </td> <td align="center"> 12.59 </td> <td align="center"> 14.45 </td> <td align="center"> 16.81 </td> <td align="center"> 18.55 </td> <td align="center"> 22.46 </td> </tr>
  <tr> <td align="center"> 7 </td> <td align="center"> 0.99 </td> <td align="center"> 1.24 </td> <td align="center"> 1.69 </td> <td align="center"> 2.17 </td> <td align="center"> 2.83 </td> <td align="center"> 4.25 </td> <td align="center"> 6.35 </td> <td align="center"> 9.04 </td> <td align="center"> 12.02 </td> <td align="center"> 14.07 </td> <td align="center"> 16.01 </td> <td align="center"> 18.48 </td> <td align="center"> 20.28 </td> <td align="center"> 24.32 </td> </tr>
  <tr> <td align="center"> 8 </td> <td align="center"> 1.34 </td> <td align="center"> 1.65 </td> <td align="center"> 2.18 </td> <td align="center"> 2.73 </td> <td align="center"> 3.49 </td> <td align="center"> 5.07 </td> <td align="center"> 7.34 </td> <td align="center"> 10.22 </td> <td align="center"> 13.36 </td> <td align="center"> 15.51 </td> <td align="center"> 17.53 </td> <td align="center"> 20.09 </td> <td align="center"> 21.95 </td> <td align="center"> 26.12 </td> </tr>
  <tr> <td align="center"> 9 </td> <td align="center"> 1.73 </td> <td align="center"> 2.09 </td> <td align="center"> 2.70 </td> <td align="center"> 3.33 </td> <td align="center"> 4.17 </td> <td align="center"> 5.90 </td> <td align="center"> 8.34 </td> <td align="center"> 11.39 </td> <td align="center"> 14.68 </td> <td align="center"> 16.92 </td> <td align="center"> 19.02 </td> <td align="center"> 21.67 </td> <td align="center"> 23.59 </td> <td align="center"> 27.88 </td> </tr>
  <tr> <td align="center"> 10 </td> <td align="center"> 2.16 </td> <td align="center"> 2.56 </td> <td align="center"> 3.25 </td> <td align="center"> 3.94 </td> <td align="center"> 4.87 </td> <td align="center"> 6.74 </td> <td align="center"> 9.34 </td> <td align="center"> 12.55 </td> <td align="center"> 15.99 </td> <td align="center"> 18.31 </td> <td align="center"> 20.48 </td> <td align="center"> 23.21 </td> <td align="center"> 25.19 </td> <td align="center"> 29.59 </td> </tr>
  <tr> <td align="center"> 11 </td> <td align="center"> 2.60 </td> <td align="center"> 3.05 </td> <td align="center"> 3.82 </td> <td align="center"> 4.57 </td> <td align="center"> 5.58 </td> <td align="center"> 7.58 </td> <td align="center"> 10.34 </td> <td align="center"> 13.70 </td> <td align="center"> 17.28 </td> <td align="center"> 19.68 </td> <td align="center"> 21.92 </td> <td align="center"> 24.72 </td> <td align="center"> 26.76 </td> <td align="center"> 31.26 </td> </tr>
  <tr> <td align="center"> 12 </td> <td align="center"> 3.07 </td> <td align="center"> 3.57 </td> <td align="center"> 4.40 </td> <td align="center"> 5.23 </td> <td align="center"> 6.30 </td> <td align="center"> 8.44 </td> <td align="center"> 11.34 </td> <td align="center"> 14.85 </td> <td align="center"> 18.55 </td> <td align="center"> 21.03 </td> <td align="center"> 23.34 </td> <td align="center"> 26.22 </td> <td align="center"> 28.30 </td> <td align="center"> 32.91 </td> </tr>
  <tr> <td align="center"> 13 </td> <td align="center"> 3.57 </td> <td align="center"> 4.11 </td> <td align="center"> 5.01 </td> <td align="center"> 5.89 </td> <td align="center"> 7.04 </td> <td align="center"> 9.30 </td> <td align="center"> 12.34 </td> <td align="center"> 15.98 </td> <td align="center"> 19.81 </td> <td align="center"> 22.36 </td> <td align="center"> 24.74 </td> <td align="center"> 27.69 </td> <td align="center"> 29.82 </td> <td align="center"> 34.53 </td> </tr>
  <tr> <td align="center"> 14 </td> <td align="center"> 4.07 </td> <td align="center"> 4.66 </td> <td align="center"> 5.63 </td> <td align="center"> 6.57 </td> <td align="center"> 7.79 </td> <td align="center"> 10.17 </td> <td align="center"> 13.34 </td> <td align="center"> 17.12 </td> <td align="center"> 21.06 </td> <td align="center"> 23.68 </td> <td align="center"> 26.12 </td> <td align="center"> 29.14 </td> <td align="center"> 31.32 </td> <td align="center"> 36.12 </td> </tr>
  <tr> <td align="center"> 15 </td> <td align="center"> 4.60 </td> <td align="center"> 5.23 </td> <td align="center"> 6.26 </td> <td align="center"> 7.26 </td> <td align="center"> 8.55 </td> <td align="center"> 11.04 </td> <td align="center"> 14.34 </td> <td align="center"> 18.25 </td> <td align="center"> 22.31 </td> <td align="center"> 25.00 </td> <td align="center"> 27.49 </td> <td align="center"> 30.58 </td> <td align="center"> 32.80 </td> <td align="center"> 37.70 </td> </tr>
  <tr> <td align="center"> 16 </td> <td align="center"> 5.14 </td> <td align="center"> 5.81 </td> <td align="center"> 6.91 </td> <td align="center"> 7.96 </td> <td align="center"> 9.31 </td> <td align="center"> 11.91 </td> <td align="center"> 15.34 </td> <td align="center"> 19.37 </td> <td align="center"> 23.54 </td> <td align="center"> 26.30 </td> <td align="center"> 28.85 </td> <td align="center"> 32.00 </td> <td align="center"> 34.27 </td> <td align="center"> 39.25 </td> </tr>
  <tr> <td align="center"> 17 </td> <td align="center"> 5.70 </td> <td align="center"> 6.41 </td> <td align="center"> 7.56 </td> <td align="center"> 8.67 </td> <td align="center"> 10.09 </td> <td align="center"> 12.79 </td> <td align="center"> 16.34 </td> <td align="center"> 20.49 </td> <td align="center"> 24.77 </td> <td align="center"> 27.59 </td> <td align="center"> 30.19 </td> <td align="center"> 33.41 </td> <td align="center"> 35.72 </td> <td align="center"> 40.79 </td> </tr>
  <tr> <td align="center"> 18 </td> <td align="center"> 6.26 </td> <td align="center"> 7.01 </td> <td align="center"> 8.23 </td> <td align="center"> 9.39 </td> <td align="center"> 10.86 </td> <td align="center"> 13.68 </td> <td align="center"> 17.34 </td> <td align="center"> 21.60 </td> <td align="center"> 25.99 </td> <td align="center"> 28.87 </td> <td align="center"> 31.53 </td> <td align="center"> 34.81 </td> <td align="center"> 37.16 </td> <td align="center"> 42.31 </td> </tr>
  <tr> <td align="center"> 19 </td> <td align="center"> 6.84 </td> <td align="center"> 7.63 </td> <td align="center"> 8.91 </td> <td align="center"> 10.12 </td> <td align="center"> 11.65 </td> <td align="center"> 14.56 </td> <td align="center"> 18.34 </td> <td align="center"> 22.72 </td> <td align="center"> 27.20 </td> <td align="center"> 30.14 </td> <td align="center"> 32.85 </td> <td align="center"> 36.19 </td> <td align="center"> 38.58 </td> <td align="center"> 43.82 </td> </tr>
  <tr> <td align="center"> 20 </td> <td align="center"> 7.43 </td> <td align="center"> 8.26 </td> <td align="center"> 9.59 </td> <td align="center"> 10.85 </td> <td align="center"> 12.44 </td> <td align="center"> 15.45 </td> <td align="center"> 19.34 </td> <td align="center"> 23.83 </td> <td align="center"> 28.41 </td> <td align="center"> 31.41 </td> <td align="center"> 34.17 </td> <td align="center"> 37.57 </td> <td align="center"> 40.00 </td> <td align="center"> 45.31 </td> </tr>
  <tr> <td align="center"> 21 </td> <td align="center"> 8.03 </td> <td align="center"> 8.90 </td> <td align="center"> 10.28 </td> <td align="center"> 11.59 </td> <td align="center"> 13.24 </td> <td align="center"> 16.34 </td> <td align="center"> 20.34 </td> <td align="center"> 24.93 </td> <td align="center"> 29.62 </td> <td align="center"> 32.67 </td> <td align="center"> 35.48 </td> <td align="center"> 38.93 </td> <td align="center"> 41.40 </td> <td align="center"> 46.80 </td> </tr>
  <tr> <td align="center"> 22 </td> <td align="center"> 8.64 </td> <td align="center"> 9.54 </td> <td align="center"> 10.98 </td> <td align="center"> 12.34 </td> <td align="center"> 14.04 </td> <td align="center"> 17.24 </td> <td align="center"> 21.34 </td> <td align="center"> 26.04 </td> <td align="center"> 30.81 </td> <td align="center"> 33.92 </td> <td align="center"> 36.78 </td> <td align="center"> 40.29 </td> <td align="center"> 42.80 </td> <td align="center"> 48.27 </td> </tr>
  <tr> <td align="center"> 23 </td> <td align="center"> 9.26 </td> <td align="center"> 10.20 </td> <td align="center"> 11.69 </td> <td align="center"> 13.09 </td> <td align="center"> 14.85 </td> <td align="center"> 18.14 </td> <td align="center"> 22.34 </td> <td align="center"> 27.14 </td> <td align="center"> 32.01 </td> <td align="center"> 35.17 </td> <td align="center"> 38.08 </td> <td align="center"> 41.64 </td> <td align="center"> 44.18 </td> <td align="center"> 49.73 </td> </tr>
  <tr> <td align="center"> 24 </td> <td align="center"> 9.89 </td> <td align="center"> 10.86 </td> <td align="center"> 12.40 </td> <td align="center"> 13.85 </td> <td align="center"> 15.66 </td> <td align="center"> 19.04 </td> <td align="center"> 23.34 </td> <td align="center"> 28.24 </td> <td align="center"> 33.20 </td> <td align="center"> 36.42 </td> <td align="center"> 39.36 </td> <td align="center"> 42.98 </td> <td align="center"> 45.56 </td> <td align="center"> 51.18 </td> </tr>
  <tr> <td align="center"> 25 </td> <td align="center"> 10.52 </td> <td align="center"> 11.52 </td> <td align="center"> 13.12 </td> <td align="center"> 14.61 </td> <td align="center"> 16.47 </td> <td align="center"> 19.94 </td> <td align="center"> 24.34 </td> <td align="center"> 29.34 </td> <td align="center"> 34.38 </td> <td align="center"> 37.65 </td> <td align="center"> 40.65 </td> <td align="center"> 44.31 </td> <td align="center"> 46.93 </td> <td align="center"> 52.62 </td> </tr>
  <tr> <td align="center"> 30 </td> <td align="center"> 13.79 </td> <td align="center"> 14.95 </td> <td align="center"> 16.79 </td> <td align="center"> 18.49 </td> <td align="center"> 20.60 </td> <td align="center"> 24.48 </td> <td align="center"> 29.34 </td> <td align="center"> 34.80 </td> <td align="center"> 40.26 </td> <td align="center"> 43.77 </td> <td align="center"> 46.98 </td> <td align="center"> 50.89 </td> <td align="center"> 53.67 </td> <td align="center"> 59.70 </td> </tr>
  <tr> <td align="center"> 40 </td> <td align="center"> 20.71 </td> <td align="center"> 22.16 </td> <td align="center"> 24.43 </td> <td align="center"> 26.51 </td> <td align="center"> 29.05 </td> <td align="center"> 33.66 </td> <td align="center"> 39.34 </td> <td align="center"> 45.62 </td> <td align="center"> 51.81 </td> <td align="center"> 55.76 </td> <td align="center"> 59.34 </td> <td align="center"> 63.69 </td> <td align="center"> 66.77 </td> <td align="center"> 73.40 </td> </tr>
  <tr> <td align="center"> 50 </td> <td align="center"> 27.99 </td> <td align="center"> 29.71 </td> <td align="center"> 32.36 </td> <td align="center"> 34.76 </td> <td align="center"> 37.69 </td> <td align="center"> 42.94 </td> <td align="center"> 49.33 </td> <td align="center"> 56.33 </td> <td align="center"> 63.17 </td> <td align="center"> 67.50 </td> <td align="center"> 71.42 </td> <td align="center"> 76.15 </td> <td align="center"> 79.49 </td> <td align="center"> 86.66 </td> </tr>
  <tr> <td align="center"> 60 </td> <td align="center"> 35.53 </td> <td align="center"> 37.48 </td> <td align="center"> 40.48 </td> <td align="center"> 43.19 </td> <td align="center"> 46.46 </td> <td align="center"> 52.29 </td> <td align="center"> 59.33 </td> <td align="center"> 66.98 </td> <td align="center"> 74.40 </td> <td align="center"> 79.08 </td> <td align="center"> 83.30 </td> <td align="center"> 88.38 </td> <td align="center"> 91.95 </td> <td align="center"> 99.61 </td> </tr>
  <tr> <td align="center"> 70 </td> <td align="center"> 43.28 </td> <td align="center"> 45.44 </td> <td align="center"> 48.76 </td> <td align="center"> 51.74 </td> <td align="center"> 55.33 </td> <td align="center"> 61.70 </td> <td align="center"> 69.33 </td> <td align="center"> 77.58 </td> <td align="center"> 85.53 </td> <td align="center"> 90.53 </td> <td align="center"> 95.02 </td> <td align="center"> 100.43 </td> <td align="center"> 104.21 </td> <td align="center"> 112.32 </td> </tr>
  <tr> <td align="center"> 80 </td> <td align="center"> 51.17 </td> <td align="center"> 53.54 </td> <td align="center"> 57.15 </td> <td align="center"> 60.39 </td> <td align="center"> 64.28 </td> <td align="center"> 71.14 </td> <td align="center"> 79.33 </td> <td align="center"> 88.13 </td> <td align="center"> 96.58 </td> <td align="center"> 101.88 </td> <td align="center"> 106.63 </td> <td align="center"> 112.33 </td> <td align="center"> 116.32 </td> <td align="center"> 124.84 </td> </tr>
  <tr> <td align="center"> 90 </td> <td align="center"> 59.20 </td> <td align="center"> 61.75 </td> <td align="center"> 65.65 </td> <td align="center"> 69.13 </td> <td align="center"> 73.29 </td> <td align="center"> 80.62 </td> <td align="center"> 89.33 </td> <td align="center"> 98.65 </td> <td align="center"> 107.57 </td> <td align="center"> 113.15 </td> <td align="center"> 118.14 </td> <td align="center"> 124.12 </td> <td align="center"> 128.30 </td> <td align="center"> 137.21 </td> </tr>
  <tr> <td align="center"> 100 </td> <td align="center"> 67.33 </td> <td align="center"> 70.06 </td> <td align="center"> 74.22 </td> <td align="center"> 77.93 </td> <td align="center"> 82.36 </td> <td align="center"> 90.13 </td> <td align="center"> 99.33 </td> <td align="center"> 109.14 </td> <td align="center"> 118.50 </td> <td align="center"> 124.34 </td> <td align="center"> 129.56 </td> <td align="center"> 135.81 </td> <td align="center"> 140.17 </td> <td align="center"> 149.45 </td> </tr>
   </table>
<p style="page-break-before: always">
<h2 id="fv_1-v_2-text-distribution"><code>\(F(v_1, v_2) \text{ Distribution}\)</code></h2>
<p><img src="https://roh.engineering/posts/2018/05/pe-industrial-engineer-reference-sheet/index_files/figure-html/unnamed-chunk-10-1.png" width="192" style="display: block; margin: auto;" /></p>
<!-- html table generated in R 4.0.3 by xtable 1.8-4 package -->
<!-- Wed Feb 17 21:22:48 2021 -->
<table border='2' cellpadding='15' cellpadding='5' rules ='all' width ='100%'>
<caption align="top"> Table 5: 95th Percentiles of the `\(F(v_1,v_2)\)` </caption>
<tr> <th> `\(v_2 \big\backslash v_1\)` </th> <th> 1 </th> <th> 2 </th> <th> 3 </th> <th> 4 </th> <th> 5 </th> <th> 6 </th> <th> 7 </th> <th> 8 </th> <th> 9 </th> <th> 10 </th> <th> 12 </th> <th> 15 </th> <th> 20 </th> <th> 24 </th> <th> 30 </th> <th> 40 </th> <th> 60 </th> <th> 120 </th> <th> `\(\infty\)` </th>  </tr>
  <tr> <td align="center"> 1 </td> <td align="center"> 161.45 </td> <td align="center"> 199.50 </td> <td align="center"> 215.71 </td> <td align="center"> 224.58 </td> <td align="center"> 230.16 </td> <td align="center"> 233.99 </td> <td align="center"> 236.77 </td> <td align="center"> 238.88 </td> <td align="center"> 240.54 </td> <td align="center"> 241.88 </td> <td align="center"> 243.91 </td> <td align="center"> 245.95 </td> <td align="center"> 248.01 </td> <td align="center"> 249.05 </td> <td align="center"> 250.10 </td> <td align="center"> 251.14 </td> <td align="center"> 252.20 </td> <td align="center"> 253.25 </td> <td align="center"> 254.31 </td> </tr>
  <tr> <td align="center"> 2 </td> <td align="center"> 18.51 </td> <td align="center"> 19.00 </td> <td align="center"> 19.16 </td> <td align="center"> 19.25 </td> <td align="center"> 19.30 </td> <td align="center"> 19.33 </td> <td align="center"> 19.35 </td> <td align="center"> 19.37 </td> <td align="center"> 19.38 </td> <td align="center"> 19.40 </td> <td align="center"> 19.41 </td> <td align="center"> 19.43 </td> <td align="center"> 19.45 </td> <td align="center"> 19.45 </td> <td align="center"> 19.46 </td> <td align="center"> 19.47 </td> <td align="center"> 19.48 </td> <td align="center"> 19.49 </td> <td align="center"> 19.50 </td> </tr>
  <tr> <td align="center"> 3 </td> <td align="center"> 10.13 </td> <td align="center"> 9.55 </td> <td align="center"> 9.28 </td> <td align="center"> 9.12 </td> <td align="center"> 9.01 </td> <td align="center"> 8.94 </td> <td align="center"> 8.89 </td> <td align="center"> 8.85 </td> <td align="center"> 8.81 </td> <td align="center"> 8.79 </td> <td align="center"> 8.74 </td> <td align="center"> 8.70 </td> <td align="center"> 8.66 </td> <td align="center"> 8.64 </td> <td align="center"> 8.62 </td> <td align="center"> 8.59 </td> <td align="center"> 8.57 </td> <td align="center"> 8.55 </td> <td align="center"> 8.53 </td> </tr>
  <tr> <td align="center"> 4 </td> <td align="center"> 7.71 </td> <td align="center"> 6.94 </td> <td align="center"> 6.59 </td> <td align="center"> 6.39 </td> <td align="center"> 6.26 </td> <td align="center"> 6.16 </td> <td align="center"> 6.09 </td> <td align="center"> 6.04 </td> <td align="center"> 6.00 </td> <td align="center"> 5.96 </td> <td align="center"> 5.91 </td> <td align="center"> 5.86 </td> <td align="center"> 5.80 </td> <td align="center"> 5.77 </td> <td align="center"> 5.75 </td> <td align="center"> 5.72 </td> <td align="center"> 5.69 </td> <td align="center"> 5.66 </td> <td align="center"> 5.63 </td> </tr>
  <tr> <td align="center"> 5 </td> <td align="center"> 6.61 </td> <td align="center"> 5.79 </td> <td align="center"> 5.41 </td> <td align="center"> 5.19 </td> <td align="center"> 5.05 </td> <td align="center"> 4.95 </td> <td align="center"> 4.88 </td> <td align="center"> 4.82 </td> <td align="center"> 4.77 </td> <td align="center"> 4.74 </td> <td align="center"> 4.68 </td> <td align="center"> 4.62 </td> <td align="center"> 4.56 </td> <td align="center"> 4.53 </td> <td align="center"> 4.50 </td> <td align="center"> 4.46 </td> <td align="center"> 4.43 </td> <td align="center"> 4.40 </td> <td align="center"> 4.36 </td> </tr>
  <tr> <td align="center"> 6 </td> <td align="center"> 5.99 </td> <td align="center"> 5.14 </td> <td align="center"> 4.76 </td> <td align="center"> 4.53 </td> <td align="center"> 4.39 </td> <td align="center"> 4.28 </td> <td align="center"> 4.21 </td> <td align="center"> 4.15 </td> <td align="center"> 4.10 </td> <td align="center"> 4.06 </td> <td align="center"> 4.00 </td> <td align="center"> 3.94 </td> <td align="center"> 3.87 </td> <td align="center"> 3.84 </td> <td align="center"> 3.81 </td> <td align="center"> 3.77 </td> <td align="center"> 3.74 </td> <td align="center"> 3.70 </td> <td align="center"> 3.67 </td> </tr>
  <tr> <td align="center"> 7 </td> <td align="center"> 5.59 </td> <td align="center"> 4.74 </td> <td align="center"> 4.35 </td> <td align="center"> 4.12 </td> <td align="center"> 3.97 </td> <td align="center"> 3.87 </td> <td align="center"> 3.79 </td> <td align="center"> 3.73 </td> <td align="center"> 3.68 </td> <td align="center"> 3.64 </td> <td align="center"> 3.57 </td> <td align="center"> 3.51 </td> <td align="center"> 3.44 </td> <td align="center"> 3.41 </td> <td align="center"> 3.38 </td> <td align="center"> 3.34 </td> <td align="center"> 3.30 </td> <td align="center"> 3.27 </td> <td align="center"> 3.23 </td> </tr>
  <tr> <td align="center"> 8 </td> <td align="center"> 5.32 </td> <td align="center"> 4.46 </td> <td align="center"> 4.07 </td> <td align="center"> 3.84 </td> <td align="center"> 3.69 </td> <td align="center"> 3.58 </td> <td align="center"> 3.50 </td> <td align="center"> 3.44 </td> <td align="center"> 3.39 </td> <td align="center"> 3.35 </td> <td align="center"> 3.28 </td> <td align="center"> 3.22 </td> <td align="center"> 3.15 </td> <td align="center"> 3.12 </td> <td align="center"> 3.08 </td> <td align="center"> 3.04 </td> <td align="center"> 3.01 </td> <td align="center"> 2.97 </td> <td align="center"> 2.93 </td> </tr>
  <tr> <td align="center"> 9 </td> <td align="center"> 5.12 </td> <td align="center"> 4.26 </td> <td align="center"> 3.86 </td> <td align="center"> 3.63 </td> <td align="center"> 3.48 </td> <td align="center"> 3.37 </td> <td align="center"> 3.29 </td> <td align="center"> 3.23 </td> <td align="center"> 3.18 </td> <td align="center"> 3.14 </td> <td align="center"> 3.07 </td> <td align="center"> 3.01 </td> <td align="center"> 2.94 </td> <td align="center"> 2.90 </td> <td align="center"> 2.86 </td> <td align="center"> 2.83 </td> <td align="center"> 2.79 </td> <td align="center"> 2.75 </td> <td align="center"> 2.71 </td> </tr>
  <tr> <td align="center"> 10 </td> <td align="center"> 4.96 </td> <td align="center"> 4.10 </td> <td align="center"> 3.71 </td> <td align="center"> 3.48 </td> <td align="center"> 3.33 </td> <td align="center"> 3.22 </td> <td align="center"> 3.14 </td> <td align="center"> 3.07 </td> <td align="center"> 3.02 </td> <td align="center"> 2.98 </td> <td align="center"> 2.91 </td> <td align="center"> 2.85 </td> <td align="center"> 2.77 </td> <td align="center"> 2.74 </td> <td align="center"> 2.70 </td> <td align="center"> 2.66 </td> <td align="center"> 2.62 </td> <td align="center"> 2.58 </td> <td align="center"> 2.54 </td> </tr>
  <tr> <td align="center"> 12 </td> <td align="center"> 4.75 </td> <td align="center"> 3.89 </td> <td align="center"> 3.49 </td> <td align="center"> 3.26 </td> <td align="center"> 3.11 </td> <td align="center"> 3.00 </td> <td align="center"> 2.91 </td> <td align="center"> 2.85 </td> <td align="center"> 2.80 </td> <td align="center"> 2.75 </td> <td align="center"> 2.69 </td> <td align="center"> 2.62 </td> <td align="center"> 2.54 </td> <td align="center"> 2.51 </td> <td align="center"> 2.47 </td> <td align="center"> 2.43 </td> <td align="center"> 2.38 </td> <td align="center"> 2.34 </td> <td align="center"> 2.30 </td> </tr>
  <tr> <td align="center"> 15 </td> <td align="center"> 4.54 </td> <td align="center"> 3.68 </td> <td align="center"> 3.29 </td> <td align="center"> 3.06 </td> <td align="center"> 2.90 </td> <td align="center"> 2.79 </td> <td align="center"> 2.71 </td> <td align="center"> 2.64 </td> <td align="center"> 2.59 </td> <td align="center"> 2.54 </td> <td align="center"> 2.48 </td> <td align="center"> 2.40 </td> <td align="center"> 2.33 </td> <td align="center"> 2.29 </td> <td align="center"> 2.25 </td> <td align="center"> 2.20 </td> <td align="center"> 2.16 </td> <td align="center"> 2.11 </td> <td align="center"> 2.07 </td> </tr>
  <tr> <td align="center"> 20 </td> <td align="center"> 4.35 </td> <td align="center"> 3.49 </td> <td align="center"> 3.10 </td> <td align="center"> 2.87 </td> <td align="center"> 2.71 </td> <td align="center"> 2.60 </td> <td align="center"> 2.51 </td> <td align="center"> 2.45 </td> <td align="center"> 2.39 </td> <td align="center"> 2.35 </td> <td align="center"> 2.28 </td> <td align="center"> 2.20 </td> <td align="center"> 2.12 </td> <td align="center"> 2.08 </td> <td align="center"> 2.04 </td> <td align="center"> 1.99 </td> <td align="center"> 1.95 </td> <td align="center"> 1.90 </td> <td align="center"> 1.84 </td> </tr>
  <tr> <td align="center"> 24 </td> <td align="center"> 4.26 </td> <td align="center"> 3.40 </td> <td align="center"> 3.01 </td> <td align="center"> 2.78 </td> <td align="center"> 2.62 </td> <td align="center"> 2.51 </td> <td align="center"> 2.42 </td> <td align="center"> 2.36 </td> <td align="center"> 2.30 </td> <td align="center"> 2.25 </td> <td align="center"> 2.18 </td> <td align="center"> 2.11 </td> <td align="center"> 2.03 </td> <td align="center"> 1.98 </td> <td align="center"> 1.94 </td> <td align="center"> 1.89 </td> <td align="center"> 1.84 </td> <td align="center"> 1.79 </td> <td align="center"> 1.73 </td> </tr>
  <tr> <td align="center"> 30 </td> <td align="center"> 4.17 </td> <td align="center"> 3.32 </td> <td align="center"> 2.92 </td> <td align="center"> 2.69 </td> <td align="center"> 2.53 </td> <td align="center"> 2.42 </td> <td align="center"> 2.33 </td> <td align="center"> 2.27 </td> <td align="center"> 2.21 </td> <td align="center"> 2.16 </td> <td align="center"> 2.09 </td> <td align="center"> 2.01 </td> <td align="center"> 1.93 </td> <td align="center"> 1.89 </td> <td align="center"> 1.84 </td> <td align="center"> 1.79 </td> <td align="center"> 1.74 </td> <td align="center"> 1.68 </td> <td align="center"> 1.62 </td> </tr>
  <tr> <td align="center"> 40 </td> <td align="center"> 4.08 </td> <td align="center"> 3.23 </td> <td align="center"> 2.84 </td> <td align="center"> 2.61 </td> <td align="center"> 2.45 </td> <td align="center"> 2.34 </td> <td align="center"> 2.25 </td> <td align="center"> 2.18 </td> <td align="center"> 2.12 </td> <td align="center"> 2.08 </td> <td align="center"> 2.00 </td> <td align="center"> 1.92 </td> <td align="center"> 1.84 </td> <td align="center"> 1.79 </td> <td align="center"> 1.74 </td> <td align="center"> 1.69 </td> <td align="center"> 1.64 </td> <td align="center"> 1.58 </td> <td align="center"> 1.51 </td> </tr>
  <tr> <td align="center"> 60 </td> <td align="center"> 4.00 </td> <td align="center"> 3.15 </td> <td align="center"> 2.76 </td> <td align="center"> 2.53 </td> <td align="center"> 2.37 </td> <td align="center"> 2.25 </td> <td align="center"> 2.17 </td> <td align="center"> 2.10 </td> <td align="center"> 2.04 </td> <td align="center"> 1.99 </td> <td align="center"> 1.92 </td> <td align="center"> 1.84 </td> <td align="center"> 1.75 </td> <td align="center"> 1.70 </td> <td align="center"> 1.65 </td> <td align="center"> 1.59 </td> <td align="center"> 1.53 </td> <td align="center"> 1.47 </td> <td align="center"> 1.39 </td> </tr>
  <tr> <td align="center"> 120 </td> <td align="center"> 3.92 </td> <td align="center"> 3.07 </td> <td align="center"> 2.68 </td> <td align="center"> 2.45 </td> <td align="center"> 2.29 </td> <td align="center"> 2.18 </td> <td align="center"> 2.09 </td> <td align="center"> 2.02 </td> <td align="center"> 1.96 </td> <td align="center"> 1.91 </td> <td align="center"> 1.83 </td> <td align="center"> 1.75 </td> <td align="center"> 1.66 </td> <td align="center"> 1.61 </td> <td align="center"> 1.55 </td> <td align="center"> 1.50 </td> <td align="center"> 1.43 </td> <td align="center"> 1.35 </td> <td align="center"> 1.25 </td> </tr>
  <tr> <td align="center"> Inf </td> <td align="center"> 3.84 </td> <td align="center"> 3.00 </td> <td align="center"> 2.60 </td> <td align="center"> 2.37 </td> <td align="center"> 2.21 </td> <td align="center"> 2.10 </td> <td align="center"> 2.01 </td> <td align="center"> 1.94 </td> <td align="center"> 1.88 </td> <td align="center"> 1.83 </td> <td align="center"> 1.75 </td> <td align="center"> 1.67 </td> <td align="center"> 1.57 </td> <td align="center"> 1.52 </td> <td align="center"> 1.46 </td> <td align="center"> 1.39 </td> <td align="center"> 1.32 </td> <td align="center"> 1.22 </td> <td align="center"> 1.00 </td> </tr>
   </table>
<!-- html table generated in R 4.0.3 by xtable 1.8-4 package -->
<!-- Wed Feb 17 21:22:48 2021 -->
<table border='2' cellpadding='15' cellpadding='5' rules ='all' width ='100%'>
<caption align="top"> Table 6: 99th Percentiles of the `\(F(v_1,v_2)\)` </caption>
<tr> <th> `\(v_2 \big\backslash v_1\)` </th> <th> 1 </th> <th> 2 </th> <th> 3 </th> <th> 4 </th> <th> 5 </th> <th> 6 </th> <th> 7 </th> <th> 8 </th> <th> 9 </th> <th> 10 </th> <th> 12 </th> <th> 15 </th> <th> 20 </th> <th> 24 </th> <th> 30 </th> <th> 40 </th> <th> 60 </th> <th> 120 </th> <th> `\(\infty\)` </th>  </tr>
  <tr> <td align="center"> 1 </td> <td align="center"> 4052 </td> <td align="center"> 5000 </td> <td align="center"> 5403 </td> <td align="center"> 5625 </td> <td align="center"> 5764 </td> <td align="center"> 5859 </td> <td align="center"> 5928 </td> <td align="center"> 5981 </td> <td align="center"> 6022 </td> <td align="center"> 6056 </td> <td align="center"> 6106 </td> <td align="center"> 6157 </td> <td align="center"> 6209 </td> <td align="center"> 6235 </td> <td align="center"> 6261 </td> <td align="center"> 6287 </td> <td align="center"> 6313 </td> <td align="center"> 6339 </td> <td align="center"> 6366 </td> </tr>
  <tr> <td align="center"> 2 </td> <td align="center"> 98.50 </td> <td align="center"> 99.00 </td> <td align="center"> 99.17 </td> <td align="center"> 99.25 </td> <td align="center"> 99.30 </td> <td align="center"> 99.33 </td> <td align="center"> 99.36 </td> <td align="center"> 99.37 </td> <td align="center"> 99.39 </td> <td align="center"> 99.40 </td> <td align="center"> 99.42 </td> <td align="center"> 99.43 </td> <td align="center"> 99.45 </td> <td align="center"> 99.46 </td> <td align="center"> 99.47 </td> <td align="center"> 99.47 </td> <td align="center"> 99.48 </td> <td align="center"> 99.49 </td> <td align="center"> 99.50 </td> </tr>
  <tr> <td align="center"> 3 </td> <td align="center"> 34.12 </td> <td align="center"> 30.82 </td> <td align="center"> 29.46 </td> <td align="center"> 28.71 </td> <td align="center"> 28.24 </td> <td align="center"> 27.91 </td> <td align="center"> 27.67 </td> <td align="center"> 27.49 </td> <td align="center"> 27.35 </td> <td align="center"> 27.23 </td> <td align="center"> 27.05 </td> <td align="center"> 26.87 </td> <td align="center"> 26.69 </td> <td align="center"> 26.60 </td> <td align="center"> 26.50 </td> <td align="center"> 26.41 </td> <td align="center"> 26.32 </td> <td align="center"> 26.22 </td> <td align="center"> 26.13 </td> </tr>
  <tr> <td align="center"> 4 </td> <td align="center"> 21.20 </td> <td align="center"> 18.00 </td> <td align="center"> 16.69 </td> <td align="center"> 15.98 </td> <td align="center"> 15.52 </td> <td align="center"> 15.21 </td> <td align="center"> 14.98 </td> <td align="center"> 14.80 </td> <td align="center"> 14.66 </td> <td align="center"> 14.55 </td> <td align="center"> 14.37 </td> <td align="center"> 14.20 </td> <td align="center"> 14.02 </td> <td align="center"> 13.93 </td> <td align="center"> 13.84 </td> <td align="center"> 13.75 </td> <td align="center"> 13.65 </td> <td align="center"> 13.56 </td> <td align="center"> 13.46 </td> </tr>
  <tr> <td align="center"> 5 </td> <td align="center"> 16.26 </td> <td align="center"> 13.27 </td> <td align="center"> 12.06 </td> <td align="center"> 11.39 </td> <td align="center"> 10.97 </td> <td align="center"> 10.67 </td> <td align="center"> 10.46 </td> <td align="center"> 10.29 </td> <td align="center"> 10.16 </td> <td align="center"> 10.05 </td> <td align="center"> 9.89 </td> <td align="center"> 9.72 </td> <td align="center"> 9.55 </td> <td align="center"> 9.47 </td> <td align="center"> 9.38 </td> <td align="center"> 9.29 </td> <td align="center"> 9.20 </td> <td align="center"> 9.11 </td> <td align="center"> 9.02 </td> </tr>
  <tr> <td align="center"> 6 </td> <td align="center"> 13.75 </td> <td align="center"> 10.92 </td> <td align="center"> 9.78 </td> <td align="center"> 9.15 </td> <td align="center"> 8.75 </td> <td align="center"> 8.47 </td> <td align="center"> 8.26 </td> <td align="center"> 8.10 </td> <td align="center"> 7.98 </td> <td align="center"> 7.87 </td> <td align="center"> 7.72 </td> <td align="center"> 7.56 </td> <td align="center"> 7.40 </td> <td align="center"> 7.31 </td> <td align="center"> 7.23 </td> <td align="center"> 7.14 </td> <td align="center"> 7.06 </td> <td align="center"> 6.97 </td> <td align="center"> 6.88 </td> </tr>
  <tr> <td align="center"> 7 </td> <td align="center"> 12.25 </td> <td align="center"> 9.55 </td> <td align="center"> 8.45 </td> <td align="center"> 7.85 </td> <td align="center"> 7.46 </td> <td align="center"> 7.19 </td> <td align="center"> 6.99 </td> <td align="center"> 6.84 </td> <td align="center"> 6.72 </td> <td align="center"> 6.62 </td> <td align="center"> 6.47 </td> <td align="center"> 6.31 </td> <td align="center"> 6.16 </td> <td align="center"> 6.07 </td> <td align="center"> 5.99 </td> <td align="center"> 5.91 </td> <td align="center"> 5.82 </td> <td align="center"> 5.74 </td> <td align="center"> 5.65 </td> </tr>
  <tr> <td align="center"> 8 </td> <td align="center"> 11.26 </td> <td align="center"> 8.65 </td> <td align="center"> 7.59 </td> <td align="center"> 7.01 </td> <td align="center"> 6.63 </td> <td align="center"> 6.37 </td> <td align="center"> 6.18 </td> <td align="center"> 6.03 </td> <td align="center"> 5.91 </td> <td align="center"> 5.81 </td> <td align="center"> 5.67 </td> <td align="center"> 5.52 </td> <td align="center"> 5.36 </td> <td align="center"> 5.28 </td> <td align="center"> 5.20 </td> <td align="center"> 5.12 </td> <td align="center"> 5.03 </td> <td align="center"> 4.95 </td> <td align="center"> 4.86 </td> </tr>
  <tr> <td align="center"> 9 </td> <td align="center"> 10.56 </td> <td align="center"> 8.02 </td> <td align="center"> 6.99 </td> <td align="center"> 6.42 </td> <td align="center"> 6.06 </td> <td align="center"> 5.80 </td> <td align="center"> 5.61 </td> <td align="center"> 5.47 </td> <td align="center"> 5.35 </td> <td align="center"> 5.26 </td> <td align="center"> 5.11 </td> <td align="center"> 4.96 </td> <td align="center"> 4.81 </td> <td align="center"> 4.73 </td> <td align="center"> 4.65 </td> <td align="center"> 4.57 </td> <td align="center"> 4.48 </td> <td align="center"> 4.40 </td> <td align="center"> 4.31 </td> </tr>
  <tr> <td align="center"> 10 </td> <td align="center"> 10.04 </td> <td align="center"> 7.56 </td> <td align="center"> 6.55 </td> <td align="center"> 5.99 </td> <td align="center"> 5.64 </td> <td align="center"> 5.39 </td> <td align="center"> 5.20 </td> <td align="center"> 5.06 </td> <td align="center"> 4.94 </td> <td align="center"> 4.85 </td> <td align="center"> 4.71 </td> <td align="center"> 4.56 </td> <td align="center"> 4.41 </td> <td align="center"> 4.33 </td> <td align="center"> 4.25 </td> <td align="center"> 4.17 </td> <td align="center"> 4.08 </td> <td align="center"> 4.00 </td> <td align="center"> 3.91 </td> </tr>
  <tr> <td align="center"> 12 </td> <td align="center"> 9.33 </td> <td align="center"> 6.93 </td> <td align="center"> 5.95 </td> <td align="center"> 5.41 </td> <td align="center"> 5.06 </td> <td align="center"> 4.82 </td> <td align="center"> 4.64 </td> <td align="center"> 4.50 </td> <td align="center"> 4.39 </td> <td align="center"> 4.30 </td> <td align="center"> 4.16 </td> <td align="center"> 4.01 </td> <td align="center"> 3.86 </td> <td align="center"> 3.78 </td> <td align="center"> 3.70 </td> <td align="center"> 3.62 </td> <td align="center"> 3.54 </td> <td align="center"> 3.45 </td> <td align="center"> 3.36 </td> </tr>
  <tr> <td align="center"> 15 </td> <td align="center"> 8.68 </td> <td align="center"> 6.36 </td> <td align="center"> 5.42 </td> <td align="center"> 4.89 </td> <td align="center"> 4.56 </td> <td align="center"> 4.32 </td> <td align="center"> 4.14 </td> <td align="center"> 4.00 </td> <td align="center"> 3.89 </td> <td align="center"> 3.80 </td> <td align="center"> 3.67 </td> <td align="center"> 3.52 </td> <td align="center"> 3.37 </td> <td align="center"> 3.29 </td> <td align="center"> 3.21 </td> <td align="center"> 3.13 </td> <td align="center"> 3.05 </td> <td align="center"> 2.96 </td> <td align="center"> 2.87 </td> </tr>
  <tr> <td align="center"> 20 </td> <td align="center"> 8.10 </td> <td align="center"> 5.85 </td> <td align="center"> 4.94 </td> <td align="center"> 4.43 </td> <td align="center"> 4.10 </td> <td align="center"> 3.87 </td> <td align="center"> 3.70 </td> <td align="center"> 3.56 </td> <td align="center"> 3.46 </td> <td align="center"> 3.37 </td> <td align="center"> 3.23 </td> <td align="center"> 3.09 </td> <td align="center"> 2.94 </td> <td align="center"> 2.86 </td> <td align="center"> 2.78 </td> <td align="center"> 2.69 </td> <td align="center"> 2.61 </td> <td align="center"> 2.52 </td> <td align="center"> 2.42 </td> </tr>
  <tr> <td align="center"> 24 </td> <td align="center"> 7.82 </td> <td align="center"> 5.61 </td> <td align="center"> 4.72 </td> <td align="center"> 4.22 </td> <td align="center"> 3.90 </td> <td align="center"> 3.67 </td> <td align="center"> 3.50 </td> <td align="center"> 3.36 </td> <td align="center"> 3.26 </td> <td align="center"> 3.17 </td> <td align="center"> 3.03 </td> <td align="center"> 2.89 </td> <td align="center"> 2.74 </td> <td align="center"> 2.66 </td> <td align="center"> 2.58 </td> <td align="center"> 2.49 </td> <td align="center"> 2.40 </td> <td align="center"> 2.31 </td> <td align="center"> 2.21 </td> </tr>
  <tr> <td align="center"> 30 </td> <td align="center"> 7.56 </td> <td align="center"> 5.39 </td> <td align="center"> 4.51 </td> <td align="center"> 4.02 </td> <td align="center"> 3.70 </td> <td align="center"> 3.47 </td> <td align="center"> 3.30 </td> <td align="center"> 3.17 </td> <td align="center"> 3.07 </td> <td align="center"> 2.98 </td> <td align="center"> 2.84 </td> <td align="center"> 2.70 </td> <td align="center"> 2.55 </td> <td align="center"> 2.47 </td> <td align="center"> 2.39 </td> <td align="center"> 2.30 </td> <td align="center"> 2.21 </td> <td align="center"> 2.11 </td> <td align="center"> 2.01 </td> </tr>
  <tr> <td align="center"> 40 </td> <td align="center"> 7.31 </td> <td align="center"> 5.18 </td> <td align="center"> 4.31 </td> <td align="center"> 3.83 </td> <td align="center"> 3.51 </td> <td align="center"> 3.29 </td> <td align="center"> 3.12 </td> <td align="center"> 2.99 </td> <td align="center"> 2.89 </td> <td align="center"> 2.80 </td> <td align="center"> 2.66 </td> <td align="center"> 2.52 </td> <td align="center"> 2.37 </td> <td align="center"> 2.29 </td> <td align="center"> 2.20 </td> <td align="center"> 2.11 </td> <td align="center"> 2.02 </td> <td align="center"> 1.92 </td> <td align="center"> 1.80 </td> </tr>
  <tr> <td align="center"> 60 </td> <td align="center"> 7.08 </td> <td align="center"> 4.98 </td> <td align="center"> 4.13 </td> <td align="center"> 3.65 </td> <td align="center"> 3.34 </td> <td align="center"> 3.12 </td> <td align="center"> 2.95 </td> <td align="center"> 2.82 </td> <td align="center"> 2.72 </td> <td align="center"> 2.63 </td> <td align="center"> 2.50 </td> <td align="center"> 2.35 </td> <td align="center"> 2.20 </td> <td align="center"> 2.12 </td> <td align="center"> 2.03 </td> <td align="center"> 1.94 </td> <td align="center"> 1.84 </td> <td align="center"> 1.73 </td> <td align="center"> 1.60 </td> </tr>
  <tr> <td align="center"> 120 </td> <td align="center"> 6.85 </td> <td align="center"> 4.79 </td> <td align="center"> 3.95 </td> <td align="center"> 3.48 </td> <td align="center"> 3.17 </td> <td align="center"> 2.96 </td> <td align="center"> 2.79 </td> <td align="center"> 2.66 </td> <td align="center"> 2.56 </td> <td align="center"> 2.47 </td> <td align="center"> 2.34 </td> <td align="center"> 2.19 </td> <td align="center"> 2.03 </td> <td align="center"> 1.95 </td> <td align="center"> 1.86 </td> <td align="center"> 1.76 </td> <td align="center"> 1.66 </td> <td align="center"> 1.53 </td> <td align="center"> 1.38 </td> </tr>
  <tr> <td align="center"> Inf </td> <td align="center"> 6.63 </td> <td align="center"> 4.61 </td> <td align="center"> 3.78 </td> <td align="center"> 3.32 </td> <td align="center"> 3.02 </td> <td align="center"> 2.80 </td> <td align="center"> 2.64 </td> <td align="center"> 2.51 </td> <td align="center"> 2.41 </td> <td align="center"> 2.32 </td> <td align="center"> 2.18 </td> <td align="center"> 2.04 </td> <td align="center"> 1.88 </td> <td align="center"> 1.79 </td> <td align="center"> 1.70 </td> <td align="center"> 1.59 </td> <td align="center"> 1.47 </td> <td align="center"> 1.32 </td> <td align="center"> 1.00 </td> </tr>
   </table>
<p style="page-break-before: always">
<h2 id="references">References</h2>
<pre><code>[[1]]
Krishnamoorthi K (2006). _A First Course in Quality Engineering:
Integrating Statistical and Management Methods of Quality_. Pearson
Prentice Hall. ISBN 9780131472013, &lt;URL:
https://books.google.com/books?id=lPQJAQAAMAAJ&gt;.

[[2]]
Kutner M, Nachtsheim C, Neter J, Li W (2004). _Applied Linear
Statistical Models with Student CD_. McGraw-Hill
Companies,Incorporated. ISBN 9780073108742, &lt;URL:
https://books.google.com/books?id=0Qq-swEACAAJ&gt;.

[[3]]
Sullivan W, Wicks E, Luxhoj J (2006). _Engineering Economy_, number v.
1 series Engineering Economy. Pearson/Prentice Hall. ISBN
9780131486492, &lt;URL: https://books.google.com/books?id=6pcoAQAAMAAJ&gt;.

[[4]]
Gross D, Shortle J, Thompson J, Harris C (2011). _Fundamentals of
Queueing Theory_, series Wiley Series in Probability and Statistics.
Wiley. ISBN 9781118211649, &lt;URL:
https://books.google.com/books?id=K3lQGeCtAJgC&gt;.

[[5]]
Winston W (2003). _Introduction to Probability Models_. Cengage
Learning. ISBN 9780534405786, &lt;URL:
https://books.google.com/books?id=L9yURQAACAAJ&gt;.

[[6]]
Niebel B, Freivalds A (2003). _Methods, Standards, and Work Design_,
series McGraw-Hill series in industrial engineering and management
science. McGraw-Hill. ISBN 9780072468243, &lt;URL:
https://books.google.com/books?id=ApXSoagqrxcC&gt;.
</code></pre>]]></description>
        </item>
        
        <item>
            <title>fitur 0.5.25 Release</title>
            <link>https://roh.engineering/posts/2018/03/fitur-0.5.25-release/</link>
            <pubDate>Wed, 14 Mar 2018 00:00:00 +0000</pubDate>
            
            <guid>https://roh.engineering/posts/2018/03/fitur-0.5.25-release/</guid>
            <description><![CDATA[<ul>
<li>
<p>Fixed appearance of plots</p>
</li>
<li>
<p>Added plot_density function for comparison pdfs of fitted functions</p>
</li>
<li>
<p>Updated argument naming conventions</p>
</li>
</ul>
<p>fitur on <a href="https://cran.r-project.org/web/packages/fitur/index.html">CRAN</a></p>
<h2 id="density-diagnostic-plot">Density Diagnostic Plot</h2>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">library</span>(fitur)
</code></pre></div><pre><code>## Warning: replacing previous import 'vctrs::data_frame' by 'tibble::data_frame'
## when loading 'dplyr'
</code></pre><div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">library</span>(ggplot2)
<span style="color:#a6e22e">library</span>(trstyles)
<span style="color:#a6e22e">set.seed</span>(<span style="color:#ae81ff">37</span>)
x <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">rgamma</span>(<span style="color:#ae81ff">10000</span>, <span style="color:#ae81ff">5</span>)
dists <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">c</span>(<span style="color:#e6db74">&#39;gamma&#39;</span>, <span style="color:#e6db74">&#39;lnorm&#39;</span>, <span style="color:#e6db74">&#39;weibull&#39;</span>)
fits <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">lapply</span>(dists, fit_univariate, x <span style="color:#f92672">=</span> x)
<span style="color:#a6e22e">theme_set</span>(<span style="color:#a6e22e">theme_tr</span>())
<span style="color:#a6e22e">plot_density</span>(x, fits, nbins <span style="color:#f92672">=</span> <span style="color:#ae81ff">20</span>)
</code></pre></div><p><img src="https://roh.engineering/posts/2018/03/fitur-0.5.25-release/index_files/figure-html/unnamed-chunk-1-1.png" width="672" /></p>
<h2 id="qq-plot">QQ-Plot</h2>
<p>The output is a ggplot object so you can add colors, styling, etc.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">plot_pp</span>(x, fits) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">scale_color_tr</span>()
</code></pre></div><p><img src="https://roh.engineering/posts/2018/03/fitur-0.5.25-release/index_files/figure-html/unnamed-chunk-2-1.png" width="672" /></p>
<h2 id="pp-plot">PP-Plot</h2>
<p>You can also zoom in on different areas.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">plot_qq</span>(x, fits) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">scale_color_tr</span>() <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">coord_cartesian</span>(xlim <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#ae81ff">5</span>,<span style="color:#ae81ff">10</span>))
</code></pre></div><p><img src="https://roh.engineering/posts/2018/03/fitur-0.5.25-release/index_files/figure-html/unnamed-chunk-3-1.png" width="672" /></p>
]]></description>
        </item>
        
        <item>
            <title>Building Distribution Reference Tables in R</title>
            <link>https://roh.engineering/posts/2018/03/building-distribution-reference-tables-in-r/</link>
            <pubDate>Sat, 10 Mar 2018 00:00:00 +0000</pubDate>
            
            <guid>https://roh.engineering/posts/2018/03/building-distribution-reference-tables-in-r/</guid>
            <description><![CDATA[<p>I&rsquo;ve recently been studing for a professional exam that does not allow computers
or advanced calculators. Some of the subject matter will require use of a few
statistical distributions which can be very time-consuming to calculate manually.
In lieu of access to statistical functions, you are allowed to bring books and
some reference sheets. I wanted to see if I could recreate these distribution
tables in R.</p>
<p>Generating distribution values is very simple in <code>R</code>. The <code>d</code>, <code>q</code>, <code>p</code>, and <code>r</code>
functions are all that you will need to fill in the table values. The table
below is for the <em>t</em> distribution.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">alpha <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">c</span>(<span style="color:#ae81ff">.1</span>, <span style="color:#ae81ff">.05</span>, <span style="color:#ae81ff">.025</span>, <span style="color:#ae81ff">.01</span>, <span style="color:#ae81ff">.005</span>)
v <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">c</span>(<span style="color:#a6e22e">seq</span>(<span style="color:#ae81ff">1</span>, <span style="color:#ae81ff">30</span>, by <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>), <span style="color:#66d9ef">Inf</span>)
tTable <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">sapply</span>((<span style="color:#ae81ff">1</span><span style="color:#f92672">-</span>alpha), <span style="color:#a6e22e">function</span>(x) <span style="color:#a6e22e">qt</span>(x, df <span style="color:#f92672">=</span> v))
<span style="color:#a6e22e">colnames</span>(tTable) <span style="color:#f92672">&lt;-</span> alpha
</code></pre></div><p>I&rsquo;m using the
<a href="https://cran.r-project.org/web/packages/xtable/xtable.pdf"><code>xtable</code></a> package here to format my table. It has some handy options to
parse math symbols and notations with its <code>sanitize.text</code> print options and allows
more customization of table style than the <code>kable</code> function in <code>knitr</code>. I&rsquo;m
setting some of style options below.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">options</span>(xtable.type <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;html&#39;</span>,
        xtable.caption.placement <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;top&#34;</span>,
        xtable.include.rownames <span style="color:#f92672">=</span> <span style="color:#66d9ef">FALSE</span>,
        xtable.html.table.attributes<span style="color:#f92672">=</span> <span style="color:#a6e22e">list</span>(<span style="color:#e6db74">&#34;border=&#39;2&#39; cellpadding=&#39;15&#39; cellpadding=&#39;5&#39; rules =&#39;all&#39; width =&#39;100%&#39;&#34;</span>))
</code></pre></div><p>When rendering the table, you can use <a href="https://www.latex-project.org/">LaTeX</a>
notation within the data of the table and have it parsed into math notation.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">library</span>(xtable)

tTable <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">data.frame</span>(<span style="color:#e6db74">&#34;$v \\big\\backslash \\alpha$&#34;</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">paste0</span>(<span style="color:#e6db74">&#34;&#34;</span>, v, <span style="color:#e6db74">&#34;&#34;</span>),
                     tTable,
                     stringsAsFactors <span style="color:#f92672">=</span> <span style="color:#66d9ef">FALSE</span>,
                     check.names <span style="color:#f92672">=</span> <span style="color:#66d9ef">FALSE</span>)
tTable[[1]][tTable[[1]] <span style="color:#f92672">==</span> <span style="color:#e6db74">&#34;Inf&#34;</span>] <span style="color:#f92672">&lt;-</span> <span style="color:#e6db74">&#34;$\\infty$&#34;</span> 
tTable <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">xtable</span>(tTable,
                      caption <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;Table 3: Percentiles of the *t* Distribution&#34;</span>,
                      align <span style="color:#f92672">=</span> <span style="color:#a6e22e">rep</span>(<span style="color:#e6db74">&#34;c&#34;</span>, <span style="color:#a6e22e">ncol</span>(tTable)<span style="color:#ae81ff">+1</span>),
                      digits <span style="color:#f92672">=</span> <span style="color:#ae81ff">4</span>)
<span style="color:#a6e22e">print</span>(tTable)
</code></pre></div><!-- html table generated in R 4.0.3 by xtable 1.8-4 package -->
<!-- Wed Feb 17 21:01:45 2021 -->
<table border='2' cellpadding='15' cellpadding='5' rules ='all' width ='100%'>
<caption align="top"> Table 3: Percentiles of the *t* Distribution </caption>
<tr> <th> `\(v \big\backslash \alpha\)` </th> <th> 0.1 </th> <th> 0.05 </th> <th> 0.025 </th> <th> 0.01 </th> <th> 0.005 </th>  </tr>
  <tr> <td align="center"> 1 </td> <td align="center"> 3.0777 </td> <td align="center"> 6.3138 </td> <td align="center"> 12.7062 </td> <td align="center"> 31.8205 </td> <td align="center"> 63.6567 </td> </tr>
  <tr> <td align="center"> 2 </td> <td align="center"> 1.8856 </td> <td align="center"> 2.9200 </td> <td align="center"> 4.3027 </td> <td align="center"> 6.9646 </td> <td align="center"> 9.9248 </td> </tr>
  <tr> <td align="center"> 3 </td> <td align="center"> 1.6377 </td> <td align="center"> 2.3534 </td> <td align="center"> 3.1824 </td> <td align="center"> 4.5407 </td> <td align="center"> 5.8409 </td> </tr>
  <tr> <td align="center"> 4 </td> <td align="center"> 1.5332 </td> <td align="center"> 2.1318 </td> <td align="center"> 2.7764 </td> <td align="center"> 3.7469 </td> <td align="center"> 4.6041 </td> </tr>
  <tr> <td align="center"> 5 </td> <td align="center"> 1.4759 </td> <td align="center"> 2.0150 </td> <td align="center"> 2.5706 </td> <td align="center"> 3.3649 </td> <td align="center"> 4.0321 </td> </tr>
  <tr> <td align="center"> 6 </td> <td align="center"> 1.4398 </td> <td align="center"> 1.9432 </td> <td align="center"> 2.4469 </td> <td align="center"> 3.1427 </td> <td align="center"> 3.7074 </td> </tr>
  <tr> <td align="center"> 7 </td> <td align="center"> 1.4149 </td> <td align="center"> 1.8946 </td> <td align="center"> 2.3646 </td> <td align="center"> 2.9980 </td> <td align="center"> 3.4995 </td> </tr>
  <tr> <td align="center"> 8 </td> <td align="center"> 1.3968 </td> <td align="center"> 1.8595 </td> <td align="center"> 2.3060 </td> <td align="center"> 2.8965 </td> <td align="center"> 3.3554 </td> </tr>
  <tr> <td align="center"> 9 </td> <td align="center"> 1.3830 </td> <td align="center"> 1.8331 </td> <td align="center"> 2.2622 </td> <td align="center"> 2.8214 </td> <td align="center"> 3.2498 </td> </tr>
  <tr> <td align="center"> 10 </td> <td align="center"> 1.3722 </td> <td align="center"> 1.8125 </td> <td align="center"> 2.2281 </td> <td align="center"> 2.7638 </td> <td align="center"> 3.1693 </td> </tr>
  <tr> <td align="center"> 11 </td> <td align="center"> 1.3634 </td> <td align="center"> 1.7959 </td> <td align="center"> 2.2010 </td> <td align="center"> 2.7181 </td> <td align="center"> 3.1058 </td> </tr>
  <tr> <td align="center"> 12 </td> <td align="center"> 1.3562 </td> <td align="center"> 1.7823 </td> <td align="center"> 2.1788 </td> <td align="center"> 2.6810 </td> <td align="center"> 3.0545 </td> </tr>
  <tr> <td align="center"> 13 </td> <td align="center"> 1.3502 </td> <td align="center"> 1.7709 </td> <td align="center"> 2.1604 </td> <td align="center"> 2.6503 </td> <td align="center"> 3.0123 </td> </tr>
  <tr> <td align="center"> 14 </td> <td align="center"> 1.3450 </td> <td align="center"> 1.7613 </td> <td align="center"> 2.1448 </td> <td align="center"> 2.6245 </td> <td align="center"> 2.9768 </td> </tr>
  <tr> <td align="center"> 15 </td> <td align="center"> 1.3406 </td> <td align="center"> 1.7531 </td> <td align="center"> 2.1314 </td> <td align="center"> 2.6025 </td> <td align="center"> 2.9467 </td> </tr>
  <tr> <td align="center"> 16 </td> <td align="center"> 1.3368 </td> <td align="center"> 1.7459 </td> <td align="center"> 2.1199 </td> <td align="center"> 2.5835 </td> <td align="center"> 2.9208 </td> </tr>
  <tr> <td align="center"> 17 </td> <td align="center"> 1.3334 </td> <td align="center"> 1.7396 </td> <td align="center"> 2.1098 </td> <td align="center"> 2.5669 </td> <td align="center"> 2.8982 </td> </tr>
  <tr> <td align="center"> 18 </td> <td align="center"> 1.3304 </td> <td align="center"> 1.7341 </td> <td align="center"> 2.1009 </td> <td align="center"> 2.5524 </td> <td align="center"> 2.8784 </td> </tr>
  <tr> <td align="center"> 19 </td> <td align="center"> 1.3277 </td> <td align="center"> 1.7291 </td> <td align="center"> 2.0930 </td> <td align="center"> 2.5395 </td> <td align="center"> 2.8609 </td> </tr>
  <tr> <td align="center"> 20 </td> <td align="center"> 1.3253 </td> <td align="center"> 1.7247 </td> <td align="center"> 2.0860 </td> <td align="center"> 2.5280 </td> <td align="center"> 2.8453 </td> </tr>
  <tr> <td align="center"> 21 </td> <td align="center"> 1.3232 </td> <td align="center"> 1.7207 </td> <td align="center"> 2.0796 </td> <td align="center"> 2.5176 </td> <td align="center"> 2.8314 </td> </tr>
  <tr> <td align="center"> 22 </td> <td align="center"> 1.3212 </td> <td align="center"> 1.7171 </td> <td align="center"> 2.0739 </td> <td align="center"> 2.5083 </td> <td align="center"> 2.8188 </td> </tr>
  <tr> <td align="center"> 23 </td> <td align="center"> 1.3195 </td> <td align="center"> 1.7139 </td> <td align="center"> 2.0687 </td> <td align="center"> 2.4999 </td> <td align="center"> 2.8073 </td> </tr>
  <tr> <td align="center"> 24 </td> <td align="center"> 1.3178 </td> <td align="center"> 1.7109 </td> <td align="center"> 2.0639 </td> <td align="center"> 2.4922 </td> <td align="center"> 2.7969 </td> </tr>
  <tr> <td align="center"> 25 </td> <td align="center"> 1.3163 </td> <td align="center"> 1.7081 </td> <td align="center"> 2.0595 </td> <td align="center"> 2.4851 </td> <td align="center"> 2.7874 </td> </tr>
  <tr> <td align="center"> 26 </td> <td align="center"> 1.3150 </td> <td align="center"> 1.7056 </td> <td align="center"> 2.0555 </td> <td align="center"> 2.4786 </td> <td align="center"> 2.7787 </td> </tr>
  <tr> <td align="center"> 27 </td> <td align="center"> 1.3137 </td> <td align="center"> 1.7033 </td> <td align="center"> 2.0518 </td> <td align="center"> 2.4727 </td> <td align="center"> 2.7707 </td> </tr>
  <tr> <td align="center"> 28 </td> <td align="center"> 1.3125 </td> <td align="center"> 1.7011 </td> <td align="center"> 2.0484 </td> <td align="center"> 2.4671 </td> <td align="center"> 2.7633 </td> </tr>
  <tr> <td align="center"> 29 </td> <td align="center"> 1.3114 </td> <td align="center"> 1.6991 </td> <td align="center"> 2.0452 </td> <td align="center"> 2.4620 </td> <td align="center"> 2.7564 </td> </tr>
  <tr> <td align="center"> 30 </td> <td align="center"> 1.3104 </td> <td align="center"> 1.6973 </td> <td align="center"> 2.0423 </td> <td align="center"> 2.4573 </td> <td align="center"> 2.7500 </td> </tr>
  <tr> <td align="center"> `\(\infty\)` </td> <td align="center"> 1.2816 </td> <td align="center"> 1.6449 </td> <td align="center"> 1.9600 </td> <td align="center"> 2.3263 </td> <td align="center"> 2.5758 </td> </tr>
   </table>
<p>I also wanted to include a plot of the distribution and describe what the values
are visually. <code>?mathplot</code> provides a guide to writing math notation in
<code>expression</code> to show math notation in plots. More information on how the math
notation will look is available
<a href="http://vis.supstat.com/2013/04/mathematical-annotation-in-r/">here</a>.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">library</span>(ggplot2)

x <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">seq</span>(<span style="color:#ae81ff">-3.5</span>, <span style="color:#ae81ff">3.5</span>, by <span style="color:#f92672">=</span> <span style="color:#ae81ff">.001</span>)
<span style="color:#a6e22e">ggplot</span>() <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">geom_ribbon</span>(<span style="color:#a6e22e">aes</span>(x <span style="color:#f92672">=</span> <span style="color:#a6e22e">seq</span>(<span style="color:#a6e22e">qnorm</span>(<span style="color:#ae81ff">.95</span>), <span style="color:#a6e22e">max</span>(x), by <span style="color:#f92672">=</span> <span style="color:#ae81ff">.001</span>),
                  ymin <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>,
                  ymax <span style="color:#f92672">=</span> <span style="color:#a6e22e">dnorm</span>(<span style="color:#a6e22e">seq</span>(<span style="color:#a6e22e">qnorm</span>(<span style="color:#ae81ff">.95</span>), <span style="color:#a6e22e">max</span>(x), by <span style="color:#f92672">=</span> <span style="color:#ae81ff">.001</span>))),
              fill <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;gray&#39;</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">geom_vline</span>(xintercept <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>, color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;black&#34;</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">geom_hline</span>(yintercept <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>, color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;black&#34;</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">stat_function</span>(data <span style="color:#f92672">=</span> <span style="color:#a6e22e">data.frame</span>(x<span style="color:#f92672">=</span>x),<span style="color:#a6e22e">aes</span>(x <span style="color:#f92672">=</span> x),  
                fun <span style="color:#f92672">=</span> dnorm, 
                size <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">geom_segment</span>(<span style="color:#a6e22e">aes</span>(x <span style="color:#f92672">=</span> <span style="color:#a6e22e">qnorm</span>(<span style="color:#ae81ff">.95</span>),
                   y <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>,
                   xend <span style="color:#f92672">=</span> <span style="color:#a6e22e">qnorm</span>(<span style="color:#ae81ff">.95</span>),
                   yend <span style="color:#f92672">=</span> <span style="color:#a6e22e">dnorm</span>(<span style="color:#a6e22e">qnorm</span>(<span style="color:#ae81ff">.95</span>))
  ),
  
  color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;black&#39;</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">theme_void</span>() <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">theme</span>(plot.margin <span style="color:#f92672">=</span> <span style="color:#a6e22e">unit</span>(<span style="color:#a6e22e">c</span>(<span style="color:#ae81ff">.1</span>,<span style="color:#ae81ff">.1</span>,<span style="color:#ae81ff">.1</span>,<span style="color:#ae81ff">.1</span>), <span style="color:#e6db74">&#34;cm&#34;</span>)) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">annotate</span>(geom <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;text&#39;</span>,
           x <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#a6e22e">qnorm</span>(<span style="color:#ae81ff">.95</span>)),
           y <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#ae81ff">-.04</span>),
           label <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#a6e22e">expression</span>(t<span style="color:#a6e22e">[paste</span>(alpha,<span style="color:#e6db74">&#39;,&#39;</span>,v)])),
           size <span style="color:#f92672">=</span> <span style="color:#ae81ff">4</span>,
           parse <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">coord_cartesian</span>(ylim <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#ae81ff">-.06</span>, <span style="color:#a6e22e">dnorm</span>(<span style="color:#a6e22e">qnorm</span>(<span style="color:#ae81ff">.5</span>))))
</code></pre></div><p><img src="https://roh.engineering/posts/2018/03/building-distribution-reference-tables-in-r/index_files/figure-html/unnamed-chunk-4-1.png" width="192" /></p>
<p>Below, is the code for the rest of the tables. I&rsquo;ve also placed a printable
version <a href="../statistical-distribution-tables">here</a>.</p>
<br>
<br>
<br>
<br>
<br>
<hr>
<h2 id="textnormal-distribution"><code>\(\text{Normal Distribution}\)</code></h2>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">x <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">seq</span>(<span style="color:#ae81ff">-3.5</span>, <span style="color:#ae81ff">3.5</span>, by <span style="color:#f92672">=</span> <span style="color:#ae81ff">.001</span>)
<span style="color:#a6e22e">ggplot</span>() <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">geom_ribbon</span>(<span style="color:#a6e22e">aes</span>(x <span style="color:#f92672">=</span> <span style="color:#a6e22e">seq</span>(<span style="color:#a6e22e">min</span>(x), <span style="color:#a6e22e">qnorm</span>(<span style="color:#ae81ff">.95</span>), by <span style="color:#f92672">=</span> <span style="color:#ae81ff">.001</span>),
                  ymin <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>,
                  ymax <span style="color:#f92672">=</span> <span style="color:#a6e22e">dnorm</span>(<span style="color:#a6e22e">seq</span>(<span style="color:#a6e22e">min</span>(x), <span style="color:#a6e22e">qnorm</span>(<span style="color:#ae81ff">.95</span>), by <span style="color:#f92672">=</span> <span style="color:#ae81ff">.001</span>))),
              fill <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;gray&#39;</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">geom_vline</span>(xintercept <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>, color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;black&#34;</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">geom_hline</span>(yintercept <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>, color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;black&#34;</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">stat_function</span>(data <span style="color:#f92672">=</span> <span style="color:#a6e22e">data.frame</span>(x<span style="color:#f92672">=</span>x),<span style="color:#a6e22e">aes</span>(x <span style="color:#f92672">=</span> x),  
                fun <span style="color:#f92672">=</span> dnorm, 
                size <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">geom_segment</span>(<span style="color:#a6e22e">aes</span>(x <span style="color:#f92672">=</span> <span style="color:#a6e22e">qnorm</span>(<span style="color:#ae81ff">.95</span>),
                   y <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>,
                   xend <span style="color:#f92672">=</span> <span style="color:#a6e22e">qnorm</span>(<span style="color:#ae81ff">.95</span>),
                   yend <span style="color:#f92672">=</span> <span style="color:#a6e22e">dnorm</span>(<span style="color:#a6e22e">qnorm</span>(<span style="color:#ae81ff">.95</span>))
  ),
  
  color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;black&#39;</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">theme_void</span>() <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">theme</span>(plot.margin <span style="color:#f92672">=</span> <span style="color:#a6e22e">unit</span>(<span style="color:#a6e22e">c</span>(<span style="color:#ae81ff">.1</span>,<span style="color:#ae81ff">.1</span>,<span style="color:#ae81ff">.1</span>,<span style="color:#ae81ff">.1</span>), <span style="color:#e6db74">&#34;cm&#34;</span>)) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">annotate</span>(geom <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;text&#39;</span>,
           x <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#a6e22e">qnorm</span>(<span style="color:#ae81ff">.95</span>)),
           y <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#ae81ff">-.04</span>),
           label <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#a6e22e">expression</span>(z[alpha])),
           size <span style="color:#f92672">=</span> <span style="color:#ae81ff">4</span>,
           parse <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">coord_cartesian</span>(ylim <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#ae81ff">-.06</span>, <span style="color:#a6e22e">dnorm</span>(<span style="color:#a6e22e">qnorm</span>(<span style="color:#ae81ff">.5</span>))))
</code></pre></div><p><img src="https://roh.engineering/posts/2018/03/building-distribution-reference-tables-in-r/index_files/figure-html/unnamed-chunk-5-1.png" width="192" /></p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">normalTable <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">matrix</span>(<span style="color:#a6e22e">round</span>(<span style="color:#a6e22e">pnorm</span>(<span style="color:#a6e22e">seq</span>(<span style="color:#ae81ff">0</span>, <span style="color:#ae81ff">3.49</span>, by <span style="color:#f92672">=</span> <span style="color:#ae81ff">.01</span>)), <span style="color:#ae81ff">4</span>), 
                      ncol <span style="color:#f92672">=</span> <span style="color:#ae81ff">10</span>,
                      byrow <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>)
<span style="color:#a6e22e">colnames</span>(normalTable) <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">seq</span>(<span style="color:#ae81ff">0</span>, <span style="color:#ae81ff">.09</span>, by <span style="color:#f92672">=</span> <span style="color:#ae81ff">.01</span>)
z <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">sprintf</span>(<span style="color:#e6db74">&#34;%01.1f&#34;</span>, <span style="color:#a6e22e">seq</span>(<span style="color:#ae81ff">0</span>, <span style="color:#ae81ff">3.4</span>, by <span style="color:#f92672">=</span> <span style="color:#ae81ff">.1</span>))
normalTable <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">data.frame</span>(<span style="color:#e6db74">&#34;$z$&#34;</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">paste0</span>(<span style="color:#e6db74">&#34;&#34;</span>, z, <span style="color:#e6db74">&#34;&#34;</span>),
                          normalTable,
                          stringsAsFactors <span style="color:#f92672">=</span> <span style="color:#66d9ef">FALSE</span>)
<span style="color:#a6e22e">colnames</span>(normalTable) <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">c</span>(<span style="color:#e6db74">&#34;z&#34;</span>, <span style="color:#a6e22e">seq</span>(<span style="color:#ae81ff">0</span>, <span style="color:#ae81ff">.09</span>, by <span style="color:#f92672">=</span> <span style="color:#ae81ff">.01</span>))
normalTable <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">xtable</span>(normalTable,
                      caption <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;Table 2: Cumulative Probabilities of the Standard Normal Distribution, $X \\sim N(0,1)$&#34;</span>,
                      align <span style="color:#f92672">=</span> <span style="color:#a6e22e">rep</span>(<span style="color:#e6db74">&#34;c&#34;</span>, <span style="color:#a6e22e">ncol</span>(normalTable)<span style="color:#ae81ff">+1</span>),
                      digits <span style="color:#f92672">=</span> <span style="color:#ae81ff">4</span>)
<span style="color:#a6e22e">print</span>(normalTable)
</code></pre></div><!-- html table generated in R 4.0.3 by xtable 1.8-4 package -->
<!-- Wed Feb 17 21:01:47 2021 -->
<table border='2' cellpadding='15' cellpadding='5' rules ='all' width ='100%'>
<caption align="top"> Table 2: Cumulative Probabilities of the Standard Normal Distribution, `\(X \sim N(0,1)\)` </caption>
<tr> <th> z </th> <th> 0 </th> <th> 0.01 </th> <th> 0.02 </th> <th> 0.03 </th> <th> 0.04 </th> <th> 0.05 </th> <th> 0.06 </th> <th> 0.07 </th> <th> 0.08 </th> <th> 0.09 </th>  </tr>
  <tr> <td align="center"> 0.0 </td> <td align="center"> 0.5000 </td> <td align="center"> 0.5040 </td> <td align="center"> 0.5080 </td> <td align="center"> 0.5120 </td> <td align="center"> 0.5160 </td> <td align="center"> 0.5199 </td> <td align="center"> 0.5239 </td> <td align="center"> 0.5279 </td> <td align="center"> 0.5319 </td> <td align="center"> 0.5359 </td> </tr>
  <tr> <td align="center"> 0.1 </td> <td align="center"> 0.5398 </td> <td align="center"> 0.5438 </td> <td align="center"> 0.5478 </td> <td align="center"> 0.5517 </td> <td align="center"> 0.5557 </td> <td align="center"> 0.5596 </td> <td align="center"> 0.5636 </td> <td align="center"> 0.5675 </td> <td align="center"> 0.5714 </td> <td align="center"> 0.5753 </td> </tr>
  <tr> <td align="center"> 0.2 </td> <td align="center"> 0.5793 </td> <td align="center"> 0.5832 </td> <td align="center"> 0.5871 </td> <td align="center"> 0.5910 </td> <td align="center"> 0.5948 </td> <td align="center"> 0.5987 </td> <td align="center"> 0.6026 </td> <td align="center"> 0.6064 </td> <td align="center"> 0.6103 </td> <td align="center"> 0.6141 </td> </tr>
  <tr> <td align="center"> 0.3 </td> <td align="center"> 0.6179 </td> <td align="center"> 0.6217 </td> <td align="center"> 0.6255 </td> <td align="center"> 0.6293 </td> <td align="center"> 0.6331 </td> <td align="center"> 0.6368 </td> <td align="center"> 0.6406 </td> <td align="center"> 0.6443 </td> <td align="center"> 0.6480 </td> <td align="center"> 0.6517 </td> </tr>
  <tr> <td align="center"> 0.4 </td> <td align="center"> 0.6554 </td> <td align="center"> 0.6591 </td> <td align="center"> 0.6628 </td> <td align="center"> 0.6664 </td> <td align="center"> 0.6700 </td> <td align="center"> 0.6736 </td> <td align="center"> 0.6772 </td> <td align="center"> 0.6808 </td> <td align="center"> 0.6844 </td> <td align="center"> 0.6879 </td> </tr>
  <tr> <td align="center"> 0.5 </td> <td align="center"> 0.6915 </td> <td align="center"> 0.6950 </td> <td align="center"> 0.6985 </td> <td align="center"> 0.7019 </td> <td align="center"> 0.7054 </td> <td align="center"> 0.7088 </td> <td align="center"> 0.7123 </td> <td align="center"> 0.7157 </td> <td align="center"> 0.7190 </td> <td align="center"> 0.7224 </td> </tr>
  <tr> <td align="center"> 0.6 </td> <td align="center"> 0.7257 </td> <td align="center"> 0.7291 </td> <td align="center"> 0.7324 </td> <td align="center"> 0.7357 </td> <td align="center"> 0.7389 </td> <td align="center"> 0.7422 </td> <td align="center"> 0.7454 </td> <td align="center"> 0.7486 </td> <td align="center"> 0.7517 </td> <td align="center"> 0.7549 </td> </tr>
  <tr> <td align="center"> 0.7 </td> <td align="center"> 0.7580 </td> <td align="center"> 0.7611 </td> <td align="center"> 0.7642 </td> <td align="center"> 0.7673 </td> <td align="center"> 0.7704 </td> <td align="center"> 0.7734 </td> <td align="center"> 0.7764 </td> <td align="center"> 0.7794 </td> <td align="center"> 0.7823 </td> <td align="center"> 0.7852 </td> </tr>
  <tr> <td align="center"> 0.8 </td> <td align="center"> 0.7881 </td> <td align="center"> 0.7910 </td> <td align="center"> 0.7939 </td> <td align="center"> 0.7967 </td> <td align="center"> 0.7995 </td> <td align="center"> 0.8023 </td> <td align="center"> 0.8051 </td> <td align="center"> 0.8078 </td> <td align="center"> 0.8106 </td> <td align="center"> 0.8133 </td> </tr>
  <tr> <td align="center"> 0.9 </td> <td align="center"> 0.8159 </td> <td align="center"> 0.8186 </td> <td align="center"> 0.8212 </td> <td align="center"> 0.8238 </td> <td align="center"> 0.8264 </td> <td align="center"> 0.8289 </td> <td align="center"> 0.8315 </td> <td align="center"> 0.8340 </td> <td align="center"> 0.8365 </td> <td align="center"> 0.8389 </td> </tr>
  <tr> <td align="center"> 1.0 </td> <td align="center"> 0.8413 </td> <td align="center"> 0.8438 </td> <td align="center"> 0.8461 </td> <td align="center"> 0.8485 </td> <td align="center"> 0.8508 </td> <td align="center"> 0.8531 </td> <td align="center"> 0.8554 </td> <td align="center"> 0.8577 </td> <td align="center"> 0.8599 </td> <td align="center"> 0.8621 </td> </tr>
  <tr> <td align="center"> 1.1 </td> <td align="center"> 0.8643 </td> <td align="center"> 0.8665 </td> <td align="center"> 0.8686 </td> <td align="center"> 0.8708 </td> <td align="center"> 0.8729 </td> <td align="center"> 0.8749 </td> <td align="center"> 0.8770 </td> <td align="center"> 0.8790 </td> <td align="center"> 0.8810 </td> <td align="center"> 0.8830 </td> </tr>
  <tr> <td align="center"> 1.2 </td> <td align="center"> 0.8849 </td> <td align="center"> 0.8869 </td> <td align="center"> 0.8888 </td> <td align="center"> 0.8907 </td> <td align="center"> 0.8925 </td> <td align="center"> 0.8944 </td> <td align="center"> 0.8962 </td> <td align="center"> 0.8980 </td> <td align="center"> 0.8997 </td> <td align="center"> 0.9015 </td> </tr>
  <tr> <td align="center"> 1.3 </td> <td align="center"> 0.9032 </td> <td align="center"> 0.9049 </td> <td align="center"> 0.9066 </td> <td align="center"> 0.9082 </td> <td align="center"> 0.9099 </td> <td align="center"> 0.9115 </td> <td align="center"> 0.9131 </td> <td align="center"> 0.9147 </td> <td align="center"> 0.9162 </td> <td align="center"> 0.9177 </td> </tr>
  <tr> <td align="center"> 1.4 </td> <td align="center"> 0.9192 </td> <td align="center"> 0.9207 </td> <td align="center"> 0.9222 </td> <td align="center"> 0.9236 </td> <td align="center"> 0.9251 </td> <td align="center"> 0.9265 </td> <td align="center"> 0.9279 </td> <td align="center"> 0.9292 </td> <td align="center"> 0.9306 </td> <td align="center"> 0.9319 </td> </tr>
  <tr> <td align="center"> 1.5 </td> <td align="center"> 0.9332 </td> <td align="center"> 0.9345 </td> <td align="center"> 0.9357 </td> <td align="center"> 0.9370 </td> <td align="center"> 0.9382 </td> <td align="center"> 0.9394 </td> <td align="center"> 0.9406 </td> <td align="center"> 0.9418 </td> <td align="center"> 0.9429 </td> <td align="center"> 0.9441 </td> </tr>
  <tr> <td align="center"> 1.6 </td> <td align="center"> 0.9452 </td> <td align="center"> 0.9463 </td> <td align="center"> 0.9474 </td> <td align="center"> 0.9484 </td> <td align="center"> 0.9495 </td> <td align="center"> 0.9505 </td> <td align="center"> 0.9515 </td> <td align="center"> 0.9525 </td> <td align="center"> 0.9535 </td> <td align="center"> 0.9545 </td> </tr>
  <tr> <td align="center"> 1.7 </td> <td align="center"> 0.9554 </td> <td align="center"> 0.9564 </td> <td align="center"> 0.9573 </td> <td align="center"> 0.9582 </td> <td align="center"> 0.9591 </td> <td align="center"> 0.9599 </td> <td align="center"> 0.9608 </td> <td align="center"> 0.9616 </td> <td align="center"> 0.9625 </td> <td align="center"> 0.9633 </td> </tr>
  <tr> <td align="center"> 1.8 </td> <td align="center"> 0.9641 </td> <td align="center"> 0.9649 </td> <td align="center"> 0.9656 </td> <td align="center"> 0.9664 </td> <td align="center"> 0.9671 </td> <td align="center"> 0.9678 </td> <td align="center"> 0.9686 </td> <td align="center"> 0.9693 </td> <td align="center"> 0.9699 </td> <td align="center"> 0.9706 </td> </tr>
  <tr> <td align="center"> 1.9 </td> <td align="center"> 0.9713 </td> <td align="center"> 0.9719 </td> <td align="center"> 0.9726 </td> <td align="center"> 0.9732 </td> <td align="center"> 0.9738 </td> <td align="center"> 0.9744 </td> <td align="center"> 0.9750 </td> <td align="center"> 0.9756 </td> <td align="center"> 0.9761 </td> <td align="center"> 0.9767 </td> </tr>
  <tr> <td align="center"> 2.0 </td> <td align="center"> 0.9772 </td> <td align="center"> 0.9778 </td> <td align="center"> 0.9783 </td> <td align="center"> 0.9788 </td> <td align="center"> 0.9793 </td> <td align="center"> 0.9798 </td> <td align="center"> 0.9803 </td> <td align="center"> 0.9808 </td> <td align="center"> 0.9812 </td> <td align="center"> 0.9817 </td> </tr>
  <tr> <td align="center"> 2.1 </td> <td align="center"> 0.9821 </td> <td align="center"> 0.9826 </td> <td align="center"> 0.9830 </td> <td align="center"> 0.9834 </td> <td align="center"> 0.9838 </td> <td align="center"> 0.9842 </td> <td align="center"> 0.9846 </td> <td align="center"> 0.9850 </td> <td align="center"> 0.9854 </td> <td align="center"> 0.9857 </td> </tr>
  <tr> <td align="center"> 2.2 </td> <td align="center"> 0.9861 </td> <td align="center"> 0.9864 </td> <td align="center"> 0.9868 </td> <td align="center"> 0.9871 </td> <td align="center"> 0.9875 </td> <td align="center"> 0.9878 </td> <td align="center"> 0.9881 </td> <td align="center"> 0.9884 </td> <td align="center"> 0.9887 </td> <td align="center"> 0.9890 </td> </tr>
  <tr> <td align="center"> 2.3 </td> <td align="center"> 0.9893 </td> <td align="center"> 0.9896 </td> <td align="center"> 0.9898 </td> <td align="center"> 0.9901 </td> <td align="center"> 0.9904 </td> <td align="center"> 0.9906 </td> <td align="center"> 0.9909 </td> <td align="center"> 0.9911 </td> <td align="center"> 0.9913 </td> <td align="center"> 0.9916 </td> </tr>
  <tr> <td align="center"> 2.4 </td> <td align="center"> 0.9918 </td> <td align="center"> 0.9920 </td> <td align="center"> 0.9922 </td> <td align="center"> 0.9925 </td> <td align="center"> 0.9927 </td> <td align="center"> 0.9929 </td> <td align="center"> 0.9931 </td> <td align="center"> 0.9932 </td> <td align="center"> 0.9934 </td> <td align="center"> 0.9936 </td> </tr>
  <tr> <td align="center"> 2.5 </td> <td align="center"> 0.9938 </td> <td align="center"> 0.9940 </td> <td align="center"> 0.9941 </td> <td align="center"> 0.9943 </td> <td align="center"> 0.9945 </td> <td align="center"> 0.9946 </td> <td align="center"> 0.9948 </td> <td align="center"> 0.9949 </td> <td align="center"> 0.9951 </td> <td align="center"> 0.9952 </td> </tr>
  <tr> <td align="center"> 2.6 </td> <td align="center"> 0.9953 </td> <td align="center"> 0.9955 </td> <td align="center"> 0.9956 </td> <td align="center"> 0.9957 </td> <td align="center"> 0.9959 </td> <td align="center"> 0.9960 </td> <td align="center"> 0.9961 </td> <td align="center"> 0.9962 </td> <td align="center"> 0.9963 </td> <td align="center"> 0.9964 </td> </tr>
  <tr> <td align="center"> 2.7 </td> <td align="center"> 0.9965 </td> <td align="center"> 0.9966 </td> <td align="center"> 0.9967 </td> <td align="center"> 0.9968 </td> <td align="center"> 0.9969 </td> <td align="center"> 0.9970 </td> <td align="center"> 0.9971 </td> <td align="center"> 0.9972 </td> <td align="center"> 0.9973 </td> <td align="center"> 0.9974 </td> </tr>
  <tr> <td align="center"> 2.8 </td> <td align="center"> 0.9974 </td> <td align="center"> 0.9975 </td> <td align="center"> 0.9976 </td> <td align="center"> 0.9977 </td> <td align="center"> 0.9977 </td> <td align="center"> 0.9978 </td> <td align="center"> 0.9979 </td> <td align="center"> 0.9979 </td> <td align="center"> 0.9980 </td> <td align="center"> 0.9981 </td> </tr>
  <tr> <td align="center"> 2.9 </td> <td align="center"> 0.9981 </td> <td align="center"> 0.9982 </td> <td align="center"> 0.9982 </td> <td align="center"> 0.9983 </td> <td align="center"> 0.9984 </td> <td align="center"> 0.9984 </td> <td align="center"> 0.9985 </td> <td align="center"> 0.9985 </td> <td align="center"> 0.9986 </td> <td align="center"> 0.9986 </td> </tr>
  <tr> <td align="center"> 3.0 </td> <td align="center"> 0.9987 </td> <td align="center"> 0.9987 </td> <td align="center"> 0.9987 </td> <td align="center"> 0.9988 </td> <td align="center"> 0.9988 </td> <td align="center"> 0.9989 </td> <td align="center"> 0.9989 </td> <td align="center"> 0.9989 </td> <td align="center"> 0.9990 </td> <td align="center"> 0.9990 </td> </tr>
  <tr> <td align="center"> 3.1 </td> <td align="center"> 0.9990 </td> <td align="center"> 0.9991 </td> <td align="center"> 0.9991 </td> <td align="center"> 0.9991 </td> <td align="center"> 0.9992 </td> <td align="center"> 0.9992 </td> <td align="center"> 0.9992 </td> <td align="center"> 0.9992 </td> <td align="center"> 0.9993 </td> <td align="center"> 0.9993 </td> </tr>
  <tr> <td align="center"> 3.2 </td> <td align="center"> 0.9993 </td> <td align="center"> 0.9993 </td> <td align="center"> 0.9994 </td> <td align="center"> 0.9994 </td> <td align="center"> 0.9994 </td> <td align="center"> 0.9994 </td> <td align="center"> 0.9994 </td> <td align="center"> 0.9995 </td> <td align="center"> 0.9995 </td> <td align="center"> 0.9995 </td> </tr>
  <tr> <td align="center"> 3.3 </td> <td align="center"> 0.9995 </td> <td align="center"> 0.9995 </td> <td align="center"> 0.9995 </td> <td align="center"> 0.9996 </td> <td align="center"> 0.9996 </td> <td align="center"> 0.9996 </td> <td align="center"> 0.9996 </td> <td align="center"> 0.9996 </td> <td align="center"> 0.9996 </td> <td align="center"> 0.9997 </td> </tr>
  <tr> <td align="center"> 3.4 </td> <td align="center"> 0.9997 </td> <td align="center"> 0.9997 </td> <td align="center"> 0.9997 </td> <td align="center"> 0.9997 </td> <td align="center"> 0.9997 </td> <td align="center"> 0.9997 </td> <td align="center"> 0.9997 </td> <td align="center"> 0.9997 </td> <td align="center"> 0.9997 </td> <td align="center"> 0.9998 </td> </tr>
   </table>
<h2 id="t-text-distribution"><code>\(t \text{ Distribution}\)</code></h2>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">x <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">seq</span>(<span style="color:#ae81ff">-3.5</span>, <span style="color:#ae81ff">3.5</span>, by <span style="color:#f92672">=</span> <span style="color:#ae81ff">.001</span>)
<span style="color:#a6e22e">ggplot</span>() <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">geom_ribbon</span>(<span style="color:#a6e22e">aes</span>(x <span style="color:#f92672">=</span> <span style="color:#a6e22e">seq</span>(<span style="color:#a6e22e">qnorm</span>(<span style="color:#ae81ff">.95</span>), <span style="color:#a6e22e">max</span>(x), by <span style="color:#f92672">=</span> <span style="color:#ae81ff">.001</span>),
                  ymin <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>,
                  ymax <span style="color:#f92672">=</span> <span style="color:#a6e22e">dnorm</span>(<span style="color:#a6e22e">seq</span>(<span style="color:#a6e22e">qnorm</span>(<span style="color:#ae81ff">.95</span>), <span style="color:#a6e22e">max</span>(x), by <span style="color:#f92672">=</span> <span style="color:#ae81ff">.001</span>))),
              fill <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;gray&#39;</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">geom_vline</span>(xintercept <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>, color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;black&#34;</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">geom_hline</span>(yintercept <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>, color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;black&#34;</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">stat_function</span>(data <span style="color:#f92672">=</span> <span style="color:#a6e22e">data.frame</span>(x<span style="color:#f92672">=</span>x),<span style="color:#a6e22e">aes</span>(x <span style="color:#f92672">=</span> x),  
                fun <span style="color:#f92672">=</span> dnorm, 
                size <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">geom_segment</span>(<span style="color:#a6e22e">aes</span>(x <span style="color:#f92672">=</span> <span style="color:#a6e22e">qnorm</span>(<span style="color:#ae81ff">.95</span>),
                   y <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>,
                   xend <span style="color:#f92672">=</span> <span style="color:#a6e22e">qnorm</span>(<span style="color:#ae81ff">.95</span>),
                   yend <span style="color:#f92672">=</span> <span style="color:#a6e22e">dnorm</span>(<span style="color:#a6e22e">qnorm</span>(<span style="color:#ae81ff">.95</span>))
  ),
  
  color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;black&#39;</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">theme_void</span>() <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">theme</span>(plot.margin <span style="color:#f92672">=</span> <span style="color:#a6e22e">unit</span>(<span style="color:#a6e22e">c</span>(<span style="color:#ae81ff">.1</span>,<span style="color:#ae81ff">.1</span>,<span style="color:#ae81ff">.1</span>,<span style="color:#ae81ff">.1</span>), <span style="color:#e6db74">&#34;cm&#34;</span>)) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">annotate</span>(geom <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;text&#39;</span>,
           x <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#a6e22e">qnorm</span>(<span style="color:#ae81ff">.95</span>)),
           y <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#ae81ff">-.04</span>),
           label <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#a6e22e">expression</span>(t<span style="color:#a6e22e">[paste</span>(alpha,<span style="color:#e6db74">&#39;,&#39;</span>,v)])),
           size <span style="color:#f92672">=</span> <span style="color:#ae81ff">4</span>,
           parse <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">coord_cartesian</span>(ylim <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#ae81ff">-.06</span>, <span style="color:#a6e22e">dnorm</span>(<span style="color:#a6e22e">qnorm</span>(<span style="color:#ae81ff">.5</span>))))
</code></pre></div><p><img src="https://roh.engineering/posts/2018/03/building-distribution-reference-tables-in-r/index_files/figure-html/unnamed-chunk-6-1.png" width="192" /></p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">alpha <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">c</span>(<span style="color:#ae81ff">.1</span>, <span style="color:#ae81ff">.05</span>, <span style="color:#ae81ff">.025</span>, <span style="color:#ae81ff">.01</span>, <span style="color:#ae81ff">.005</span>)
v <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">c</span>(<span style="color:#a6e22e">seq</span>(<span style="color:#ae81ff">1</span>, <span style="color:#ae81ff">30</span>, by <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>), <span style="color:#66d9ef">Inf</span>)
tTable <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">sapply</span>((<span style="color:#ae81ff">1</span><span style="color:#f92672">-</span>alpha), <span style="color:#a6e22e">function</span>(x) <span style="color:#a6e22e">qt</span>(x, df <span style="color:#f92672">=</span> v))
<span style="color:#a6e22e">colnames</span>(tTable) <span style="color:#f92672">&lt;-</span> alpha
tTable <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">data.frame</span>(<span style="color:#e6db74">&#34;$v \\big\\backslash \\alpha$&#34;</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">paste0</span>(<span style="color:#e6db74">&#34;&#34;</span>, v, <span style="color:#e6db74">&#34;&#34;</span>),
                     tTable,
                     stringsAsFactors <span style="color:#f92672">=</span> <span style="color:#66d9ef">FALSE</span>,
                     check.names <span style="color:#f92672">=</span> <span style="color:#66d9ef">FALSE</span>)
tTable[[1]][tTable[[1]] <span style="color:#f92672">==</span> <span style="color:#e6db74">&#34;Inf&#34;</span>] <span style="color:#f92672">&lt;-</span> <span style="color:#e6db74">&#34;$\\infty$&#34;</span> 
tTable <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">xtable</span>(tTable,
                      caption <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;Table 3: Percentiles of the *t* Distribution&#34;</span>,
                      align <span style="color:#f92672">=</span> <span style="color:#a6e22e">rep</span>(<span style="color:#e6db74">&#34;c&#34;</span>, <span style="color:#a6e22e">ncol</span>(tTable)<span style="color:#ae81ff">+1</span>),
                      digits <span style="color:#f92672">=</span> <span style="color:#ae81ff">4</span>)
<span style="color:#a6e22e">print</span>(tTable)
</code></pre></div><!-- html table generated in R 4.0.3 by xtable 1.8-4 package -->
<!-- Wed Feb 17 21:01:47 2021 -->
<table border='2' cellpadding='15' cellpadding='5' rules ='all' width ='100%'>
<caption align="top"> Table 3: Percentiles of the *t* Distribution </caption>
<tr> <th> `\(v \big\backslash \alpha\)` </th> <th> 0.1 </th> <th> 0.05 </th> <th> 0.025 </th> <th> 0.01 </th> <th> 0.005 </th>  </tr>
  <tr> <td align="center"> 1 </td> <td align="center"> 3.0777 </td> <td align="center"> 6.3138 </td> <td align="center"> 12.7062 </td> <td align="center"> 31.8205 </td> <td align="center"> 63.6567 </td> </tr>
  <tr> <td align="center"> 2 </td> <td align="center"> 1.8856 </td> <td align="center"> 2.9200 </td> <td align="center"> 4.3027 </td> <td align="center"> 6.9646 </td> <td align="center"> 9.9248 </td> </tr>
  <tr> <td align="center"> 3 </td> <td align="center"> 1.6377 </td> <td align="center"> 2.3534 </td> <td align="center"> 3.1824 </td> <td align="center"> 4.5407 </td> <td align="center"> 5.8409 </td> </tr>
  <tr> <td align="center"> 4 </td> <td align="center"> 1.5332 </td> <td align="center"> 2.1318 </td> <td align="center"> 2.7764 </td> <td align="center"> 3.7469 </td> <td align="center"> 4.6041 </td> </tr>
  <tr> <td align="center"> 5 </td> <td align="center"> 1.4759 </td> <td align="center"> 2.0150 </td> <td align="center"> 2.5706 </td> <td align="center"> 3.3649 </td> <td align="center"> 4.0321 </td> </tr>
  <tr> <td align="center"> 6 </td> <td align="center"> 1.4398 </td> <td align="center"> 1.9432 </td> <td align="center"> 2.4469 </td> <td align="center"> 3.1427 </td> <td align="center"> 3.7074 </td> </tr>
  <tr> <td align="center"> 7 </td> <td align="center"> 1.4149 </td> <td align="center"> 1.8946 </td> <td align="center"> 2.3646 </td> <td align="center"> 2.9980 </td> <td align="center"> 3.4995 </td> </tr>
  <tr> <td align="center"> 8 </td> <td align="center"> 1.3968 </td> <td align="center"> 1.8595 </td> <td align="center"> 2.3060 </td> <td align="center"> 2.8965 </td> <td align="center"> 3.3554 </td> </tr>
  <tr> <td align="center"> 9 </td> <td align="center"> 1.3830 </td> <td align="center"> 1.8331 </td> <td align="center"> 2.2622 </td> <td align="center"> 2.8214 </td> <td align="center"> 3.2498 </td> </tr>
  <tr> <td align="center"> 10 </td> <td align="center"> 1.3722 </td> <td align="center"> 1.8125 </td> <td align="center"> 2.2281 </td> <td align="center"> 2.7638 </td> <td align="center"> 3.1693 </td> </tr>
  <tr> <td align="center"> 11 </td> <td align="center"> 1.3634 </td> <td align="center"> 1.7959 </td> <td align="center"> 2.2010 </td> <td align="center"> 2.7181 </td> <td align="center"> 3.1058 </td> </tr>
  <tr> <td align="center"> 12 </td> <td align="center"> 1.3562 </td> <td align="center"> 1.7823 </td> <td align="center"> 2.1788 </td> <td align="center"> 2.6810 </td> <td align="center"> 3.0545 </td> </tr>
  <tr> <td align="center"> 13 </td> <td align="center"> 1.3502 </td> <td align="center"> 1.7709 </td> <td align="center"> 2.1604 </td> <td align="center"> 2.6503 </td> <td align="center"> 3.0123 </td> </tr>
  <tr> <td align="center"> 14 </td> <td align="center"> 1.3450 </td> <td align="center"> 1.7613 </td> <td align="center"> 2.1448 </td> <td align="center"> 2.6245 </td> <td align="center"> 2.9768 </td> </tr>
  <tr> <td align="center"> 15 </td> <td align="center"> 1.3406 </td> <td align="center"> 1.7531 </td> <td align="center"> 2.1314 </td> <td align="center"> 2.6025 </td> <td align="center"> 2.9467 </td> </tr>
  <tr> <td align="center"> 16 </td> <td align="center"> 1.3368 </td> <td align="center"> 1.7459 </td> <td align="center"> 2.1199 </td> <td align="center"> 2.5835 </td> <td align="center"> 2.9208 </td> </tr>
  <tr> <td align="center"> 17 </td> <td align="center"> 1.3334 </td> <td align="center"> 1.7396 </td> <td align="center"> 2.1098 </td> <td align="center"> 2.5669 </td> <td align="center"> 2.8982 </td> </tr>
  <tr> <td align="center"> 18 </td> <td align="center"> 1.3304 </td> <td align="center"> 1.7341 </td> <td align="center"> 2.1009 </td> <td align="center"> 2.5524 </td> <td align="center"> 2.8784 </td> </tr>
  <tr> <td align="center"> 19 </td> <td align="center"> 1.3277 </td> <td align="center"> 1.7291 </td> <td align="center"> 2.0930 </td> <td align="center"> 2.5395 </td> <td align="center"> 2.8609 </td> </tr>
  <tr> <td align="center"> 20 </td> <td align="center"> 1.3253 </td> <td align="center"> 1.7247 </td> <td align="center"> 2.0860 </td> <td align="center"> 2.5280 </td> <td align="center"> 2.8453 </td> </tr>
  <tr> <td align="center"> 21 </td> <td align="center"> 1.3232 </td> <td align="center"> 1.7207 </td> <td align="center"> 2.0796 </td> <td align="center"> 2.5176 </td> <td align="center"> 2.8314 </td> </tr>
  <tr> <td align="center"> 22 </td> <td align="center"> 1.3212 </td> <td align="center"> 1.7171 </td> <td align="center"> 2.0739 </td> <td align="center"> 2.5083 </td> <td align="center"> 2.8188 </td> </tr>
  <tr> <td align="center"> 23 </td> <td align="center"> 1.3195 </td> <td align="center"> 1.7139 </td> <td align="center"> 2.0687 </td> <td align="center"> 2.4999 </td> <td align="center"> 2.8073 </td> </tr>
  <tr> <td align="center"> 24 </td> <td align="center"> 1.3178 </td> <td align="center"> 1.7109 </td> <td align="center"> 2.0639 </td> <td align="center"> 2.4922 </td> <td align="center"> 2.7969 </td> </tr>
  <tr> <td align="center"> 25 </td> <td align="center"> 1.3163 </td> <td align="center"> 1.7081 </td> <td align="center"> 2.0595 </td> <td align="center"> 2.4851 </td> <td align="center"> 2.7874 </td> </tr>
  <tr> <td align="center"> 26 </td> <td align="center"> 1.3150 </td> <td align="center"> 1.7056 </td> <td align="center"> 2.0555 </td> <td align="center"> 2.4786 </td> <td align="center"> 2.7787 </td> </tr>
  <tr> <td align="center"> 27 </td> <td align="center"> 1.3137 </td> <td align="center"> 1.7033 </td> <td align="center"> 2.0518 </td> <td align="center"> 2.4727 </td> <td align="center"> 2.7707 </td> </tr>
  <tr> <td align="center"> 28 </td> <td align="center"> 1.3125 </td> <td align="center"> 1.7011 </td> <td align="center"> 2.0484 </td> <td align="center"> 2.4671 </td> <td align="center"> 2.7633 </td> </tr>
  <tr> <td align="center"> 29 </td> <td align="center"> 1.3114 </td> <td align="center"> 1.6991 </td> <td align="center"> 2.0452 </td> <td align="center"> 2.4620 </td> <td align="center"> 2.7564 </td> </tr>
  <tr> <td align="center"> 30 </td> <td align="center"> 1.3104 </td> <td align="center"> 1.6973 </td> <td align="center"> 2.0423 </td> <td align="center"> 2.4573 </td> <td align="center"> 2.7500 </td> </tr>
  <tr> <td align="center"> `\(\infty\)` </td> <td align="center"> 1.2816 </td> <td align="center"> 1.6449 </td> <td align="center"> 1.9600 </td> <td align="center"> 2.3263 </td> <td align="center"> 2.5758 </td> </tr>
   </table>
<h2 id="chi2-text-distribution"><code>\(\chi^2 \text{ Distribution}\)</code></h2>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">x <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">seq</span>(<span style="color:#ae81ff">0</span>, <span style="color:#ae81ff">30</span>, <span style="color:#ae81ff">.01</span>)
v <span style="color:#f92672">&lt;-</span> <span style="color:#ae81ff">10</span>
<span style="color:#a6e22e">ggplot</span>() <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">geom_ribbon</span>(<span style="color:#a6e22e">aes</span>(x <span style="color:#f92672">=</span> <span style="color:#a6e22e">seq</span>(<span style="color:#a6e22e">qchisq</span>(<span style="color:#ae81ff">.95</span>, df <span style="color:#f92672">=</span> v), <span style="color:#a6e22e">max</span>(x), by <span style="color:#f92672">=</span> <span style="color:#ae81ff">.001</span>),
                  ymin <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>,
                  ymax <span style="color:#f92672">=</span> <span style="color:#a6e22e">dchisq</span>(<span style="color:#a6e22e">seq</span>(<span style="color:#a6e22e">qchisq</span>(<span style="color:#ae81ff">.95</span>, df <span style="color:#f92672">=</span> v), <span style="color:#a6e22e">max</span>(x), by <span style="color:#f92672">=</span> <span style="color:#ae81ff">.001</span>),
                                df <span style="color:#f92672">=</span> v)
                  ),
              fill <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;gray&#39;</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">geom_vline</span>(xintercept <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>, color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;black&#34;</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">geom_hline</span>(yintercept <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>, color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;black&#34;</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">stat_function</span>(data <span style="color:#f92672">=</span> <span style="color:#a6e22e">data.frame</span>(x<span style="color:#f92672">=</span>x),<span style="color:#a6e22e">aes</span>(x <span style="color:#f92672">=</span> x),  
                fun <span style="color:#f92672">=</span> dchisq, 
                args <span style="color:#f92672">=</span> <span style="color:#a6e22e">list</span>(df <span style="color:#f92672">=</span> v),
                size <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">geom_segment</span>(<span style="color:#a6e22e">aes</span>(x <span style="color:#f92672">=</span> <span style="color:#a6e22e">qchisq</span>(<span style="color:#ae81ff">.95</span>, df <span style="color:#f92672">=</span> v),
                   y <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>,
                   xend <span style="color:#f92672">=</span> <span style="color:#a6e22e">qchisq</span>(<span style="color:#ae81ff">.95</span>, df <span style="color:#f92672">=</span> v),
                   yend <span style="color:#f92672">=</span> <span style="color:#a6e22e">dchisq</span>(<span style="color:#a6e22e">qchisq</span>(<span style="color:#ae81ff">.95</span>, df <span style="color:#f92672">=</span> v), df <span style="color:#f92672">=</span> v)
  ),
  
  color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;black&#39;</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">theme_void</span>() <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">theme</span>(plot.margin <span style="color:#f92672">=</span> <span style="color:#a6e22e">unit</span>(<span style="color:#a6e22e">c</span>(<span style="color:#ae81ff">.1</span>,<span style="color:#ae81ff">.1</span>,<span style="color:#ae81ff">.1</span>,<span style="color:#ae81ff">.1</span>), <span style="color:#e6db74">&#34;cm&#34;</span>)) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">annotate</span>(geom <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;text&#39;</span>,
           x <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#a6e22e">qchisq</span>(<span style="color:#ae81ff">.95</span>, df <span style="color:#f92672">=</span> v)),
           y <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#ae81ff">-.015</span>),
           label <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#a6e22e">expression</span>( <span style="color:#a6e22e">paste</span>(Chi^2)<span style="color:#a6e22e">[paste</span>(alpha,<span style="color:#e6db74">&#39;,&#39;</span>,<span style="color:#e6db74">&#39;v&#39;</span>)])),
           size <span style="color:#f92672">=</span> <span style="color:#ae81ff">4</span>,
           parse <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">coord_cartesian</span>(ylim <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#ae81ff">-.02</span>, <span style="color:#a6e22e">dchisq</span>(<span style="color:#a6e22e">qchisq</span>(<span style="color:#ae81ff">.5</span>, df <span style="color:#f92672">=</span> v), df <span style="color:#f92672">=</span> v)))
</code></pre></div><p><img src="https://roh.engineering/posts/2018/03/building-distribution-reference-tables-in-r/index_files/figure-html/unnamed-chunk-7-1.png" width="192" /></p>
<!-- html table generated in R 4.0.3 by xtable 1.8-4 package -->
<!-- Wed Feb 17 21:01:47 2021 -->
<table border='2' cellpadding='15' cellpadding='5' rules ='all' width ='100%'>
<caption align="top"> Table 4: Percentiles of the `\(\chi^2\)` Distribution </caption>
<tr> <th> `\(v \big\backslash \alpha\)` </th> <th> 0.995 </th> <th> 0.99 </th> <th> 0.975 </th> <th> 0.95 </th> <th> 0.9 </th> <th> 0.75 </th> <th> 0.5 </th> <th> 0.25 </th> <th> 0.1 </th> <th> 0.05 </th> <th> 0.025 </th> <th> 0.01 </th> <th> 0.005 </th> <th> 0.001 </th>  </tr>
  <tr> <td align="center"> 1 </td> <td align="center"> 0.00 </td> <td align="center"> 0.00 </td> <td align="center"> 0.00 </td> <td align="center"> 0.00 </td> <td align="center"> 0.02 </td> <td align="center"> 0.10 </td> <td align="center"> 0.45 </td> <td align="center"> 1.32 </td> <td align="center"> 2.71 </td> <td align="center"> 3.84 </td> <td align="center"> 5.02 </td> <td align="center"> 6.63 </td> <td align="center"> 7.88 </td> <td align="center"> 10.83 </td> </tr>
  <tr> <td align="center"> 2 </td> <td align="center"> 0.01 </td> <td align="center"> 0.02 </td> <td align="center"> 0.05 </td> <td align="center"> 0.10 </td> <td align="center"> 0.21 </td> <td align="center"> 0.58 </td> <td align="center"> 1.39 </td> <td align="center"> 2.77 </td> <td align="center"> 4.61 </td> <td align="center"> 5.99 </td> <td align="center"> 7.38 </td> <td align="center"> 9.21 </td> <td align="center"> 10.60 </td> <td align="center"> 13.82 </td> </tr>
  <tr> <td align="center"> 3 </td> <td align="center"> 0.07 </td> <td align="center"> 0.11 </td> <td align="center"> 0.22 </td> <td align="center"> 0.35 </td> <td align="center"> 0.58 </td> <td align="center"> 1.21 </td> <td align="center"> 2.37 </td> <td align="center"> 4.11 </td> <td align="center"> 6.25 </td> <td align="center"> 7.81 </td> <td align="center"> 9.35 </td> <td align="center"> 11.34 </td> <td align="center"> 12.84 </td> <td align="center"> 16.27 </td> </tr>
  <tr> <td align="center"> 4 </td> <td align="center"> 0.21 </td> <td align="center"> 0.30 </td> <td align="center"> 0.48 </td> <td align="center"> 0.71 </td> <td align="center"> 1.06 </td> <td align="center"> 1.92 </td> <td align="center"> 3.36 </td> <td align="center"> 5.39 </td> <td align="center"> 7.78 </td> <td align="center"> 9.49 </td> <td align="center"> 11.14 </td> <td align="center"> 13.28 </td> <td align="center"> 14.86 </td> <td align="center"> 18.47 </td> </tr>
  <tr> <td align="center"> 5 </td> <td align="center"> 0.41 </td> <td align="center"> 0.55 </td> <td align="center"> 0.83 </td> <td align="center"> 1.15 </td> <td align="center"> 1.61 </td> <td align="center"> 2.67 </td> <td align="center"> 4.35 </td> <td align="center"> 6.63 </td> <td align="center"> 9.24 </td> <td align="center"> 11.07 </td> <td align="center"> 12.83 </td> <td align="center"> 15.09 </td> <td align="center"> 16.75 </td> <td align="center"> 20.52 </td> </tr>
  <tr> <td align="center"> 6 </td> <td align="center"> 0.68 </td> <td align="center"> 0.87 </td> <td align="center"> 1.24 </td> <td align="center"> 1.64 </td> <td align="center"> 2.20 </td> <td align="center"> 3.45 </td> <td align="center"> 5.35 </td> <td align="center"> 7.84 </td> <td align="center"> 10.64 </td> <td align="center"> 12.59 </td> <td align="center"> 14.45 </td> <td align="center"> 16.81 </td> <td align="center"> 18.55 </td> <td align="center"> 22.46 </td> </tr>
  <tr> <td align="center"> 7 </td> <td align="center"> 0.99 </td> <td align="center"> 1.24 </td> <td align="center"> 1.69 </td> <td align="center"> 2.17 </td> <td align="center"> 2.83 </td> <td align="center"> 4.25 </td> <td align="center"> 6.35 </td> <td align="center"> 9.04 </td> <td align="center"> 12.02 </td> <td align="center"> 14.07 </td> <td align="center"> 16.01 </td> <td align="center"> 18.48 </td> <td align="center"> 20.28 </td> <td align="center"> 24.32 </td> </tr>
  <tr> <td align="center"> 8 </td> <td align="center"> 1.34 </td> <td align="center"> 1.65 </td> <td align="center"> 2.18 </td> <td align="center"> 2.73 </td> <td align="center"> 3.49 </td> <td align="center"> 5.07 </td> <td align="center"> 7.34 </td> <td align="center"> 10.22 </td> <td align="center"> 13.36 </td> <td align="center"> 15.51 </td> <td align="center"> 17.53 </td> <td align="center"> 20.09 </td> <td align="center"> 21.95 </td> <td align="center"> 26.12 </td> </tr>
  <tr> <td align="center"> 9 </td> <td align="center"> 1.73 </td> <td align="center"> 2.09 </td> <td align="center"> 2.70 </td> <td align="center"> 3.33 </td> <td align="center"> 4.17 </td> <td align="center"> 5.90 </td> <td align="center"> 8.34 </td> <td align="center"> 11.39 </td> <td align="center"> 14.68 </td> <td align="center"> 16.92 </td> <td align="center"> 19.02 </td> <td align="center"> 21.67 </td> <td align="center"> 23.59 </td> <td align="center"> 27.88 </td> </tr>
  <tr> <td align="center"> 10 </td> <td align="center"> 2.16 </td> <td align="center"> 2.56 </td> <td align="center"> 3.25 </td> <td align="center"> 3.94 </td> <td align="center"> 4.87 </td> <td align="center"> 6.74 </td> <td align="center"> 9.34 </td> <td align="center"> 12.55 </td> <td align="center"> 15.99 </td> <td align="center"> 18.31 </td> <td align="center"> 20.48 </td> <td align="center"> 23.21 </td> <td align="center"> 25.19 </td> <td align="center"> 29.59 </td> </tr>
  <tr> <td align="center"> 11 </td> <td align="center"> 2.60 </td> <td align="center"> 3.05 </td> <td align="center"> 3.82 </td> <td align="center"> 4.57 </td> <td align="center"> 5.58 </td> <td align="center"> 7.58 </td> <td align="center"> 10.34 </td> <td align="center"> 13.70 </td> <td align="center"> 17.28 </td> <td align="center"> 19.68 </td> <td align="center"> 21.92 </td> <td align="center"> 24.72 </td> <td align="center"> 26.76 </td> <td align="center"> 31.26 </td> </tr>
  <tr> <td align="center"> 12 </td> <td align="center"> 3.07 </td> <td align="center"> 3.57 </td> <td align="center"> 4.40 </td> <td align="center"> 5.23 </td> <td align="center"> 6.30 </td> <td align="center"> 8.44 </td> <td align="center"> 11.34 </td> <td align="center"> 14.85 </td> <td align="center"> 18.55 </td> <td align="center"> 21.03 </td> <td align="center"> 23.34 </td> <td align="center"> 26.22 </td> <td align="center"> 28.30 </td> <td align="center"> 32.91 </td> </tr>
  <tr> <td align="center"> 13 </td> <td align="center"> 3.57 </td> <td align="center"> 4.11 </td> <td align="center"> 5.01 </td> <td align="center"> 5.89 </td> <td align="center"> 7.04 </td> <td align="center"> 9.30 </td> <td align="center"> 12.34 </td> <td align="center"> 15.98 </td> <td align="center"> 19.81 </td> <td align="center"> 22.36 </td> <td align="center"> 24.74 </td> <td align="center"> 27.69 </td> <td align="center"> 29.82 </td> <td align="center"> 34.53 </td> </tr>
  <tr> <td align="center"> 14 </td> <td align="center"> 4.07 </td> <td align="center"> 4.66 </td> <td align="center"> 5.63 </td> <td align="center"> 6.57 </td> <td align="center"> 7.79 </td> <td align="center"> 10.17 </td> <td align="center"> 13.34 </td> <td align="center"> 17.12 </td> <td align="center"> 21.06 </td> <td align="center"> 23.68 </td> <td align="center"> 26.12 </td> <td align="center"> 29.14 </td> <td align="center"> 31.32 </td> <td align="center"> 36.12 </td> </tr>
  <tr> <td align="center"> 15 </td> <td align="center"> 4.60 </td> <td align="center"> 5.23 </td> <td align="center"> 6.26 </td> <td align="center"> 7.26 </td> <td align="center"> 8.55 </td> <td align="center"> 11.04 </td> <td align="center"> 14.34 </td> <td align="center"> 18.25 </td> <td align="center"> 22.31 </td> <td align="center"> 25.00 </td> <td align="center"> 27.49 </td> <td align="center"> 30.58 </td> <td align="center"> 32.80 </td> <td align="center"> 37.70 </td> </tr>
  <tr> <td align="center"> 16 </td> <td align="center"> 5.14 </td> <td align="center"> 5.81 </td> <td align="center"> 6.91 </td> <td align="center"> 7.96 </td> <td align="center"> 9.31 </td> <td align="center"> 11.91 </td> <td align="center"> 15.34 </td> <td align="center"> 19.37 </td> <td align="center"> 23.54 </td> <td align="center"> 26.30 </td> <td align="center"> 28.85 </td> <td align="center"> 32.00 </td> <td align="center"> 34.27 </td> <td align="center"> 39.25 </td> </tr>
  <tr> <td align="center"> 17 </td> <td align="center"> 5.70 </td> <td align="center"> 6.41 </td> <td align="center"> 7.56 </td> <td align="center"> 8.67 </td> <td align="center"> 10.09 </td> <td align="center"> 12.79 </td> <td align="center"> 16.34 </td> <td align="center"> 20.49 </td> <td align="center"> 24.77 </td> <td align="center"> 27.59 </td> <td align="center"> 30.19 </td> <td align="center"> 33.41 </td> <td align="center"> 35.72 </td> <td align="center"> 40.79 </td> </tr>
  <tr> <td align="center"> 18 </td> <td align="center"> 6.26 </td> <td align="center"> 7.01 </td> <td align="center"> 8.23 </td> <td align="center"> 9.39 </td> <td align="center"> 10.86 </td> <td align="center"> 13.68 </td> <td align="center"> 17.34 </td> <td align="center"> 21.60 </td> <td align="center"> 25.99 </td> <td align="center"> 28.87 </td> <td align="center"> 31.53 </td> <td align="center"> 34.81 </td> <td align="center"> 37.16 </td> <td align="center"> 42.31 </td> </tr>
  <tr> <td align="center"> 19 </td> <td align="center"> 6.84 </td> <td align="center"> 7.63 </td> <td align="center"> 8.91 </td> <td align="center"> 10.12 </td> <td align="center"> 11.65 </td> <td align="center"> 14.56 </td> <td align="center"> 18.34 </td> <td align="center"> 22.72 </td> <td align="center"> 27.20 </td> <td align="center"> 30.14 </td> <td align="center"> 32.85 </td> <td align="center"> 36.19 </td> <td align="center"> 38.58 </td> <td align="center"> 43.82 </td> </tr>
  <tr> <td align="center"> 20 </td> <td align="center"> 7.43 </td> <td align="center"> 8.26 </td> <td align="center"> 9.59 </td> <td align="center"> 10.85 </td> <td align="center"> 12.44 </td> <td align="center"> 15.45 </td> <td align="center"> 19.34 </td> <td align="center"> 23.83 </td> <td align="center"> 28.41 </td> <td align="center"> 31.41 </td> <td align="center"> 34.17 </td> <td align="center"> 37.57 </td> <td align="center"> 40.00 </td> <td align="center"> 45.31 </td> </tr>
  <tr> <td align="center"> 21 </td> <td align="center"> 8.03 </td> <td align="center"> 8.90 </td> <td align="center"> 10.28 </td> <td align="center"> 11.59 </td> <td align="center"> 13.24 </td> <td align="center"> 16.34 </td> <td align="center"> 20.34 </td> <td align="center"> 24.93 </td> <td align="center"> 29.62 </td> <td align="center"> 32.67 </td> <td align="center"> 35.48 </td> <td align="center"> 38.93 </td> <td align="center"> 41.40 </td> <td align="center"> 46.80 </td> </tr>
  <tr> <td align="center"> 22 </td> <td align="center"> 8.64 </td> <td align="center"> 9.54 </td> <td align="center"> 10.98 </td> <td align="center"> 12.34 </td> <td align="center"> 14.04 </td> <td align="center"> 17.24 </td> <td align="center"> 21.34 </td> <td align="center"> 26.04 </td> <td align="center"> 30.81 </td> <td align="center"> 33.92 </td> <td align="center"> 36.78 </td> <td align="center"> 40.29 </td> <td align="center"> 42.80 </td> <td align="center"> 48.27 </td> </tr>
  <tr> <td align="center"> 23 </td> <td align="center"> 9.26 </td> <td align="center"> 10.20 </td> <td align="center"> 11.69 </td> <td align="center"> 13.09 </td> <td align="center"> 14.85 </td> <td align="center"> 18.14 </td> <td align="center"> 22.34 </td> <td align="center"> 27.14 </td> <td align="center"> 32.01 </td> <td align="center"> 35.17 </td> <td align="center"> 38.08 </td> <td align="center"> 41.64 </td> <td align="center"> 44.18 </td> <td align="center"> 49.73 </td> </tr>
  <tr> <td align="center"> 24 </td> <td align="center"> 9.89 </td> <td align="center"> 10.86 </td> <td align="center"> 12.40 </td> <td align="center"> 13.85 </td> <td align="center"> 15.66 </td> <td align="center"> 19.04 </td> <td align="center"> 23.34 </td> <td align="center"> 28.24 </td> <td align="center"> 33.20 </td> <td align="center"> 36.42 </td> <td align="center"> 39.36 </td> <td align="center"> 42.98 </td> <td align="center"> 45.56 </td> <td align="center"> 51.18 </td> </tr>
  <tr> <td align="center"> 25 </td> <td align="center"> 10.52 </td> <td align="center"> 11.52 </td> <td align="center"> 13.12 </td> <td align="center"> 14.61 </td> <td align="center"> 16.47 </td> <td align="center"> 19.94 </td> <td align="center"> 24.34 </td> <td align="center"> 29.34 </td> <td align="center"> 34.38 </td> <td align="center"> 37.65 </td> <td align="center"> 40.65 </td> <td align="center"> 44.31 </td> <td align="center"> 46.93 </td> <td align="center"> 52.62 </td> </tr>
  <tr> <td align="center"> 30 </td> <td align="center"> 13.79 </td> <td align="center"> 14.95 </td> <td align="center"> 16.79 </td> <td align="center"> 18.49 </td> <td align="center"> 20.60 </td> <td align="center"> 24.48 </td> <td align="center"> 29.34 </td> <td align="center"> 34.80 </td> <td align="center"> 40.26 </td> <td align="center"> 43.77 </td> <td align="center"> 46.98 </td> <td align="center"> 50.89 </td> <td align="center"> 53.67 </td> <td align="center"> 59.70 </td> </tr>
  <tr> <td align="center"> 40 </td> <td align="center"> 20.71 </td> <td align="center"> 22.16 </td> <td align="center"> 24.43 </td> <td align="center"> 26.51 </td> <td align="center"> 29.05 </td> <td align="center"> 33.66 </td> <td align="center"> 39.34 </td> <td align="center"> 45.62 </td> <td align="center"> 51.81 </td> <td align="center"> 55.76 </td> <td align="center"> 59.34 </td> <td align="center"> 63.69 </td> <td align="center"> 66.77 </td> <td align="center"> 73.40 </td> </tr>
  <tr> <td align="center"> 50 </td> <td align="center"> 27.99 </td> <td align="center"> 29.71 </td> <td align="center"> 32.36 </td> <td align="center"> 34.76 </td> <td align="center"> 37.69 </td> <td align="center"> 42.94 </td> <td align="center"> 49.33 </td> <td align="center"> 56.33 </td> <td align="center"> 63.17 </td> <td align="center"> 67.50 </td> <td align="center"> 71.42 </td> <td align="center"> 76.15 </td> <td align="center"> 79.49 </td> <td align="center"> 86.66 </td> </tr>
  <tr> <td align="center"> 60 </td> <td align="center"> 35.53 </td> <td align="center"> 37.48 </td> <td align="center"> 40.48 </td> <td align="center"> 43.19 </td> <td align="center"> 46.46 </td> <td align="center"> 52.29 </td> <td align="center"> 59.33 </td> <td align="center"> 66.98 </td> <td align="center"> 74.40 </td> <td align="center"> 79.08 </td> <td align="center"> 83.30 </td> <td align="center"> 88.38 </td> <td align="center"> 91.95 </td> <td align="center"> 99.61 </td> </tr>
  <tr> <td align="center"> 70 </td> <td align="center"> 43.28 </td> <td align="center"> 45.44 </td> <td align="center"> 48.76 </td> <td align="center"> 51.74 </td> <td align="center"> 55.33 </td> <td align="center"> 61.70 </td> <td align="center"> 69.33 </td> <td align="center"> 77.58 </td> <td align="center"> 85.53 </td> <td align="center"> 90.53 </td> <td align="center"> 95.02 </td> <td align="center"> 100.43 </td> <td align="center"> 104.21 </td> <td align="center"> 112.32 </td> </tr>
  <tr> <td align="center"> 80 </td> <td align="center"> 51.17 </td> <td align="center"> 53.54 </td> <td align="center"> 57.15 </td> <td align="center"> 60.39 </td> <td align="center"> 64.28 </td> <td align="center"> 71.14 </td> <td align="center"> 79.33 </td> <td align="center"> 88.13 </td> <td align="center"> 96.58 </td> <td align="center"> 101.88 </td> <td align="center"> 106.63 </td> <td align="center"> 112.33 </td> <td align="center"> 116.32 </td> <td align="center"> 124.84 </td> </tr>
  <tr> <td align="center"> 90 </td> <td align="center"> 59.20 </td> <td align="center"> 61.75 </td> <td align="center"> 65.65 </td> <td align="center"> 69.13 </td> <td align="center"> 73.29 </td> <td align="center"> 80.62 </td> <td align="center"> 89.33 </td> <td align="center"> 98.65 </td> <td align="center"> 107.57 </td> <td align="center"> 113.15 </td> <td align="center"> 118.14 </td> <td align="center"> 124.12 </td> <td align="center"> 128.30 </td> <td align="center"> 137.21 </td> </tr>
  <tr> <td align="center"> 100 </td> <td align="center"> 67.33 </td> <td align="center"> 70.06 </td> <td align="center"> 74.22 </td> <td align="center"> 77.93 </td> <td align="center"> 82.36 </td> <td align="center"> 90.13 </td> <td align="center"> 99.33 </td> <td align="center"> 109.14 </td> <td align="center"> 118.50 </td> <td align="center"> 124.34 </td> <td align="center"> 129.56 </td> <td align="center"> 135.81 </td> <td align="center"> 140.17 </td> <td align="center"> 149.45 </td> </tr>
   </table>
<h2 id="fv_1-v_2-text-distribution"><code>\(F(v_1, v_2) \text{ Distribution}\)</code></h2>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">x <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">seq</span>(<span style="color:#ae81ff">0</span>, <span style="color:#ae81ff">5</span>, <span style="color:#ae81ff">.01</span>)
v1 <span style="color:#f92672">&lt;-</span> <span style="color:#ae81ff">10</span>
v2 <span style="color:#f92672">&lt;-</span> <span style="color:#ae81ff">10</span>
<span style="color:#a6e22e">ggplot</span>() <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">geom_ribbon</span>(<span style="color:#a6e22e">aes</span>(x <span style="color:#f92672">=</span> <span style="color:#a6e22e">seq</span>(<span style="color:#a6e22e">qf</span>(<span style="color:#ae81ff">.95</span>, df1 <span style="color:#f92672">=</span> v1, df2 <span style="color:#f92672">=</span> v2), <span style="color:#a6e22e">max</span>(x), by <span style="color:#f92672">=</span> <span style="color:#ae81ff">.001</span>),
                  ymin <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>,
                  ymax <span style="color:#f92672">=</span> <span style="color:#a6e22e">df</span>(<span style="color:#a6e22e">seq</span>(<span style="color:#a6e22e">qf</span>(<span style="color:#ae81ff">.95</span>, df1 <span style="color:#f92672">=</span> v1, df2 <span style="color:#f92672">=</span> v2), <span style="color:#a6e22e">max</span>(x), by <span style="color:#f92672">=</span> <span style="color:#ae81ff">.001</span>),
                                df1 <span style="color:#f92672">=</span> v1, df2 <span style="color:#f92672">=</span> v2)
                  ),
              fill <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;gray&#39;</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">geom_vline</span>(xintercept <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>, color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;black&#34;</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">geom_hline</span>(yintercept <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>, color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;black&#34;</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">stat_function</span>(data <span style="color:#f92672">=</span> <span style="color:#a6e22e">data.frame</span>(x<span style="color:#f92672">=</span>x),<span style="color:#a6e22e">aes</span>(x <span style="color:#f92672">=</span> x),  
                fun <span style="color:#f92672">=</span> df, 
                args <span style="color:#f92672">=</span> <span style="color:#a6e22e">list</span>(df1 <span style="color:#f92672">=</span> v1, df2 <span style="color:#f92672">=</span> v2),
                size <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">geom_segment</span>(<span style="color:#a6e22e">aes</span>(x <span style="color:#f92672">=</span> <span style="color:#a6e22e">qf</span>(<span style="color:#ae81ff">.95</span>, df1 <span style="color:#f92672">=</span> v1, df2 <span style="color:#f92672">=</span> v2),
                   y <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>,
                   xend <span style="color:#f92672">=</span> <span style="color:#a6e22e">qf</span>(<span style="color:#ae81ff">.95</span>, df1 <span style="color:#f92672">=</span> v1, df2 <span style="color:#f92672">=</span> v2),
                   yend <span style="color:#f92672">=</span> <span style="color:#a6e22e">df</span>(<span style="color:#a6e22e">qf</span>(<span style="color:#ae81ff">.95</span>, df1 <span style="color:#f92672">=</span> v1, df2 <span style="color:#f92672">=</span> v2), df1 <span style="color:#f92672">=</span> v1, df2 <span style="color:#f92672">=</span> v2)
  ),
  
  color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;black&#39;</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">theme_void</span>() <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">theme</span>(plot.margin <span style="color:#f92672">=</span> <span style="color:#a6e22e">unit</span>(<span style="color:#a6e22e">c</span>(<span style="color:#ae81ff">.1</span>,<span style="color:#ae81ff">.1</span>,<span style="color:#ae81ff">.1</span>,<span style="color:#ae81ff">.1</span>), <span style="color:#e6db74">&#34;cm&#34;</span>)) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">annotate</span>(geom <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;text&#39;</span>,
           x <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#a6e22e">qf</span>(<span style="color:#ae81ff">.95</span>, df1 <span style="color:#f92672">=</span> v1, df2 <span style="color:#f92672">=</span> v2)),
           y <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#ae81ff">-.07</span>),
           label <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#a6e22e">expression</span>(<span style="color:#a6e22e">F</span>(<span style="color:#a6e22e">paste</span>(v1,<span style="color:#e6db74">&#39;,&#39;</span>,v2)))),
           size <span style="color:#f92672">=</span> <span style="color:#ae81ff">4</span>,
           parse <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">coord_cartesian</span>(ylim <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#ae81ff">-.07</span>, <span style="color:#a6e22e">df</span>(<span style="color:#a6e22e">qf</span>(<span style="color:#ae81ff">.25</span>, df1 <span style="color:#f92672">=</span> v1, df2 <span style="color:#f92672">=</span> v2), df1 <span style="color:#f92672">=</span> v1, df2 <span style="color:#f92672">=</span> v2)))
</code></pre></div><p><img src="https://roh.engineering/posts/2018/03/building-distribution-reference-tables-in-r/index_files/figure-html/unnamed-chunk-8-1.png" width="192" /></p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r">v1 <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">c</span>(<span style="color:#a6e22e">seq</span>(<span style="color:#ae81ff">1</span>, <span style="color:#ae81ff">10</span>, by <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>), <span style="color:#ae81ff">12</span>, <span style="color:#ae81ff">15</span>, <span style="color:#ae81ff">20</span>, <span style="color:#ae81ff">24</span>, <span style="color:#ae81ff">30</span>, <span style="color:#ae81ff">40</span>, <span style="color:#ae81ff">60</span>, <span style="color:#ae81ff">120</span>, <span style="color:#66d9ef">Inf</span>)
v2 <span style="color:#f92672">&lt;-</span> v1
fTable95 <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">sapply</span>(v1, <span style="color:#a6e22e">function</span>(x) <span style="color:#a6e22e">round</span>(<span style="color:#a6e22e">qf</span>(<span style="color:#ae81ff">.95</span>, x, v2), <span style="color:#ae81ff">2</span>))
<span style="color:#a6e22e">colnames</span>(fTable95) <span style="color:#f92672">&lt;-</span> v1
<span style="color:#a6e22e">colnames</span>(fTable95)<span style="color:#a6e22e">[colnames</span>(fTable95) <span style="color:#f92672">==</span> <span style="color:#e6db74">&#39;Inf&#39;</span>] <span style="color:#f92672">&lt;-</span> <span style="color:#e6db74">&#34;$\\infty$&#34;</span>
fTable95 <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">data.frame</span>(<span style="color:#e6db74">&#34;$v_2 \\big\\backslash v_1$&#34;</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">paste0</span>(<span style="color:#e6db74">&#34;&#34;</span>, v2, <span style="color:#e6db74">&#34;&#34;</span>),
                       fTable95,
                       stringsAsFactors <span style="color:#f92672">=</span> <span style="color:#66d9ef">FALSE</span>,
                       check.names <span style="color:#f92672">=</span> <span style="color:#66d9ef">FALSE</span>)
fTable95[[1]][fTable95[[1]] <span style="color:#f92672">==</span> <span style="color:#e6db74">&#34;Inf&#34;</span>] <span style="color:#f92672">&lt;-</span> <span style="color:#e6db74">&#34;$\\infty$&#34;</span>                        
fTable95 <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">xtable</span>(fTable95,
                      caption <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;Table 5: 95th Percentiles of the $F(v_1,v_2)$&#34;</span>,
                      align <span style="color:#f92672">=</span> <span style="color:#a6e22e">rep</span>(<span style="color:#e6db74">&#34;c&#34;</span>, <span style="color:#a6e22e">ncol</span>(fTable95)<span style="color:#ae81ff">+1</span>))

<span style="color:#a6e22e">print</span>(fTable95)
</code></pre></div><!-- html table generated in R 4.0.3 by xtable 1.8-4 package -->
<!-- Wed Feb 17 21:01:48 2021 -->
<table border='2' cellpadding='15' cellpadding='5' rules ='all' width ='100%'>
<caption align="top"> Table 5: 95th Percentiles of the `\(F(v_1,v_2)\)` </caption>
<tr> <th> `\(v_2 \big\backslash v_1\)` </th> <th> 1 </th> <th> 2 </th> <th> 3 </th> <th> 4 </th> <th> 5 </th> <th> 6 </th> <th> 7 </th> <th> 8 </th> <th> 9 </th> <th> 10 </th> <th> 12 </th> <th> 15 </th> <th> 20 </th> <th> 24 </th> <th> 30 </th> <th> 40 </th> <th> 60 </th> <th> 120 </th> <th> `\(\infty\)` </th>  </tr>
  <tr> <td align="center"> 1 </td> <td align="center"> 161.45 </td> <td align="center"> 199.50 </td> <td align="center"> 215.71 </td> <td align="center"> 224.58 </td> <td align="center"> 230.16 </td> <td align="center"> 233.99 </td> <td align="center"> 236.77 </td> <td align="center"> 238.88 </td> <td align="center"> 240.54 </td> <td align="center"> 241.88 </td> <td align="center"> 243.91 </td> <td align="center"> 245.95 </td> <td align="center"> 248.01 </td> <td align="center"> 249.05 </td> <td align="center"> 250.10 </td> <td align="center"> 251.14 </td> <td align="center"> 252.20 </td> <td align="center"> 253.25 </td> <td align="center"> 254.31 </td> </tr>
  <tr> <td align="center"> 2 </td> <td align="center"> 18.51 </td> <td align="center"> 19.00 </td> <td align="center"> 19.16 </td> <td align="center"> 19.25 </td> <td align="center"> 19.30 </td> <td align="center"> 19.33 </td> <td align="center"> 19.35 </td> <td align="center"> 19.37 </td> <td align="center"> 19.38 </td> <td align="center"> 19.40 </td> <td align="center"> 19.41 </td> <td align="center"> 19.43 </td> <td align="center"> 19.45 </td> <td align="center"> 19.45 </td> <td align="center"> 19.46 </td> <td align="center"> 19.47 </td> <td align="center"> 19.48 </td> <td align="center"> 19.49 </td> <td align="center"> 19.50 </td> </tr>
  <tr> <td align="center"> 3 </td> <td align="center"> 10.13 </td> <td align="center"> 9.55 </td> <td align="center"> 9.28 </td> <td align="center"> 9.12 </td> <td align="center"> 9.01 </td> <td align="center"> 8.94 </td> <td align="center"> 8.89 </td> <td align="center"> 8.85 </td> <td align="center"> 8.81 </td> <td align="center"> 8.79 </td> <td align="center"> 8.74 </td> <td align="center"> 8.70 </td> <td align="center"> 8.66 </td> <td align="center"> 8.64 </td> <td align="center"> 8.62 </td> <td align="center"> 8.59 </td> <td align="center"> 8.57 </td> <td align="center"> 8.55 </td> <td align="center"> 8.53 </td> </tr>
  <tr> <td align="center"> 4 </td> <td align="center"> 7.71 </td> <td align="center"> 6.94 </td> <td align="center"> 6.59 </td> <td align="center"> 6.39 </td> <td align="center"> 6.26 </td> <td align="center"> 6.16 </td> <td align="center"> 6.09 </td> <td align="center"> 6.04 </td> <td align="center"> 6.00 </td> <td align="center"> 5.96 </td> <td align="center"> 5.91 </td> <td align="center"> 5.86 </td> <td align="center"> 5.80 </td> <td align="center"> 5.77 </td> <td align="center"> 5.75 </td> <td align="center"> 5.72 </td> <td align="center"> 5.69 </td> <td align="center"> 5.66 </td> <td align="center"> 5.63 </td> </tr>
  <tr> <td align="center"> 5 </td> <td align="center"> 6.61 </td> <td align="center"> 5.79 </td> <td align="center"> 5.41 </td> <td align="center"> 5.19 </td> <td align="center"> 5.05 </td> <td align="center"> 4.95 </td> <td align="center"> 4.88 </td> <td align="center"> 4.82 </td> <td align="center"> 4.77 </td> <td align="center"> 4.74 </td> <td align="center"> 4.68 </td> <td align="center"> 4.62 </td> <td align="center"> 4.56 </td> <td align="center"> 4.53 </td> <td align="center"> 4.50 </td> <td align="center"> 4.46 </td> <td align="center"> 4.43 </td> <td align="center"> 4.40 </td> <td align="center"> 4.36 </td> </tr>
  <tr> <td align="center"> 6 </td> <td align="center"> 5.99 </td> <td align="center"> 5.14 </td> <td align="center"> 4.76 </td> <td align="center"> 4.53 </td> <td align="center"> 4.39 </td> <td align="center"> 4.28 </td> <td align="center"> 4.21 </td> <td align="center"> 4.15 </td> <td align="center"> 4.10 </td> <td align="center"> 4.06 </td> <td align="center"> 4.00 </td> <td align="center"> 3.94 </td> <td align="center"> 3.87 </td> <td align="center"> 3.84 </td> <td align="center"> 3.81 </td> <td align="center"> 3.77 </td> <td align="center"> 3.74 </td> <td align="center"> 3.70 </td> <td align="center"> 3.67 </td> </tr>
  <tr> <td align="center"> 7 </td> <td align="center"> 5.59 </td> <td align="center"> 4.74 </td> <td align="center"> 4.35 </td> <td align="center"> 4.12 </td> <td align="center"> 3.97 </td> <td align="center"> 3.87 </td> <td align="center"> 3.79 </td> <td align="center"> 3.73 </td> <td align="center"> 3.68 </td> <td align="center"> 3.64 </td> <td align="center"> 3.57 </td> <td align="center"> 3.51 </td> <td align="center"> 3.44 </td> <td align="center"> 3.41 </td> <td align="center"> 3.38 </td> <td align="center"> 3.34 </td> <td align="center"> 3.30 </td> <td align="center"> 3.27 </td> <td align="center"> 3.23 </td> </tr>
  <tr> <td align="center"> 8 </td> <td align="center"> 5.32 </td> <td align="center"> 4.46 </td> <td align="center"> 4.07 </td> <td align="center"> 3.84 </td> <td align="center"> 3.69 </td> <td align="center"> 3.58 </td> <td align="center"> 3.50 </td> <td align="center"> 3.44 </td> <td align="center"> 3.39 </td> <td align="center"> 3.35 </td> <td align="center"> 3.28 </td> <td align="center"> 3.22 </td> <td align="center"> 3.15 </td> <td align="center"> 3.12 </td> <td align="center"> 3.08 </td> <td align="center"> 3.04 </td> <td align="center"> 3.01 </td> <td align="center"> 2.97 </td> <td align="center"> 2.93 </td> </tr>
  <tr> <td align="center"> 9 </td> <td align="center"> 5.12 </td> <td align="center"> 4.26 </td> <td align="center"> 3.86 </td> <td align="center"> 3.63 </td> <td align="center"> 3.48 </td> <td align="center"> 3.37 </td> <td align="center"> 3.29 </td> <td align="center"> 3.23 </td> <td align="center"> 3.18 </td> <td align="center"> 3.14 </td> <td align="center"> 3.07 </td> <td align="center"> 3.01 </td> <td align="center"> 2.94 </td> <td align="center"> 2.90 </td> <td align="center"> 2.86 </td> <td align="center"> 2.83 </td> <td align="center"> 2.79 </td> <td align="center"> 2.75 </td> <td align="center"> 2.71 </td> </tr>
  <tr> <td align="center"> 10 </td> <td align="center"> 4.96 </td> <td align="center"> 4.10 </td> <td align="center"> 3.71 </td> <td align="center"> 3.48 </td> <td align="center"> 3.33 </td> <td align="center"> 3.22 </td> <td align="center"> 3.14 </td> <td align="center"> 3.07 </td> <td align="center"> 3.02 </td> <td align="center"> 2.98 </td> <td align="center"> 2.91 </td> <td align="center"> 2.85 </td> <td align="center"> 2.77 </td> <td align="center"> 2.74 </td> <td align="center"> 2.70 </td> <td align="center"> 2.66 </td> <td align="center"> 2.62 </td> <td align="center"> 2.58 </td> <td align="center"> 2.54 </td> </tr>
  <tr> <td align="center"> 12 </td> <td align="center"> 4.75 </td> <td align="center"> 3.89 </td> <td align="center"> 3.49 </td> <td align="center"> 3.26 </td> <td align="center"> 3.11 </td> <td align="center"> 3.00 </td> <td align="center"> 2.91 </td> <td align="center"> 2.85 </td> <td align="center"> 2.80 </td> <td align="center"> 2.75 </td> <td align="center"> 2.69 </td> <td align="center"> 2.62 </td> <td align="center"> 2.54 </td> <td align="center"> 2.51 </td> <td align="center"> 2.47 </td> <td align="center"> 2.43 </td> <td align="center"> 2.38 </td> <td align="center"> 2.34 </td> <td align="center"> 2.30 </td> </tr>
  <tr> <td align="center"> 15 </td> <td align="center"> 4.54 </td> <td align="center"> 3.68 </td> <td align="center"> 3.29 </td> <td align="center"> 3.06 </td> <td align="center"> 2.90 </td> <td align="center"> 2.79 </td> <td align="center"> 2.71 </td> <td align="center"> 2.64 </td> <td align="center"> 2.59 </td> <td align="center"> 2.54 </td> <td align="center"> 2.48 </td> <td align="center"> 2.40 </td> <td align="center"> 2.33 </td> <td align="center"> 2.29 </td> <td align="center"> 2.25 </td> <td align="center"> 2.20 </td> <td align="center"> 2.16 </td> <td align="center"> 2.11 </td> <td align="center"> 2.07 </td> </tr>
  <tr> <td align="center"> 20 </td> <td align="center"> 4.35 </td> <td align="center"> 3.49 </td> <td align="center"> 3.10 </td> <td align="center"> 2.87 </td> <td align="center"> 2.71 </td> <td align="center"> 2.60 </td> <td align="center"> 2.51 </td> <td align="center"> 2.45 </td> <td align="center"> 2.39 </td> <td align="center"> 2.35 </td> <td align="center"> 2.28 </td> <td align="center"> 2.20 </td> <td align="center"> 2.12 </td> <td align="center"> 2.08 </td> <td align="center"> 2.04 </td> <td align="center"> 1.99 </td> <td align="center"> 1.95 </td> <td align="center"> 1.90 </td> <td align="center"> 1.84 </td> </tr>
  <tr> <td align="center"> 24 </td> <td align="center"> 4.26 </td> <td align="center"> 3.40 </td> <td align="center"> 3.01 </td> <td align="center"> 2.78 </td> <td align="center"> 2.62 </td> <td align="center"> 2.51 </td> <td align="center"> 2.42 </td> <td align="center"> 2.36 </td> <td align="center"> 2.30 </td> <td align="center"> 2.25 </td> <td align="center"> 2.18 </td> <td align="center"> 2.11 </td> <td align="center"> 2.03 </td> <td align="center"> 1.98 </td> <td align="center"> 1.94 </td> <td align="center"> 1.89 </td> <td align="center"> 1.84 </td> <td align="center"> 1.79 </td> <td align="center"> 1.73 </td> </tr>
  <tr> <td align="center"> 30 </td> <td align="center"> 4.17 </td> <td align="center"> 3.32 </td> <td align="center"> 2.92 </td> <td align="center"> 2.69 </td> <td align="center"> 2.53 </td> <td align="center"> 2.42 </td> <td align="center"> 2.33 </td> <td align="center"> 2.27 </td> <td align="center"> 2.21 </td> <td align="center"> 2.16 </td> <td align="center"> 2.09 </td> <td align="center"> 2.01 </td> <td align="center"> 1.93 </td> <td align="center"> 1.89 </td> <td align="center"> 1.84 </td> <td align="center"> 1.79 </td> <td align="center"> 1.74 </td> <td align="center"> 1.68 </td> <td align="center"> 1.62 </td> </tr>
  <tr> <td align="center"> 40 </td> <td align="center"> 4.08 </td> <td align="center"> 3.23 </td> <td align="center"> 2.84 </td> <td align="center"> 2.61 </td> <td align="center"> 2.45 </td> <td align="center"> 2.34 </td> <td align="center"> 2.25 </td> <td align="center"> 2.18 </td> <td align="center"> 2.12 </td> <td align="center"> 2.08 </td> <td align="center"> 2.00 </td> <td align="center"> 1.92 </td> <td align="center"> 1.84 </td> <td align="center"> 1.79 </td> <td align="center"> 1.74 </td> <td align="center"> 1.69 </td> <td align="center"> 1.64 </td> <td align="center"> 1.58 </td> <td align="center"> 1.51 </td> </tr>
  <tr> <td align="center"> 60 </td> <td align="center"> 4.00 </td> <td align="center"> 3.15 </td> <td align="center"> 2.76 </td> <td align="center"> 2.53 </td> <td align="center"> 2.37 </td> <td align="center"> 2.25 </td> <td align="center"> 2.17 </td> <td align="center"> 2.10 </td> <td align="center"> 2.04 </td> <td align="center"> 1.99 </td> <td align="center"> 1.92 </td> <td align="center"> 1.84 </td> <td align="center"> 1.75 </td> <td align="center"> 1.70 </td> <td align="center"> 1.65 </td> <td align="center"> 1.59 </td> <td align="center"> 1.53 </td> <td align="center"> 1.47 </td> <td align="center"> 1.39 </td> </tr>
  <tr> <td align="center"> 120 </td> <td align="center"> 3.92 </td> <td align="center"> 3.07 </td> <td align="center"> 2.68 </td> <td align="center"> 2.45 </td> <td align="center"> 2.29 </td> <td align="center"> 2.18 </td> <td align="center"> 2.09 </td> <td align="center"> 2.02 </td> <td align="center"> 1.96 </td> <td align="center"> 1.91 </td> <td align="center"> 1.83 </td> <td align="center"> 1.75 </td> <td align="center"> 1.66 </td> <td align="center"> 1.61 </td> <td align="center"> 1.55 </td> <td align="center"> 1.50 </td> <td align="center"> 1.43 </td> <td align="center"> 1.35 </td> <td align="center"> 1.25 </td> </tr>
  <tr> <td align="center"> `\(\infty\)` </td> <td align="center"> 3.84 </td> <td align="center"> 3.00 </td> <td align="center"> 2.60 </td> <td align="center"> 2.37 </td> <td align="center"> 2.21 </td> <td align="center"> 2.10 </td> <td align="center"> 2.01 </td> <td align="center"> 1.94 </td> <td align="center"> 1.88 </td> <td align="center"> 1.83 </td> <td align="center"> 1.75 </td> <td align="center"> 1.67 </td> <td align="center"> 1.57 </td> <td align="center"> 1.52 </td> <td align="center"> 1.46 </td> <td align="center"> 1.39 </td> <td align="center"> 1.32 </td> <td align="center"> 1.22 </td> <td align="center"> 1.00 </td> </tr>
   </table>
]]></description>
        </item>
        
        <item>
            <title>Statistical Distribution Tables</title>
            <link>https://roh.engineering/posts/2018/03/statistical-distribution-tables/</link>
            <pubDate>Sat, 10 Mar 2018 00:00:00 +0000</pubDate>
            
            <guid>https://roh.engineering/posts/2018/03/statistical-distribution-tables/</guid>
            <description><![CDATA[<h2 id="textnormal-distribution"><code>\(\text{Normal Distribution}\)</code></h2>
<p><img src="https://roh.engineering/posts/2018/03/statistical-distribution-tables/index_files/figure-html/unnamed-chunk-1-1.png" width="192" style="display: block; margin: auto;" /></p>
<h5 id="texttable-2-cumulative-probabilities-of-the-standard-normal-distribution--x-sim-n01"><code>$\text{Table 2: Cumulative Probabilities of the Standard Normal Distribution, } X \sim N(0,1)$</code></h5>
<table>
<thead>
<tr>
<th style="text-align:left">z</th>
<th style="text-align:right">0</th>
<th style="text-align:right">0.01</th>
<th style="text-align:right">0.02</th>
<th style="text-align:right">0.03</th>
<th style="text-align:right">0.04</th>
<th style="text-align:right">0.05</th>
<th style="text-align:right">0.06</th>
<th style="text-align:right">0.07</th>
<th style="text-align:right">0.08</th>
<th style="text-align:right">0.09</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"><strong>0.0</strong></td>
<td style="text-align:right">0.5000</td>
<td style="text-align:right">0.5040</td>
<td style="text-align:right">0.5080</td>
<td style="text-align:right">0.5120</td>
<td style="text-align:right">0.5160</td>
<td style="text-align:right">0.5199</td>
<td style="text-align:right">0.5239</td>
<td style="text-align:right">0.5279</td>
<td style="text-align:right">0.5319</td>
<td style="text-align:right">0.5359</td>
</tr>
<tr>
<td style="text-align:left"><strong>0.1</strong></td>
<td style="text-align:right">0.5398</td>
<td style="text-align:right">0.5438</td>
<td style="text-align:right">0.5478</td>
<td style="text-align:right">0.5517</td>
<td style="text-align:right">0.5557</td>
<td style="text-align:right">0.5596</td>
<td style="text-align:right">0.5636</td>
<td style="text-align:right">0.5675</td>
<td style="text-align:right">0.5714</td>
<td style="text-align:right">0.5753</td>
</tr>
<tr>
<td style="text-align:left"><strong>0.2</strong></td>
<td style="text-align:right">0.5793</td>
<td style="text-align:right">0.5832</td>
<td style="text-align:right">0.5871</td>
<td style="text-align:right">0.5910</td>
<td style="text-align:right">0.5948</td>
<td style="text-align:right">0.5987</td>
<td style="text-align:right">0.6026</td>
<td style="text-align:right">0.6064</td>
<td style="text-align:right">0.6103</td>
<td style="text-align:right">0.6141</td>
</tr>
<tr>
<td style="text-align:left"><strong>0.3</strong></td>
<td style="text-align:right">0.6179</td>
<td style="text-align:right">0.6217</td>
<td style="text-align:right">0.6255</td>
<td style="text-align:right">0.6293</td>
<td style="text-align:right">0.6331</td>
<td style="text-align:right">0.6368</td>
<td style="text-align:right">0.6406</td>
<td style="text-align:right">0.6443</td>
<td style="text-align:right">0.6480</td>
<td style="text-align:right">0.6517</td>
</tr>
<tr>
<td style="text-align:left"><strong>0.4</strong></td>
<td style="text-align:right">0.6554</td>
<td style="text-align:right">0.6591</td>
<td style="text-align:right">0.6628</td>
<td style="text-align:right">0.6664</td>
<td style="text-align:right">0.6700</td>
<td style="text-align:right">0.6736</td>
<td style="text-align:right">0.6772</td>
<td style="text-align:right">0.6808</td>
<td style="text-align:right">0.6844</td>
<td style="text-align:right">0.6879</td>
</tr>
<tr>
<td style="text-align:left"><strong>0.5</strong></td>
<td style="text-align:right">0.6915</td>
<td style="text-align:right">0.6950</td>
<td style="text-align:right">0.6985</td>
<td style="text-align:right">0.7019</td>
<td style="text-align:right">0.7054</td>
<td style="text-align:right">0.7088</td>
<td style="text-align:right">0.7123</td>
<td style="text-align:right">0.7157</td>
<td style="text-align:right">0.7190</td>
<td style="text-align:right">0.7224</td>
</tr>
<tr>
<td style="text-align:left"><strong>0.6</strong></td>
<td style="text-align:right">0.7257</td>
<td style="text-align:right">0.7291</td>
<td style="text-align:right">0.7324</td>
<td style="text-align:right">0.7357</td>
<td style="text-align:right">0.7389</td>
<td style="text-align:right">0.7422</td>
<td style="text-align:right">0.7454</td>
<td style="text-align:right">0.7486</td>
<td style="text-align:right">0.7517</td>
<td style="text-align:right">0.7549</td>
</tr>
<tr>
<td style="text-align:left"><strong>0.7</strong></td>
<td style="text-align:right">0.7580</td>
<td style="text-align:right">0.7611</td>
<td style="text-align:right">0.7642</td>
<td style="text-align:right">0.7673</td>
<td style="text-align:right">0.7704</td>
<td style="text-align:right">0.7734</td>
<td style="text-align:right">0.7764</td>
<td style="text-align:right">0.7794</td>
<td style="text-align:right">0.7823</td>
<td style="text-align:right">0.7852</td>
</tr>
<tr>
<td style="text-align:left"><strong>0.8</strong></td>
<td style="text-align:right">0.7881</td>
<td style="text-align:right">0.7910</td>
<td style="text-align:right">0.7939</td>
<td style="text-align:right">0.7967</td>
<td style="text-align:right">0.7995</td>
<td style="text-align:right">0.8023</td>
<td style="text-align:right">0.8051</td>
<td style="text-align:right">0.8078</td>
<td style="text-align:right">0.8106</td>
<td style="text-align:right">0.8133</td>
</tr>
<tr>
<td style="text-align:left"><strong>0.9</strong></td>
<td style="text-align:right">0.8159</td>
<td style="text-align:right">0.8186</td>
<td style="text-align:right">0.8212</td>
<td style="text-align:right">0.8238</td>
<td style="text-align:right">0.8264</td>
<td style="text-align:right">0.8289</td>
<td style="text-align:right">0.8315</td>
<td style="text-align:right">0.8340</td>
<td style="text-align:right">0.8365</td>
<td style="text-align:right">0.8389</td>
</tr>
<tr>
<td style="text-align:left"><strong>1.0</strong></td>
<td style="text-align:right">0.8413</td>
<td style="text-align:right">0.8438</td>
<td style="text-align:right">0.8461</td>
<td style="text-align:right">0.8485</td>
<td style="text-align:right">0.8508</td>
<td style="text-align:right">0.8531</td>
<td style="text-align:right">0.8554</td>
<td style="text-align:right">0.8577</td>
<td style="text-align:right">0.8599</td>
<td style="text-align:right">0.8621</td>
</tr>
<tr>
<td style="text-align:left"><strong>1.1</strong></td>
<td style="text-align:right">0.8643</td>
<td style="text-align:right">0.8665</td>
<td style="text-align:right">0.8686</td>
<td style="text-align:right">0.8708</td>
<td style="text-align:right">0.8729</td>
<td style="text-align:right">0.8749</td>
<td style="text-align:right">0.8770</td>
<td style="text-align:right">0.8790</td>
<td style="text-align:right">0.8810</td>
<td style="text-align:right">0.8830</td>
</tr>
<tr>
<td style="text-align:left"><strong>1.2</strong></td>
<td style="text-align:right">0.8849</td>
<td style="text-align:right">0.8869</td>
<td style="text-align:right">0.8888</td>
<td style="text-align:right">0.8907</td>
<td style="text-align:right">0.8925</td>
<td style="text-align:right">0.8944</td>
<td style="text-align:right">0.8962</td>
<td style="text-align:right">0.8980</td>
<td style="text-align:right">0.8997</td>
<td style="text-align:right">0.9015</td>
</tr>
<tr>
<td style="text-align:left"><strong>1.3</strong></td>
<td style="text-align:right">0.9032</td>
<td style="text-align:right">0.9049</td>
<td style="text-align:right">0.9066</td>
<td style="text-align:right">0.9082</td>
<td style="text-align:right">0.9099</td>
<td style="text-align:right">0.9115</td>
<td style="text-align:right">0.9131</td>
<td style="text-align:right">0.9147</td>
<td style="text-align:right">0.9162</td>
<td style="text-align:right">0.9177</td>
</tr>
<tr>
<td style="text-align:left"><strong>1.4</strong></td>
<td style="text-align:right">0.9192</td>
<td style="text-align:right">0.9207</td>
<td style="text-align:right">0.9222</td>
<td style="text-align:right">0.9236</td>
<td style="text-align:right">0.9251</td>
<td style="text-align:right">0.9265</td>
<td style="text-align:right">0.9279</td>
<td style="text-align:right">0.9292</td>
<td style="text-align:right">0.9306</td>
<td style="text-align:right">0.9319</td>
</tr>
<tr>
<td style="text-align:left"><strong>1.5</strong></td>
<td style="text-align:right">0.9332</td>
<td style="text-align:right">0.9345</td>
<td style="text-align:right">0.9357</td>
<td style="text-align:right">0.9370</td>
<td style="text-align:right">0.9382</td>
<td style="text-align:right">0.9394</td>
<td style="text-align:right">0.9406</td>
<td style="text-align:right">0.9418</td>
<td style="text-align:right">0.9429</td>
<td style="text-align:right">0.9441</td>
</tr>
<tr>
<td style="text-align:left"><strong>1.6</strong></td>
<td style="text-align:right">0.9452</td>
<td style="text-align:right">0.9463</td>
<td style="text-align:right">0.9474</td>
<td style="text-align:right">0.9484</td>
<td style="text-align:right">0.9495</td>
<td style="text-align:right">0.9505</td>
<td style="text-align:right">0.9515</td>
<td style="text-align:right">0.9525</td>
<td style="text-align:right">0.9535</td>
<td style="text-align:right">0.9545</td>
</tr>
<tr>
<td style="text-align:left"><strong>1.7</strong></td>
<td style="text-align:right">0.9554</td>
<td style="text-align:right">0.9564</td>
<td style="text-align:right">0.9573</td>
<td style="text-align:right">0.9582</td>
<td style="text-align:right">0.9591</td>
<td style="text-align:right">0.9599</td>
<td style="text-align:right">0.9608</td>
<td style="text-align:right">0.9616</td>
<td style="text-align:right">0.9625</td>
<td style="text-align:right">0.9633</td>
</tr>
<tr>
<td style="text-align:left"><strong>1.8</strong></td>
<td style="text-align:right">0.9641</td>
<td style="text-align:right">0.9649</td>
<td style="text-align:right">0.9656</td>
<td style="text-align:right">0.9664</td>
<td style="text-align:right">0.9671</td>
<td style="text-align:right">0.9678</td>
<td style="text-align:right">0.9686</td>
<td style="text-align:right">0.9693</td>
<td style="text-align:right">0.9699</td>
<td style="text-align:right">0.9706</td>
</tr>
<tr>
<td style="text-align:left"><strong>1.9</strong></td>
<td style="text-align:right">0.9713</td>
<td style="text-align:right">0.9719</td>
<td style="text-align:right">0.9726</td>
<td style="text-align:right">0.9732</td>
<td style="text-align:right">0.9738</td>
<td style="text-align:right">0.9744</td>
<td style="text-align:right">0.9750</td>
<td style="text-align:right">0.9756</td>
<td style="text-align:right">0.9761</td>
<td style="text-align:right">0.9767</td>
</tr>
<tr>
<td style="text-align:left"><strong>2.0</strong></td>
<td style="text-align:right">0.9772</td>
<td style="text-align:right">0.9778</td>
<td style="text-align:right">0.9783</td>
<td style="text-align:right">0.9788</td>
<td style="text-align:right">0.9793</td>
<td style="text-align:right">0.9798</td>
<td style="text-align:right">0.9803</td>
<td style="text-align:right">0.9808</td>
<td style="text-align:right">0.9812</td>
<td style="text-align:right">0.9817</td>
</tr>
<tr>
<td style="text-align:left"><strong>2.1</strong></td>
<td style="text-align:right">0.9821</td>
<td style="text-align:right">0.9826</td>
<td style="text-align:right">0.9830</td>
<td style="text-align:right">0.9834</td>
<td style="text-align:right">0.9838</td>
<td style="text-align:right">0.9842</td>
<td style="text-align:right">0.9846</td>
<td style="text-align:right">0.9850</td>
<td style="text-align:right">0.9854</td>
<td style="text-align:right">0.9857</td>
</tr>
<tr>
<td style="text-align:left"><strong>2.2</strong></td>
<td style="text-align:right">0.9861</td>
<td style="text-align:right">0.9864</td>
<td style="text-align:right">0.9868</td>
<td style="text-align:right">0.9871</td>
<td style="text-align:right">0.9875</td>
<td style="text-align:right">0.9878</td>
<td style="text-align:right">0.9881</td>
<td style="text-align:right">0.9884</td>
<td style="text-align:right">0.9887</td>
<td style="text-align:right">0.9890</td>
</tr>
<tr>
<td style="text-align:left"><strong>2.3</strong></td>
<td style="text-align:right">0.9893</td>
<td style="text-align:right">0.9896</td>
<td style="text-align:right">0.9898</td>
<td style="text-align:right">0.9901</td>
<td style="text-align:right">0.9904</td>
<td style="text-align:right">0.9906</td>
<td style="text-align:right">0.9909</td>
<td style="text-align:right">0.9911</td>
<td style="text-align:right">0.9913</td>
<td style="text-align:right">0.9916</td>
</tr>
<tr>
<td style="text-align:left"><strong>2.4</strong></td>
<td style="text-align:right">0.9918</td>
<td style="text-align:right">0.9920</td>
<td style="text-align:right">0.9922</td>
<td style="text-align:right">0.9925</td>
<td style="text-align:right">0.9927</td>
<td style="text-align:right">0.9929</td>
<td style="text-align:right">0.9931</td>
<td style="text-align:right">0.9932</td>
<td style="text-align:right">0.9934</td>
<td style="text-align:right">0.9936</td>
</tr>
<tr>
<td style="text-align:left"><strong>2.5</strong></td>
<td style="text-align:right">0.9938</td>
<td style="text-align:right">0.9940</td>
<td style="text-align:right">0.9941</td>
<td style="text-align:right">0.9943</td>
<td style="text-align:right">0.9945</td>
<td style="text-align:right">0.9946</td>
<td style="text-align:right">0.9948</td>
<td style="text-align:right">0.9949</td>
<td style="text-align:right">0.9951</td>
<td style="text-align:right">0.9952</td>
</tr>
<tr>
<td style="text-align:left"><strong>2.6</strong></td>
<td style="text-align:right">0.9953</td>
<td style="text-align:right">0.9955</td>
<td style="text-align:right">0.9956</td>
<td style="text-align:right">0.9957</td>
<td style="text-align:right">0.9959</td>
<td style="text-align:right">0.9960</td>
<td style="text-align:right">0.9961</td>
<td style="text-align:right">0.9962</td>
<td style="text-align:right">0.9963</td>
<td style="text-align:right">0.9964</td>
</tr>
<tr>
<td style="text-align:left"><strong>2.7</strong></td>
<td style="text-align:right">0.9965</td>
<td style="text-align:right">0.9966</td>
<td style="text-align:right">0.9967</td>
<td style="text-align:right">0.9968</td>
<td style="text-align:right">0.9969</td>
<td style="text-align:right">0.9970</td>
<td style="text-align:right">0.9971</td>
<td style="text-align:right">0.9972</td>
<td style="text-align:right">0.9973</td>
<td style="text-align:right">0.9974</td>
</tr>
<tr>
<td style="text-align:left"><strong>2.8</strong></td>
<td style="text-align:right">0.9974</td>
<td style="text-align:right">0.9975</td>
<td style="text-align:right">0.9976</td>
<td style="text-align:right">0.9977</td>
<td style="text-align:right">0.9977</td>
<td style="text-align:right">0.9978</td>
<td style="text-align:right">0.9979</td>
<td style="text-align:right">0.9979</td>
<td style="text-align:right">0.9980</td>
<td style="text-align:right">0.9981</td>
</tr>
<tr>
<td style="text-align:left"><strong>2.9</strong></td>
<td style="text-align:right">0.9981</td>
<td style="text-align:right">0.9982</td>
<td style="text-align:right">0.9982</td>
<td style="text-align:right">0.9983</td>
<td style="text-align:right">0.9984</td>
<td style="text-align:right">0.9984</td>
<td style="text-align:right">0.9985</td>
<td style="text-align:right">0.9985</td>
<td style="text-align:right">0.9986</td>
<td style="text-align:right">0.9986</td>
</tr>
<tr>
<td style="text-align:left"><strong>3.0</strong></td>
<td style="text-align:right">0.9987</td>
<td style="text-align:right">0.9987</td>
<td style="text-align:right">0.9987</td>
<td style="text-align:right">0.9988</td>
<td style="text-align:right">0.9988</td>
<td style="text-align:right">0.9989</td>
<td style="text-align:right">0.9989</td>
<td style="text-align:right">0.9989</td>
<td style="text-align:right">0.9990</td>
<td style="text-align:right">0.9990</td>
</tr>
<tr>
<td style="text-align:left"><strong>3.1</strong></td>
<td style="text-align:right">0.9990</td>
<td style="text-align:right">0.9991</td>
<td style="text-align:right">0.9991</td>
<td style="text-align:right">0.9991</td>
<td style="text-align:right">0.9992</td>
<td style="text-align:right">0.9992</td>
<td style="text-align:right">0.9992</td>
<td style="text-align:right">0.9992</td>
<td style="text-align:right">0.9993</td>
<td style="text-align:right">0.9993</td>
</tr>
<tr>
<td style="text-align:left"><strong>3.2</strong></td>
<td style="text-align:right">0.9993</td>
<td style="text-align:right">0.9993</td>
<td style="text-align:right">0.9994</td>
<td style="text-align:right">0.9994</td>
<td style="text-align:right">0.9994</td>
<td style="text-align:right">0.9994</td>
<td style="text-align:right">0.9994</td>
<td style="text-align:right">0.9995</td>
<td style="text-align:right">0.9995</td>
<td style="text-align:right">0.9995</td>
</tr>
<tr>
<td style="text-align:left"><strong>3.3</strong></td>
<td style="text-align:right">0.9995</td>
<td style="text-align:right">0.9995</td>
<td style="text-align:right">0.9995</td>
<td style="text-align:right">0.9996</td>
<td style="text-align:right">0.9996</td>
<td style="text-align:right">0.9996</td>
<td style="text-align:right">0.9996</td>
<td style="text-align:right">0.9996</td>
<td style="text-align:right">0.9996</td>
<td style="text-align:right">0.9997</td>
</tr>
<tr>
<td style="text-align:left"><strong>3.4</strong></td>
<td style="text-align:right">0.9997</td>
<td style="text-align:right">0.9997</td>
<td style="text-align:right">0.9997</td>
<td style="text-align:right">0.9997</td>
<td style="text-align:right">0.9997</td>
<td style="text-align:right">0.9997</td>
<td style="text-align:right">0.9997</td>
<td style="text-align:right">0.9997</td>
<td style="text-align:right">0.9997</td>
<td style="text-align:right">0.9998</td>
</tr>
</tbody>
</table>
<h2 id="t-text-distribution"><code>\(t \text{ Distribution}\)</code></h2>
<p><img src="https://roh.engineering/posts/2018/03/statistical-distribution-tables/index_files/figure-html/unnamed-chunk-2-1.png" width="192" style="display: block; margin: auto;" /></p>
<h5 id="texttable-3-percentiles-of-the-t-distribution"><code>$\text{Table 3: Percentiles of the t Distribution}$</code></h5>
<table>
<thead>
<tr>
<th style="text-align:left"><code>$v \big\backslash \alpha$</code></th>
<th style="text-align:right">0.1</th>
<th style="text-align:right">0.05</th>
<th style="text-align:right">0.025</th>
<th style="text-align:right">0.01</th>
<th style="text-align:right">0.005</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"><strong>1</strong></td>
<td style="text-align:right">3.077684</td>
<td style="text-align:right">6.313752</td>
<td style="text-align:right">12.706205</td>
<td style="text-align:right">31.820516</td>
<td style="text-align:right">63.656741</td>
</tr>
<tr>
<td style="text-align:left"><strong>2</strong></td>
<td style="text-align:right">1.885618</td>
<td style="text-align:right">2.919986</td>
<td style="text-align:right">4.302653</td>
<td style="text-align:right">6.964557</td>
<td style="text-align:right">9.924843</td>
</tr>
<tr>
<td style="text-align:left"><strong>3</strong></td>
<td style="text-align:right">1.637744</td>
<td style="text-align:right">2.353363</td>
<td style="text-align:right">3.182446</td>
<td style="text-align:right">4.540703</td>
<td style="text-align:right">5.840909</td>
</tr>
<tr>
<td style="text-align:left"><strong>4</strong></td>
<td style="text-align:right">1.533206</td>
<td style="text-align:right">2.131847</td>
<td style="text-align:right">2.776445</td>
<td style="text-align:right">3.746947</td>
<td style="text-align:right">4.604095</td>
</tr>
<tr>
<td style="text-align:left"><strong>5</strong></td>
<td style="text-align:right">1.475884</td>
<td style="text-align:right">2.015048</td>
<td style="text-align:right">2.570582</td>
<td style="text-align:right">3.364930</td>
<td style="text-align:right">4.032143</td>
</tr>
<tr>
<td style="text-align:left"><strong>6</strong></td>
<td style="text-align:right">1.439756</td>
<td style="text-align:right">1.943180</td>
<td style="text-align:right">2.446912</td>
<td style="text-align:right">3.142668</td>
<td style="text-align:right">3.707428</td>
</tr>
<tr>
<td style="text-align:left"><strong>7</strong></td>
<td style="text-align:right">1.414924</td>
<td style="text-align:right">1.894579</td>
<td style="text-align:right">2.364624</td>
<td style="text-align:right">2.997952</td>
<td style="text-align:right">3.499483</td>
</tr>
<tr>
<td style="text-align:left"><strong>8</strong></td>
<td style="text-align:right">1.396815</td>
<td style="text-align:right">1.859548</td>
<td style="text-align:right">2.306004</td>
<td style="text-align:right">2.896459</td>
<td style="text-align:right">3.355387</td>
</tr>
<tr>
<td style="text-align:left"><strong>9</strong></td>
<td style="text-align:right">1.383029</td>
<td style="text-align:right">1.833113</td>
<td style="text-align:right">2.262157</td>
<td style="text-align:right">2.821438</td>
<td style="text-align:right">3.249836</td>
</tr>
<tr>
<td style="text-align:left"><strong>10</strong></td>
<td style="text-align:right">1.372184</td>
<td style="text-align:right">1.812461</td>
<td style="text-align:right">2.228139</td>
<td style="text-align:right">2.763769</td>
<td style="text-align:right">3.169273</td>
</tr>
<tr>
<td style="text-align:left"><strong>11</strong></td>
<td style="text-align:right">1.363430</td>
<td style="text-align:right">1.795885</td>
<td style="text-align:right">2.200985</td>
<td style="text-align:right">2.718079</td>
<td style="text-align:right">3.105806</td>
</tr>
<tr>
<td style="text-align:left"><strong>12</strong></td>
<td style="text-align:right">1.356217</td>
<td style="text-align:right">1.782288</td>
<td style="text-align:right">2.178813</td>
<td style="text-align:right">2.680998</td>
<td style="text-align:right">3.054540</td>
</tr>
<tr>
<td style="text-align:left"><strong>13</strong></td>
<td style="text-align:right">1.350171</td>
<td style="text-align:right">1.770933</td>
<td style="text-align:right">2.160369</td>
<td style="text-align:right">2.650309</td>
<td style="text-align:right">3.012276</td>
</tr>
<tr>
<td style="text-align:left"><strong>14</strong></td>
<td style="text-align:right">1.345030</td>
<td style="text-align:right">1.761310</td>
<td style="text-align:right">2.144787</td>
<td style="text-align:right">2.624494</td>
<td style="text-align:right">2.976843</td>
</tr>
<tr>
<td style="text-align:left"><strong>15</strong></td>
<td style="text-align:right">1.340606</td>
<td style="text-align:right">1.753050</td>
<td style="text-align:right">2.131449</td>
<td style="text-align:right">2.602480</td>
<td style="text-align:right">2.946713</td>
</tr>
<tr>
<td style="text-align:left"><strong>16</strong></td>
<td style="text-align:right">1.336757</td>
<td style="text-align:right">1.745884</td>
<td style="text-align:right">2.119905</td>
<td style="text-align:right">2.583487</td>
<td style="text-align:right">2.920782</td>
</tr>
<tr>
<td style="text-align:left"><strong>17</strong></td>
<td style="text-align:right">1.333379</td>
<td style="text-align:right">1.739607</td>
<td style="text-align:right">2.109816</td>
<td style="text-align:right">2.566934</td>
<td style="text-align:right">2.898230</td>
</tr>
<tr>
<td style="text-align:left"><strong>18</strong></td>
<td style="text-align:right">1.330391</td>
<td style="text-align:right">1.734064</td>
<td style="text-align:right">2.100922</td>
<td style="text-align:right">2.552380</td>
<td style="text-align:right">2.878440</td>
</tr>
<tr>
<td style="text-align:left"><strong>19</strong></td>
<td style="text-align:right">1.327728</td>
<td style="text-align:right">1.729133</td>
<td style="text-align:right">2.093024</td>
<td style="text-align:right">2.539483</td>
<td style="text-align:right">2.860935</td>
</tr>
<tr>
<td style="text-align:left"><strong>20</strong></td>
<td style="text-align:right">1.325341</td>
<td style="text-align:right">1.724718</td>
<td style="text-align:right">2.085963</td>
<td style="text-align:right">2.527977</td>
<td style="text-align:right">2.845340</td>
</tr>
<tr>
<td style="text-align:left"><strong>21</strong></td>
<td style="text-align:right">1.323188</td>
<td style="text-align:right">1.720743</td>
<td style="text-align:right">2.079614</td>
<td style="text-align:right">2.517648</td>
<td style="text-align:right">2.831360</td>
</tr>
<tr>
<td style="text-align:left"><strong>22</strong></td>
<td style="text-align:right">1.321237</td>
<td style="text-align:right">1.717144</td>
<td style="text-align:right">2.073873</td>
<td style="text-align:right">2.508325</td>
<td style="text-align:right">2.818756</td>
</tr>
<tr>
<td style="text-align:left"><strong>23</strong></td>
<td style="text-align:right">1.319460</td>
<td style="text-align:right">1.713871</td>
<td style="text-align:right">2.068658</td>
<td style="text-align:right">2.499867</td>
<td style="text-align:right">2.807336</td>
</tr>
<tr>
<td style="text-align:left"><strong>24</strong></td>
<td style="text-align:right">1.317836</td>
<td style="text-align:right">1.710882</td>
<td style="text-align:right">2.063899</td>
<td style="text-align:right">2.492160</td>
<td style="text-align:right">2.796940</td>
</tr>
<tr>
<td style="text-align:left"><strong>25</strong></td>
<td style="text-align:right">1.316345</td>
<td style="text-align:right">1.708141</td>
<td style="text-align:right">2.059539</td>
<td style="text-align:right">2.485107</td>
<td style="text-align:right">2.787436</td>
</tr>
<tr>
<td style="text-align:left"><strong>26</strong></td>
<td style="text-align:right">1.314972</td>
<td style="text-align:right">1.705618</td>
<td style="text-align:right">2.055529</td>
<td style="text-align:right">2.478630</td>
<td style="text-align:right">2.778714</td>
</tr>
<tr>
<td style="text-align:left"><strong>27</strong></td>
<td style="text-align:right">1.313703</td>
<td style="text-align:right">1.703288</td>
<td style="text-align:right">2.051830</td>
<td style="text-align:right">2.472660</td>
<td style="text-align:right">2.770683</td>
</tr>
<tr>
<td style="text-align:left"><strong>28</strong></td>
<td style="text-align:right">1.312527</td>
<td style="text-align:right">1.701131</td>
<td style="text-align:right">2.048407</td>
<td style="text-align:right">2.467140</td>
<td style="text-align:right">2.763263</td>
</tr>
<tr>
<td style="text-align:left"><strong>29</strong></td>
<td style="text-align:right">1.311434</td>
<td style="text-align:right">1.699127</td>
<td style="text-align:right">2.045230</td>
<td style="text-align:right">2.462021</td>
<td style="text-align:right">2.756386</td>
</tr>
<tr>
<td style="text-align:left"><strong>30</strong></td>
<td style="text-align:right">1.310415</td>
<td style="text-align:right">1.697261</td>
<td style="text-align:right">2.042273</td>
<td style="text-align:right">2.457261</td>
<td style="text-align:right">2.749996</td>
</tr>
<tr>
<td style="text-align:left">$\infty$</td>
<td style="text-align:right">1.281552</td>
<td style="text-align:right">1.644854</td>
<td style="text-align:right">1.959964</td>
<td style="text-align:right">2.326348</td>
<td style="text-align:right">2.575829</td>
</tr>
</tbody>
</table>
<h2 id="chi2-text-distribution"><code>\(\chi^2 \text{ Distribution}\)</code></h2>
<p><img src="https://roh.engineering/posts/2018/03/statistical-distribution-tables/index_files/figure-html/unnamed-chunk-3-1.png" width="192" style="display: block; margin: auto;" /></p>
<h5 id="texttable-4-percentiles-of-the--chi2-text-distribution"><code>$\text{Table 4: Percentiles of the } \chi^2 \text{ Distribution}$</code></h5>
<table>
<thead>
<tr>
<th style="text-align:left"><code>$v \big\backslash \alpha$</code></th>
<th style="text-align:right">0.995</th>
<th style="text-align:right">0.99</th>
<th style="text-align:right">0.975</th>
<th style="text-align:right">0.95</th>
<th style="text-align:right">0.9</th>
<th style="text-align:right">0.75</th>
<th style="text-align:right">0.5</th>
<th style="text-align:right">0.25</th>
<th style="text-align:right">0.1</th>
<th style="text-align:right">0.05</th>
<th style="text-align:right">0.025</th>
<th style="text-align:right">0.01</th>
<th style="text-align:right">0.005</th>
<th style="text-align:right">0.001</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"><strong>1</strong></td>
<td style="text-align:right">0.00</td>
<td style="text-align:right">0.00</td>
<td style="text-align:right">0.00</td>
<td style="text-align:right">0.00</td>
<td style="text-align:right">0.02</td>
<td style="text-align:right">0.10</td>
<td style="text-align:right">0.45</td>
<td style="text-align:right">1.32</td>
<td style="text-align:right">2.71</td>
<td style="text-align:right">3.84</td>
<td style="text-align:right">5.02</td>
<td style="text-align:right">6.63</td>
<td style="text-align:right">7.88</td>
<td style="text-align:right">10.83</td>
</tr>
<tr>
<td style="text-align:left"><strong>2</strong></td>
<td style="text-align:right">0.01</td>
<td style="text-align:right">0.02</td>
<td style="text-align:right">0.05</td>
<td style="text-align:right">0.10</td>
<td style="text-align:right">0.21</td>
<td style="text-align:right">0.58</td>
<td style="text-align:right">1.39</td>
<td style="text-align:right">2.77</td>
<td style="text-align:right">4.61</td>
<td style="text-align:right">5.99</td>
<td style="text-align:right">7.38</td>
<td style="text-align:right">9.21</td>
<td style="text-align:right">10.60</td>
<td style="text-align:right">13.82</td>
</tr>
<tr>
<td style="text-align:left"><strong>3</strong></td>
<td style="text-align:right">0.07</td>
<td style="text-align:right">0.11</td>
<td style="text-align:right">0.22</td>
<td style="text-align:right">0.35</td>
<td style="text-align:right">0.58</td>
<td style="text-align:right">1.21</td>
<td style="text-align:right">2.37</td>
<td style="text-align:right">4.11</td>
<td style="text-align:right">6.25</td>
<td style="text-align:right">7.81</td>
<td style="text-align:right">9.35</td>
<td style="text-align:right">11.34</td>
<td style="text-align:right">12.84</td>
<td style="text-align:right">16.27</td>
</tr>
<tr>
<td style="text-align:left"><strong>4</strong></td>
<td style="text-align:right">0.21</td>
<td style="text-align:right">0.30</td>
<td style="text-align:right">0.48</td>
<td style="text-align:right">0.71</td>
<td style="text-align:right">1.06</td>
<td style="text-align:right">1.92</td>
<td style="text-align:right">3.36</td>
<td style="text-align:right">5.39</td>
<td style="text-align:right">7.78</td>
<td style="text-align:right">9.49</td>
<td style="text-align:right">11.14</td>
<td style="text-align:right">13.28</td>
<td style="text-align:right">14.86</td>
<td style="text-align:right">18.47</td>
</tr>
<tr>
<td style="text-align:left"><strong>5</strong></td>
<td style="text-align:right">0.41</td>
<td style="text-align:right">0.55</td>
<td style="text-align:right">0.83</td>
<td style="text-align:right">1.15</td>
<td style="text-align:right">1.61</td>
<td style="text-align:right">2.67</td>
<td style="text-align:right">4.35</td>
<td style="text-align:right">6.63</td>
<td style="text-align:right">9.24</td>
<td style="text-align:right">11.07</td>
<td style="text-align:right">12.83</td>
<td style="text-align:right">15.09</td>
<td style="text-align:right">16.75</td>
<td style="text-align:right">20.52</td>
</tr>
<tr>
<td style="text-align:left"><strong>6</strong></td>
<td style="text-align:right">0.68</td>
<td style="text-align:right">0.87</td>
<td style="text-align:right">1.24</td>
<td style="text-align:right">1.64</td>
<td style="text-align:right">2.20</td>
<td style="text-align:right">3.45</td>
<td style="text-align:right">5.35</td>
<td style="text-align:right">7.84</td>
<td style="text-align:right">10.64</td>
<td style="text-align:right">12.59</td>
<td style="text-align:right">14.45</td>
<td style="text-align:right">16.81</td>
<td style="text-align:right">18.55</td>
<td style="text-align:right">22.46</td>
</tr>
<tr>
<td style="text-align:left"><strong>7</strong></td>
<td style="text-align:right">0.99</td>
<td style="text-align:right">1.24</td>
<td style="text-align:right">1.69</td>
<td style="text-align:right">2.17</td>
<td style="text-align:right">2.83</td>
<td style="text-align:right">4.25</td>
<td style="text-align:right">6.35</td>
<td style="text-align:right">9.04</td>
<td style="text-align:right">12.02</td>
<td style="text-align:right">14.07</td>
<td style="text-align:right">16.01</td>
<td style="text-align:right">18.48</td>
<td style="text-align:right">20.28</td>
<td style="text-align:right">24.32</td>
</tr>
<tr>
<td style="text-align:left"><strong>8</strong></td>
<td style="text-align:right">1.34</td>
<td style="text-align:right">1.65</td>
<td style="text-align:right">2.18</td>
<td style="text-align:right">2.73</td>
<td style="text-align:right">3.49</td>
<td style="text-align:right">5.07</td>
<td style="text-align:right">7.34</td>
<td style="text-align:right">10.22</td>
<td style="text-align:right">13.36</td>
<td style="text-align:right">15.51</td>
<td style="text-align:right">17.53</td>
<td style="text-align:right">20.09</td>
<td style="text-align:right">21.95</td>
<td style="text-align:right">26.12</td>
</tr>
<tr>
<td style="text-align:left"><strong>9</strong></td>
<td style="text-align:right">1.73</td>
<td style="text-align:right">2.09</td>
<td style="text-align:right">2.70</td>
<td style="text-align:right">3.33</td>
<td style="text-align:right">4.17</td>
<td style="text-align:right">5.90</td>
<td style="text-align:right">8.34</td>
<td style="text-align:right">11.39</td>
<td style="text-align:right">14.68</td>
<td style="text-align:right">16.92</td>
<td style="text-align:right">19.02</td>
<td style="text-align:right">21.67</td>
<td style="text-align:right">23.59</td>
<td style="text-align:right">27.88</td>
</tr>
<tr>
<td style="text-align:left"><strong>10</strong></td>
<td style="text-align:right">2.16</td>
<td style="text-align:right">2.56</td>
<td style="text-align:right">3.25</td>
<td style="text-align:right">3.94</td>
<td style="text-align:right">4.87</td>
<td style="text-align:right">6.74</td>
<td style="text-align:right">9.34</td>
<td style="text-align:right">12.55</td>
<td style="text-align:right">15.99</td>
<td style="text-align:right">18.31</td>
<td style="text-align:right">20.48</td>
<td style="text-align:right">23.21</td>
<td style="text-align:right">25.19</td>
<td style="text-align:right">29.59</td>
</tr>
<tr>
<td style="text-align:left"><strong>11</strong></td>
<td style="text-align:right">2.60</td>
<td style="text-align:right">3.05</td>
<td style="text-align:right">3.82</td>
<td style="text-align:right">4.57</td>
<td style="text-align:right">5.58</td>
<td style="text-align:right">7.58</td>
<td style="text-align:right">10.34</td>
<td style="text-align:right">13.70</td>
<td style="text-align:right">17.28</td>
<td style="text-align:right">19.68</td>
<td style="text-align:right">21.92</td>
<td style="text-align:right">24.72</td>
<td style="text-align:right">26.76</td>
<td style="text-align:right">31.26</td>
</tr>
<tr>
<td style="text-align:left"><strong>12</strong></td>
<td style="text-align:right">3.07</td>
<td style="text-align:right">3.57</td>
<td style="text-align:right">4.40</td>
<td style="text-align:right">5.23</td>
<td style="text-align:right">6.30</td>
<td style="text-align:right">8.44</td>
<td style="text-align:right">11.34</td>
<td style="text-align:right">14.85</td>
<td style="text-align:right">18.55</td>
<td style="text-align:right">21.03</td>
<td style="text-align:right">23.34</td>
<td style="text-align:right">26.22</td>
<td style="text-align:right">28.30</td>
<td style="text-align:right">32.91</td>
</tr>
<tr>
<td style="text-align:left"><strong>13</strong></td>
<td style="text-align:right">3.57</td>
<td style="text-align:right">4.11</td>
<td style="text-align:right">5.01</td>
<td style="text-align:right">5.89</td>
<td style="text-align:right">7.04</td>
<td style="text-align:right">9.30</td>
<td style="text-align:right">12.34</td>
<td style="text-align:right">15.98</td>
<td style="text-align:right">19.81</td>
<td style="text-align:right">22.36</td>
<td style="text-align:right">24.74</td>
<td style="text-align:right">27.69</td>
<td style="text-align:right">29.82</td>
<td style="text-align:right">34.53</td>
</tr>
<tr>
<td style="text-align:left"><strong>14</strong></td>
<td style="text-align:right">4.07</td>
<td style="text-align:right">4.66</td>
<td style="text-align:right">5.63</td>
<td style="text-align:right">6.57</td>
<td style="text-align:right">7.79</td>
<td style="text-align:right">10.17</td>
<td style="text-align:right">13.34</td>
<td style="text-align:right">17.12</td>
<td style="text-align:right">21.06</td>
<td style="text-align:right">23.68</td>
<td style="text-align:right">26.12</td>
<td style="text-align:right">29.14</td>
<td style="text-align:right">31.32</td>
<td style="text-align:right">36.12</td>
</tr>
<tr>
<td style="text-align:left"><strong>15</strong></td>
<td style="text-align:right">4.60</td>
<td style="text-align:right">5.23</td>
<td style="text-align:right">6.26</td>
<td style="text-align:right">7.26</td>
<td style="text-align:right">8.55</td>
<td style="text-align:right">11.04</td>
<td style="text-align:right">14.34</td>
<td style="text-align:right">18.25</td>
<td style="text-align:right">22.31</td>
<td style="text-align:right">25.00</td>
<td style="text-align:right">27.49</td>
<td style="text-align:right">30.58</td>
<td style="text-align:right">32.80</td>
<td style="text-align:right">37.70</td>
</tr>
<tr>
<td style="text-align:left"><strong>16</strong></td>
<td style="text-align:right">5.14</td>
<td style="text-align:right">5.81</td>
<td style="text-align:right">6.91</td>
<td style="text-align:right">7.96</td>
<td style="text-align:right">9.31</td>
<td style="text-align:right">11.91</td>
<td style="text-align:right">15.34</td>
<td style="text-align:right">19.37</td>
<td style="text-align:right">23.54</td>
<td style="text-align:right">26.30</td>
<td style="text-align:right">28.85</td>
<td style="text-align:right">32.00</td>
<td style="text-align:right">34.27</td>
<td style="text-align:right">39.25</td>
</tr>
<tr>
<td style="text-align:left"><strong>17</strong></td>
<td style="text-align:right">5.70</td>
<td style="text-align:right">6.41</td>
<td style="text-align:right">7.56</td>
<td style="text-align:right">8.67</td>
<td style="text-align:right">10.09</td>
<td style="text-align:right">12.79</td>
<td style="text-align:right">16.34</td>
<td style="text-align:right">20.49</td>
<td style="text-align:right">24.77</td>
<td style="text-align:right">27.59</td>
<td style="text-align:right">30.19</td>
<td style="text-align:right">33.41</td>
<td style="text-align:right">35.72</td>
<td style="text-align:right">40.79</td>
</tr>
<tr>
<td style="text-align:left"><strong>18</strong></td>
<td style="text-align:right">6.26</td>
<td style="text-align:right">7.01</td>
<td style="text-align:right">8.23</td>
<td style="text-align:right">9.39</td>
<td style="text-align:right">10.86</td>
<td style="text-align:right">13.68</td>
<td style="text-align:right">17.34</td>
<td style="text-align:right">21.60</td>
<td style="text-align:right">25.99</td>
<td style="text-align:right">28.87</td>
<td style="text-align:right">31.53</td>
<td style="text-align:right">34.81</td>
<td style="text-align:right">37.16</td>
<td style="text-align:right">42.31</td>
</tr>
<tr>
<td style="text-align:left"><strong>19</strong></td>
<td style="text-align:right">6.84</td>
<td style="text-align:right">7.63</td>
<td style="text-align:right">8.91</td>
<td style="text-align:right">10.12</td>
<td style="text-align:right">11.65</td>
<td style="text-align:right">14.56</td>
<td style="text-align:right">18.34</td>
<td style="text-align:right">22.72</td>
<td style="text-align:right">27.20</td>
<td style="text-align:right">30.14</td>
<td style="text-align:right">32.85</td>
<td style="text-align:right">36.19</td>
<td style="text-align:right">38.58</td>
<td style="text-align:right">43.82</td>
</tr>
<tr>
<td style="text-align:left"><strong>20</strong></td>
<td style="text-align:right">7.43</td>
<td style="text-align:right">8.26</td>
<td style="text-align:right">9.59</td>
<td style="text-align:right">10.85</td>
<td style="text-align:right">12.44</td>
<td style="text-align:right">15.45</td>
<td style="text-align:right">19.34</td>
<td style="text-align:right">23.83</td>
<td style="text-align:right">28.41</td>
<td style="text-align:right">31.41</td>
<td style="text-align:right">34.17</td>
<td style="text-align:right">37.57</td>
<td style="text-align:right">40.00</td>
<td style="text-align:right">45.31</td>
</tr>
<tr>
<td style="text-align:left"><strong>21</strong></td>
<td style="text-align:right">8.03</td>
<td style="text-align:right">8.90</td>
<td style="text-align:right">10.28</td>
<td style="text-align:right">11.59</td>
<td style="text-align:right">13.24</td>
<td style="text-align:right">16.34</td>
<td style="text-align:right">20.34</td>
<td style="text-align:right">24.93</td>
<td style="text-align:right">29.62</td>
<td style="text-align:right">32.67</td>
<td style="text-align:right">35.48</td>
<td style="text-align:right">38.93</td>
<td style="text-align:right">41.40</td>
<td style="text-align:right">46.80</td>
</tr>
<tr>
<td style="text-align:left"><strong>22</strong></td>
<td style="text-align:right">8.64</td>
<td style="text-align:right">9.54</td>
<td style="text-align:right">10.98</td>
<td style="text-align:right">12.34</td>
<td style="text-align:right">14.04</td>
<td style="text-align:right">17.24</td>
<td style="text-align:right">21.34</td>
<td style="text-align:right">26.04</td>
<td style="text-align:right">30.81</td>
<td style="text-align:right">33.92</td>
<td style="text-align:right">36.78</td>
<td style="text-align:right">40.29</td>
<td style="text-align:right">42.80</td>
<td style="text-align:right">48.27</td>
</tr>
<tr>
<td style="text-align:left"><strong>23</strong></td>
<td style="text-align:right">9.26</td>
<td style="text-align:right">10.20</td>
<td style="text-align:right">11.69</td>
<td style="text-align:right">13.09</td>
<td style="text-align:right">14.85</td>
<td style="text-align:right">18.14</td>
<td style="text-align:right">22.34</td>
<td style="text-align:right">27.14</td>
<td style="text-align:right">32.01</td>
<td style="text-align:right">35.17</td>
<td style="text-align:right">38.08</td>
<td style="text-align:right">41.64</td>
<td style="text-align:right">44.18</td>
<td style="text-align:right">49.73</td>
</tr>
<tr>
<td style="text-align:left"><strong>24</strong></td>
<td style="text-align:right">9.89</td>
<td style="text-align:right">10.86</td>
<td style="text-align:right">12.40</td>
<td style="text-align:right">13.85</td>
<td style="text-align:right">15.66</td>
<td style="text-align:right">19.04</td>
<td style="text-align:right">23.34</td>
<td style="text-align:right">28.24</td>
<td style="text-align:right">33.20</td>
<td style="text-align:right">36.42</td>
<td style="text-align:right">39.36</td>
<td style="text-align:right">42.98</td>
<td style="text-align:right">45.56</td>
<td style="text-align:right">51.18</td>
</tr>
<tr>
<td style="text-align:left"><strong>25</strong></td>
<td style="text-align:right">10.52</td>
<td style="text-align:right">11.52</td>
<td style="text-align:right">13.12</td>
<td style="text-align:right">14.61</td>
<td style="text-align:right">16.47</td>
<td style="text-align:right">19.94</td>
<td style="text-align:right">24.34</td>
<td style="text-align:right">29.34</td>
<td style="text-align:right">34.38</td>
<td style="text-align:right">37.65</td>
<td style="text-align:right">40.65</td>
<td style="text-align:right">44.31</td>
<td style="text-align:right">46.93</td>
<td style="text-align:right">52.62</td>
</tr>
<tr>
<td style="text-align:left"><strong>30</strong></td>
<td style="text-align:right">13.79</td>
<td style="text-align:right">14.95</td>
<td style="text-align:right">16.79</td>
<td style="text-align:right">18.49</td>
<td style="text-align:right">20.60</td>
<td style="text-align:right">24.48</td>
<td style="text-align:right">29.34</td>
<td style="text-align:right">34.80</td>
<td style="text-align:right">40.26</td>
<td style="text-align:right">43.77</td>
<td style="text-align:right">46.98</td>
<td style="text-align:right">50.89</td>
<td style="text-align:right">53.67</td>
<td style="text-align:right">59.70</td>
</tr>
<tr>
<td style="text-align:left"><strong>40</strong></td>
<td style="text-align:right">20.71</td>
<td style="text-align:right">22.16</td>
<td style="text-align:right">24.43</td>
<td style="text-align:right">26.51</td>
<td style="text-align:right">29.05</td>
<td style="text-align:right">33.66</td>
<td style="text-align:right">39.34</td>
<td style="text-align:right">45.62</td>
<td style="text-align:right">51.81</td>
<td style="text-align:right">55.76</td>
<td style="text-align:right">59.34</td>
<td style="text-align:right">63.69</td>
<td style="text-align:right">66.77</td>
<td style="text-align:right">73.40</td>
</tr>
<tr>
<td style="text-align:left"><strong>50</strong></td>
<td style="text-align:right">27.99</td>
<td style="text-align:right">29.71</td>
<td style="text-align:right">32.36</td>
<td style="text-align:right">34.76</td>
<td style="text-align:right">37.69</td>
<td style="text-align:right">42.94</td>
<td style="text-align:right">49.33</td>
<td style="text-align:right">56.33</td>
<td style="text-align:right">63.17</td>
<td style="text-align:right">67.50</td>
<td style="text-align:right">71.42</td>
<td style="text-align:right">76.15</td>
<td style="text-align:right">79.49</td>
<td style="text-align:right">86.66</td>
</tr>
<tr>
<td style="text-align:left"><strong>60</strong></td>
<td style="text-align:right">35.53</td>
<td style="text-align:right">37.48</td>
<td style="text-align:right">40.48</td>
<td style="text-align:right">43.19</td>
<td style="text-align:right">46.46</td>
<td style="text-align:right">52.29</td>
<td style="text-align:right">59.33</td>
<td style="text-align:right">66.98</td>
<td style="text-align:right">74.40</td>
<td style="text-align:right">79.08</td>
<td style="text-align:right">83.30</td>
<td style="text-align:right">88.38</td>
<td style="text-align:right">91.95</td>
<td style="text-align:right">99.61</td>
</tr>
<tr>
<td style="text-align:left"><strong>70</strong></td>
<td style="text-align:right">43.28</td>
<td style="text-align:right">45.44</td>
<td style="text-align:right">48.76</td>
<td style="text-align:right">51.74</td>
<td style="text-align:right">55.33</td>
<td style="text-align:right">61.70</td>
<td style="text-align:right">69.33</td>
<td style="text-align:right">77.58</td>
<td style="text-align:right">85.53</td>
<td style="text-align:right">90.53</td>
<td style="text-align:right">95.02</td>
<td style="text-align:right">100.43</td>
<td style="text-align:right">104.21</td>
<td style="text-align:right">112.32</td>
</tr>
<tr>
<td style="text-align:left"><strong>80</strong></td>
<td style="text-align:right">51.17</td>
<td style="text-align:right">53.54</td>
<td style="text-align:right">57.15</td>
<td style="text-align:right">60.39</td>
<td style="text-align:right">64.28</td>
<td style="text-align:right">71.14</td>
<td style="text-align:right">79.33</td>
<td style="text-align:right">88.13</td>
<td style="text-align:right">96.58</td>
<td style="text-align:right">101.88</td>
<td style="text-align:right">106.63</td>
<td style="text-align:right">112.33</td>
<td style="text-align:right">116.32</td>
<td style="text-align:right">124.84</td>
</tr>
<tr>
<td style="text-align:left"><strong>90</strong></td>
<td style="text-align:right">59.20</td>
<td style="text-align:right">61.75</td>
<td style="text-align:right">65.65</td>
<td style="text-align:right">69.13</td>
<td style="text-align:right">73.29</td>
<td style="text-align:right">80.62</td>
<td style="text-align:right">89.33</td>
<td style="text-align:right">98.65</td>
<td style="text-align:right">107.57</td>
<td style="text-align:right">113.15</td>
<td style="text-align:right">118.14</td>
<td style="text-align:right">124.12</td>
<td style="text-align:right">128.30</td>
<td style="text-align:right">137.21</td>
</tr>
<tr>
<td style="text-align:left"><strong>100</strong></td>
<td style="text-align:right">67.33</td>
<td style="text-align:right">70.06</td>
<td style="text-align:right">74.22</td>
<td style="text-align:right">77.93</td>
<td style="text-align:right">82.36</td>
<td style="text-align:right">90.13</td>
<td style="text-align:right">99.33</td>
<td style="text-align:right">109.14</td>
<td style="text-align:right">118.50</td>
<td style="text-align:right">124.34</td>
<td style="text-align:right">129.56</td>
<td style="text-align:right">135.81</td>
<td style="text-align:right">140.17</td>
<td style="text-align:right">149.45</td>
</tr>
</tbody>
</table>
<h2 id="fv_1-v_2-text-distribution"><code>\(F(v_1, v_2) \text{ Distribution}\)</code></h2>
<p><img src="https://roh.engineering/posts/2018/03/statistical-distribution-tables/index_files/figure-html/unnamed-chunk-4-1.png" width="192" style="display: block; margin: auto;" /></p>
<h5 id="texttable-5-95th-percentiles-of-the--fv_1v_2"><code>$\text{Table 5: 95th Percentiles of the } F(v_1,v_2)$</code></h5>
<table>
<thead>
<tr>
<th style="text-align:left"><code>$v_2 \big\backslash v_1$</code></th>
<th style="text-align:right">1</th>
<th style="text-align:right">2</th>
<th style="text-align:right">3</th>
<th style="text-align:right">4</th>
<th style="text-align:right">5</th>
<th style="text-align:right">6</th>
<th style="text-align:right">7</th>
<th style="text-align:right">8</th>
<th style="text-align:right">9</th>
<th style="text-align:right">10</th>
<th style="text-align:right">12</th>
<th style="text-align:right">15</th>
<th style="text-align:right">20</th>
<th style="text-align:right">24</th>
<th style="text-align:right">30</th>
<th style="text-align:right">40</th>
<th style="text-align:right">60</th>
<th style="text-align:right">120</th>
<th style="text-align:right"><code>$\infty$</code></th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"><strong>1</strong></td>
<td style="text-align:right">161.45</td>
<td style="text-align:right">199.50</td>
<td style="text-align:right">215.71</td>
<td style="text-align:right">224.58</td>
<td style="text-align:right">230.16</td>
<td style="text-align:right">233.99</td>
<td style="text-align:right">236.77</td>
<td style="text-align:right">238.88</td>
<td style="text-align:right">240.54</td>
<td style="text-align:right">241.88</td>
<td style="text-align:right">243.91</td>
<td style="text-align:right">245.95</td>
<td style="text-align:right">248.01</td>
<td style="text-align:right">249.05</td>
<td style="text-align:right">250.10</td>
<td style="text-align:right">251.14</td>
<td style="text-align:right">252.20</td>
<td style="text-align:right">253.25</td>
<td style="text-align:right">254.31</td>
</tr>
<tr>
<td style="text-align:left"><strong>2</strong></td>
<td style="text-align:right">18.51</td>
<td style="text-align:right">19.00</td>
<td style="text-align:right">19.16</td>
<td style="text-align:right">19.25</td>
<td style="text-align:right">19.30</td>
<td style="text-align:right">19.33</td>
<td style="text-align:right">19.35</td>
<td style="text-align:right">19.37</td>
<td style="text-align:right">19.38</td>
<td style="text-align:right">19.40</td>
<td style="text-align:right">19.41</td>
<td style="text-align:right">19.43</td>
<td style="text-align:right">19.45</td>
<td style="text-align:right">19.45</td>
<td style="text-align:right">19.46</td>
<td style="text-align:right">19.47</td>
<td style="text-align:right">19.48</td>
<td style="text-align:right">19.49</td>
<td style="text-align:right">19.50</td>
</tr>
<tr>
<td style="text-align:left"><strong>3</strong></td>
<td style="text-align:right">10.13</td>
<td style="text-align:right">9.55</td>
<td style="text-align:right">9.28</td>
<td style="text-align:right">9.12</td>
<td style="text-align:right">9.01</td>
<td style="text-align:right">8.94</td>
<td style="text-align:right">8.89</td>
<td style="text-align:right">8.85</td>
<td style="text-align:right">8.81</td>
<td style="text-align:right">8.79</td>
<td style="text-align:right">8.74</td>
<td style="text-align:right">8.70</td>
<td style="text-align:right">8.66</td>
<td style="text-align:right">8.64</td>
<td style="text-align:right">8.62</td>
<td style="text-align:right">8.59</td>
<td style="text-align:right">8.57</td>
<td style="text-align:right">8.55</td>
<td style="text-align:right">8.53</td>
</tr>
<tr>
<td style="text-align:left"><strong>4</strong></td>
<td style="text-align:right">7.71</td>
<td style="text-align:right">6.94</td>
<td style="text-align:right">6.59</td>
<td style="text-align:right">6.39</td>
<td style="text-align:right">6.26</td>
<td style="text-align:right">6.16</td>
<td style="text-align:right">6.09</td>
<td style="text-align:right">6.04</td>
<td style="text-align:right">6.00</td>
<td style="text-align:right">5.96</td>
<td style="text-align:right">5.91</td>
<td style="text-align:right">5.86</td>
<td style="text-align:right">5.80</td>
<td style="text-align:right">5.77</td>
<td style="text-align:right">5.75</td>
<td style="text-align:right">5.72</td>
<td style="text-align:right">5.69</td>
<td style="text-align:right">5.66</td>
<td style="text-align:right">5.63</td>
</tr>
<tr>
<td style="text-align:left"><strong>5</strong></td>
<td style="text-align:right">6.61</td>
<td style="text-align:right">5.79</td>
<td style="text-align:right">5.41</td>
<td style="text-align:right">5.19</td>
<td style="text-align:right">5.05</td>
<td style="text-align:right">4.95</td>
<td style="text-align:right">4.88</td>
<td style="text-align:right">4.82</td>
<td style="text-align:right">4.77</td>
<td style="text-align:right">4.74</td>
<td style="text-align:right">4.68</td>
<td style="text-align:right">4.62</td>
<td style="text-align:right">4.56</td>
<td style="text-align:right">4.53</td>
<td style="text-align:right">4.50</td>
<td style="text-align:right">4.46</td>
<td style="text-align:right">4.43</td>
<td style="text-align:right">4.40</td>
<td style="text-align:right">4.36</td>
</tr>
<tr>
<td style="text-align:left"><strong>6</strong></td>
<td style="text-align:right">5.99</td>
<td style="text-align:right">5.14</td>
<td style="text-align:right">4.76</td>
<td style="text-align:right">4.53</td>
<td style="text-align:right">4.39</td>
<td style="text-align:right">4.28</td>
<td style="text-align:right">4.21</td>
<td style="text-align:right">4.15</td>
<td style="text-align:right">4.10</td>
<td style="text-align:right">4.06</td>
<td style="text-align:right">4.00</td>
<td style="text-align:right">3.94</td>
<td style="text-align:right">3.87</td>
<td style="text-align:right">3.84</td>
<td style="text-align:right">3.81</td>
<td style="text-align:right">3.77</td>
<td style="text-align:right">3.74</td>
<td style="text-align:right">3.70</td>
<td style="text-align:right">3.67</td>
</tr>
<tr>
<td style="text-align:left"><strong>7</strong></td>
<td style="text-align:right">5.59</td>
<td style="text-align:right">4.74</td>
<td style="text-align:right">4.35</td>
<td style="text-align:right">4.12</td>
<td style="text-align:right">3.97</td>
<td style="text-align:right">3.87</td>
<td style="text-align:right">3.79</td>
<td style="text-align:right">3.73</td>
<td style="text-align:right">3.68</td>
<td style="text-align:right">3.64</td>
<td style="text-align:right">3.57</td>
<td style="text-align:right">3.51</td>
<td style="text-align:right">3.44</td>
<td style="text-align:right">3.41</td>
<td style="text-align:right">3.38</td>
<td style="text-align:right">3.34</td>
<td style="text-align:right">3.30</td>
<td style="text-align:right">3.27</td>
<td style="text-align:right">3.23</td>
</tr>
<tr>
<td style="text-align:left"><strong>8</strong></td>
<td style="text-align:right">5.32</td>
<td style="text-align:right">4.46</td>
<td style="text-align:right">4.07</td>
<td style="text-align:right">3.84</td>
<td style="text-align:right">3.69</td>
<td style="text-align:right">3.58</td>
<td style="text-align:right">3.50</td>
<td style="text-align:right">3.44</td>
<td style="text-align:right">3.39</td>
<td style="text-align:right">3.35</td>
<td style="text-align:right">3.28</td>
<td style="text-align:right">3.22</td>
<td style="text-align:right">3.15</td>
<td style="text-align:right">3.12</td>
<td style="text-align:right">3.08</td>
<td style="text-align:right">3.04</td>
<td style="text-align:right">3.01</td>
<td style="text-align:right">2.97</td>
<td style="text-align:right">2.93</td>
</tr>
<tr>
<td style="text-align:left"><strong>9</strong></td>
<td style="text-align:right">5.12</td>
<td style="text-align:right">4.26</td>
<td style="text-align:right">3.86</td>
<td style="text-align:right">3.63</td>
<td style="text-align:right">3.48</td>
<td style="text-align:right">3.37</td>
<td style="text-align:right">3.29</td>
<td style="text-align:right">3.23</td>
<td style="text-align:right">3.18</td>
<td style="text-align:right">3.14</td>
<td style="text-align:right">3.07</td>
<td style="text-align:right">3.01</td>
<td style="text-align:right">2.94</td>
<td style="text-align:right">2.90</td>
<td style="text-align:right">2.86</td>
<td style="text-align:right">2.83</td>
<td style="text-align:right">2.79</td>
<td style="text-align:right">2.75</td>
<td style="text-align:right">2.71</td>
</tr>
<tr>
<td style="text-align:left"><strong>10</strong></td>
<td style="text-align:right">4.96</td>
<td style="text-align:right">4.10</td>
<td style="text-align:right">3.71</td>
<td style="text-align:right">3.48</td>
<td style="text-align:right">3.33</td>
<td style="text-align:right">3.22</td>
<td style="text-align:right">3.14</td>
<td style="text-align:right">3.07</td>
<td style="text-align:right">3.02</td>
<td style="text-align:right">2.98</td>
<td style="text-align:right">2.91</td>
<td style="text-align:right">2.85</td>
<td style="text-align:right">2.77</td>
<td style="text-align:right">2.74</td>
<td style="text-align:right">2.70</td>
<td style="text-align:right">2.66</td>
<td style="text-align:right">2.62</td>
<td style="text-align:right">2.58</td>
<td style="text-align:right">2.54</td>
</tr>
<tr>
<td style="text-align:left"><strong>12</strong></td>
<td style="text-align:right">4.75</td>
<td style="text-align:right">3.89</td>
<td style="text-align:right">3.49</td>
<td style="text-align:right">3.26</td>
<td style="text-align:right">3.11</td>
<td style="text-align:right">3.00</td>
<td style="text-align:right">2.91</td>
<td style="text-align:right">2.85</td>
<td style="text-align:right">2.80</td>
<td style="text-align:right">2.75</td>
<td style="text-align:right">2.69</td>
<td style="text-align:right">2.62</td>
<td style="text-align:right">2.54</td>
<td style="text-align:right">2.51</td>
<td style="text-align:right">2.47</td>
<td style="text-align:right">2.43</td>
<td style="text-align:right">2.38</td>
<td style="text-align:right">2.34</td>
<td style="text-align:right">2.30</td>
</tr>
<tr>
<td style="text-align:left"><strong>15</strong></td>
<td style="text-align:right">4.54</td>
<td style="text-align:right">3.68</td>
<td style="text-align:right">3.29</td>
<td style="text-align:right">3.06</td>
<td style="text-align:right">2.90</td>
<td style="text-align:right">2.79</td>
<td style="text-align:right">2.71</td>
<td style="text-align:right">2.64</td>
<td style="text-align:right">2.59</td>
<td style="text-align:right">2.54</td>
<td style="text-align:right">2.48</td>
<td style="text-align:right">2.40</td>
<td style="text-align:right">2.33</td>
<td style="text-align:right">2.29</td>
<td style="text-align:right">2.25</td>
<td style="text-align:right">2.20</td>
<td style="text-align:right">2.16</td>
<td style="text-align:right">2.11</td>
<td style="text-align:right">2.07</td>
</tr>
<tr>
<td style="text-align:left"><strong>20</strong></td>
<td style="text-align:right">4.35</td>
<td style="text-align:right">3.49</td>
<td style="text-align:right">3.10</td>
<td style="text-align:right">2.87</td>
<td style="text-align:right">2.71</td>
<td style="text-align:right">2.60</td>
<td style="text-align:right">2.51</td>
<td style="text-align:right">2.45</td>
<td style="text-align:right">2.39</td>
<td style="text-align:right">2.35</td>
<td style="text-align:right">2.28</td>
<td style="text-align:right">2.20</td>
<td style="text-align:right">2.12</td>
<td style="text-align:right">2.08</td>
<td style="text-align:right">2.04</td>
<td style="text-align:right">1.99</td>
<td style="text-align:right">1.95</td>
<td style="text-align:right">1.90</td>
<td style="text-align:right">1.84</td>
</tr>
<tr>
<td style="text-align:left"><strong>24</strong></td>
<td style="text-align:right">4.26</td>
<td style="text-align:right">3.40</td>
<td style="text-align:right">3.01</td>
<td style="text-align:right">2.78</td>
<td style="text-align:right">2.62</td>
<td style="text-align:right">2.51</td>
<td style="text-align:right">2.42</td>
<td style="text-align:right">2.36</td>
<td style="text-align:right">2.30</td>
<td style="text-align:right">2.25</td>
<td style="text-align:right">2.18</td>
<td style="text-align:right">2.11</td>
<td style="text-align:right">2.03</td>
<td style="text-align:right">1.98</td>
<td style="text-align:right">1.94</td>
<td style="text-align:right">1.89</td>
<td style="text-align:right">1.84</td>
<td style="text-align:right">1.79</td>
<td style="text-align:right">1.73</td>
</tr>
<tr>
<td style="text-align:left"><strong>30</strong></td>
<td style="text-align:right">4.17</td>
<td style="text-align:right">3.32</td>
<td style="text-align:right">2.92</td>
<td style="text-align:right">2.69</td>
<td style="text-align:right">2.53</td>
<td style="text-align:right">2.42</td>
<td style="text-align:right">2.33</td>
<td style="text-align:right">2.27</td>
<td style="text-align:right">2.21</td>
<td style="text-align:right">2.16</td>
<td style="text-align:right">2.09</td>
<td style="text-align:right">2.01</td>
<td style="text-align:right">1.93</td>
<td style="text-align:right">1.89</td>
<td style="text-align:right">1.84</td>
<td style="text-align:right">1.79</td>
<td style="text-align:right">1.74</td>
<td style="text-align:right">1.68</td>
<td style="text-align:right">1.62</td>
</tr>
<tr>
<td style="text-align:left"><strong>40</strong></td>
<td style="text-align:right">4.08</td>
<td style="text-align:right">3.23</td>
<td style="text-align:right">2.84</td>
<td style="text-align:right">2.61</td>
<td style="text-align:right">2.45</td>
<td style="text-align:right">2.34</td>
<td style="text-align:right">2.25</td>
<td style="text-align:right">2.18</td>
<td style="text-align:right">2.12</td>
<td style="text-align:right">2.08</td>
<td style="text-align:right">2.00</td>
<td style="text-align:right">1.92</td>
<td style="text-align:right">1.84</td>
<td style="text-align:right">1.79</td>
<td style="text-align:right">1.74</td>
<td style="text-align:right">1.69</td>
<td style="text-align:right">1.64</td>
<td style="text-align:right">1.58</td>
<td style="text-align:right">1.51</td>
</tr>
<tr>
<td style="text-align:left"><strong>60</strong></td>
<td style="text-align:right">4.00</td>
<td style="text-align:right">3.15</td>
<td style="text-align:right">2.76</td>
<td style="text-align:right">2.53</td>
<td style="text-align:right">2.37</td>
<td style="text-align:right">2.25</td>
<td style="text-align:right">2.17</td>
<td style="text-align:right">2.10</td>
<td style="text-align:right">2.04</td>
<td style="text-align:right">1.99</td>
<td style="text-align:right">1.92</td>
<td style="text-align:right">1.84</td>
<td style="text-align:right">1.75</td>
<td style="text-align:right">1.70</td>
<td style="text-align:right">1.65</td>
<td style="text-align:right">1.59</td>
<td style="text-align:right">1.53</td>
<td style="text-align:right">1.47</td>
<td style="text-align:right">1.39</td>
</tr>
<tr>
<td style="text-align:left"><strong>120</strong></td>
<td style="text-align:right">3.92</td>
<td style="text-align:right">3.07</td>
<td style="text-align:right">2.68</td>
<td style="text-align:right">2.45</td>
<td style="text-align:right">2.29</td>
<td style="text-align:right">2.18</td>
<td style="text-align:right">2.09</td>
<td style="text-align:right">2.02</td>
<td style="text-align:right">1.96</td>
<td style="text-align:right">1.91</td>
<td style="text-align:right">1.83</td>
<td style="text-align:right">1.75</td>
<td style="text-align:right">1.66</td>
<td style="text-align:right">1.61</td>
<td style="text-align:right">1.55</td>
<td style="text-align:right">1.50</td>
<td style="text-align:right">1.43</td>
<td style="text-align:right">1.35</td>
<td style="text-align:right">1.25</td>
</tr>
<tr>
<td style="text-align:left"><code>$\infty$</code></td>
<td style="text-align:right">3.84</td>
<td style="text-align:right">3.00</td>
<td style="text-align:right">2.60</td>
<td style="text-align:right">2.37</td>
<td style="text-align:right">2.21</td>
<td style="text-align:right">2.10</td>
<td style="text-align:right">2.01</td>
<td style="text-align:right">1.94</td>
<td style="text-align:right">1.88</td>
<td style="text-align:right">1.83</td>
<td style="text-align:right">1.75</td>
<td style="text-align:right">1.67</td>
<td style="text-align:right">1.57</td>
<td style="text-align:right">1.52</td>
<td style="text-align:right">1.46</td>
<td style="text-align:right">1.39</td>
<td style="text-align:right">1.32</td>
<td style="text-align:right">1.22</td>
<td style="text-align:right">1.00</td>
</tr>
</tbody>
</table>
<h5 id="texttable-5-99th-percentiles-of-the--fv_1v_2"><code>$\text{Table 5: 99th Percentiles of the } F(v_1,v_2)$</code></h5>
<table>
<thead>
<tr>
<th style="text-align:left"><code>$v_2 \big\backslash v_1$</code></th>
<th style="text-align:left">1</th>
<th style="text-align:left">2</th>
<th style="text-align:left">3</th>
<th style="text-align:left">4</th>
<th style="text-align:left">5</th>
<th style="text-align:left">6</th>
<th style="text-align:left">7</th>
<th style="text-align:left">8</th>
<th style="text-align:left">9</th>
<th style="text-align:left">10</th>
<th style="text-align:left">12</th>
<th style="text-align:left">15</th>
<th style="text-align:left">20</th>
<th style="text-align:left">24</th>
<th style="text-align:left">30</th>
<th style="text-align:left">40</th>
<th style="text-align:left">60</th>
<th style="text-align:left">120</th>
<th style="text-align:left"><code>$ \infty$</code></th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"><strong>1</strong></td>
<td style="text-align:left">4052</td>
<td style="text-align:left">5000</td>
<td style="text-align:left">5403</td>
<td style="text-align:left">5625</td>
<td style="text-align:left">5764</td>
<td style="text-align:left">5859</td>
<td style="text-align:left">5928</td>
<td style="text-align:left">5981</td>
<td style="text-align:left">6022</td>
<td style="text-align:left">6056</td>
<td style="text-align:left">6106</td>
<td style="text-align:left">6157</td>
<td style="text-align:left">6209</td>
<td style="text-align:left">6235</td>
<td style="text-align:left">6261</td>
<td style="text-align:left">6287</td>
<td style="text-align:left">6313</td>
<td style="text-align:left">6339</td>
<td style="text-align:left">6366</td>
</tr>
<tr>
<td style="text-align:left"><strong>2</strong></td>
<td style="text-align:left">98.50</td>
<td style="text-align:left">99.00</td>
<td style="text-align:left">99.17</td>
<td style="text-align:left">99.25</td>
<td style="text-align:left">99.30</td>
<td style="text-align:left">99.33</td>
<td style="text-align:left">99.36</td>
<td style="text-align:left">99.37</td>
<td style="text-align:left">99.39</td>
<td style="text-align:left">99.40</td>
<td style="text-align:left">99.42</td>
<td style="text-align:left">99.43</td>
<td style="text-align:left">99.45</td>
<td style="text-align:left">99.46</td>
<td style="text-align:left">99.47</td>
<td style="text-align:left">99.47</td>
<td style="text-align:left">99.48</td>
<td style="text-align:left">99.49</td>
<td style="text-align:left">99.50</td>
</tr>
<tr>
<td style="text-align:left"><strong>3</strong></td>
<td style="text-align:left">34.12</td>
<td style="text-align:left">30.82</td>
<td style="text-align:left">29.46</td>
<td style="text-align:left">28.71</td>
<td style="text-align:left">28.24</td>
<td style="text-align:left">27.91</td>
<td style="text-align:left">27.67</td>
<td style="text-align:left">27.49</td>
<td style="text-align:left">27.35</td>
<td style="text-align:left">27.23</td>
<td style="text-align:left">27.05</td>
<td style="text-align:left">26.87</td>
<td style="text-align:left">26.69</td>
<td style="text-align:left">26.60</td>
<td style="text-align:left">26.50</td>
<td style="text-align:left">26.41</td>
<td style="text-align:left">26.32</td>
<td style="text-align:left">26.22</td>
<td style="text-align:left">26.13</td>
</tr>
<tr>
<td style="text-align:left"><strong>4</strong></td>
<td style="text-align:left">21.20</td>
<td style="text-align:left">18.00</td>
<td style="text-align:left">16.69</td>
<td style="text-align:left">15.98</td>
<td style="text-align:left">15.52</td>
<td style="text-align:left">15.21</td>
<td style="text-align:left">14.98</td>
<td style="text-align:left">14.80</td>
<td style="text-align:left">14.66</td>
<td style="text-align:left">14.55</td>
<td style="text-align:left">14.37</td>
<td style="text-align:left">14.20</td>
<td style="text-align:left">14.02</td>
<td style="text-align:left">13.93</td>
<td style="text-align:left">13.84</td>
<td style="text-align:left">13.75</td>
<td style="text-align:left">13.65</td>
<td style="text-align:left">13.56</td>
<td style="text-align:left">13.46</td>
</tr>
<tr>
<td style="text-align:left"><strong>5</strong></td>
<td style="text-align:left">16.26</td>
<td style="text-align:left">13.27</td>
<td style="text-align:left">12.06</td>
<td style="text-align:left">11.39</td>
<td style="text-align:left">10.97</td>
<td style="text-align:left">10.67</td>
<td style="text-align:left">10.46</td>
<td style="text-align:left">10.29</td>
<td style="text-align:left">10.16</td>
<td style="text-align:left">10.05</td>
<td style="text-align:left">9.89</td>
<td style="text-align:left">9.72</td>
<td style="text-align:left">9.55</td>
<td style="text-align:left">9.47</td>
<td style="text-align:left">9.38</td>
<td style="text-align:left">9.29</td>
<td style="text-align:left">9.20</td>
<td style="text-align:left">9.11</td>
<td style="text-align:left">9.02</td>
</tr>
<tr>
<td style="text-align:left"><strong>6</strong></td>
<td style="text-align:left">13.75</td>
<td style="text-align:left">10.92</td>
<td style="text-align:left">9.78</td>
<td style="text-align:left">9.15</td>
<td style="text-align:left">8.75</td>
<td style="text-align:left">8.47</td>
<td style="text-align:left">8.26</td>
<td style="text-align:left">8.10</td>
<td style="text-align:left">7.98</td>
<td style="text-align:left">7.87</td>
<td style="text-align:left">7.72</td>
<td style="text-align:left">7.56</td>
<td style="text-align:left">7.40</td>
<td style="text-align:left">7.31</td>
<td style="text-align:left">7.23</td>
<td style="text-align:left">7.14</td>
<td style="text-align:left">7.06</td>
<td style="text-align:left">6.97</td>
<td style="text-align:left">6.88</td>
</tr>
<tr>
<td style="text-align:left"><strong>7</strong></td>
<td style="text-align:left">12.25</td>
<td style="text-align:left">9.55</td>
<td style="text-align:left">8.45</td>
<td style="text-align:left">7.85</td>
<td style="text-align:left">7.46</td>
<td style="text-align:left">7.19</td>
<td style="text-align:left">6.99</td>
<td style="text-align:left">6.84</td>
<td style="text-align:left">6.72</td>
<td style="text-align:left">6.62</td>
<td style="text-align:left">6.47</td>
<td style="text-align:left">6.31</td>
<td style="text-align:left">6.16</td>
<td style="text-align:left">6.07</td>
<td style="text-align:left">5.99</td>
<td style="text-align:left">5.91</td>
<td style="text-align:left">5.82</td>
<td style="text-align:left">5.74</td>
<td style="text-align:left">5.65</td>
</tr>
<tr>
<td style="text-align:left"><strong>8</strong></td>
<td style="text-align:left">11.26</td>
<td style="text-align:left">8.65</td>
<td style="text-align:left">7.59</td>
<td style="text-align:left">7.01</td>
<td style="text-align:left">6.63</td>
<td style="text-align:left">6.37</td>
<td style="text-align:left">6.18</td>
<td style="text-align:left">6.03</td>
<td style="text-align:left">5.91</td>
<td style="text-align:left">5.81</td>
<td style="text-align:left">5.67</td>
<td style="text-align:left">5.52</td>
<td style="text-align:left">5.36</td>
<td style="text-align:left">5.28</td>
<td style="text-align:left">5.20</td>
<td style="text-align:left">5.12</td>
<td style="text-align:left">5.03</td>
<td style="text-align:left">4.95</td>
<td style="text-align:left">4.86</td>
</tr>
<tr>
<td style="text-align:left"><strong>9</strong></td>
<td style="text-align:left">10.56</td>
<td style="text-align:left">8.02</td>
<td style="text-align:left">6.99</td>
<td style="text-align:left">6.42</td>
<td style="text-align:left">6.06</td>
<td style="text-align:left">5.80</td>
<td style="text-align:left">5.61</td>
<td style="text-align:left">5.47</td>
<td style="text-align:left">5.35</td>
<td style="text-align:left">5.26</td>
<td style="text-align:left">5.11</td>
<td style="text-align:left">4.96</td>
<td style="text-align:left">4.81</td>
<td style="text-align:left">4.73</td>
<td style="text-align:left">4.65</td>
<td style="text-align:left">4.57</td>
<td style="text-align:left">4.48</td>
<td style="text-align:left">4.40</td>
<td style="text-align:left">4.31</td>
</tr>
<tr>
<td style="text-align:left"><strong>10</strong></td>
<td style="text-align:left">10.04</td>
<td style="text-align:left">7.56</td>
<td style="text-align:left">6.55</td>
<td style="text-align:left">5.99</td>
<td style="text-align:left">5.64</td>
<td style="text-align:left">5.39</td>
<td style="text-align:left">5.20</td>
<td style="text-align:left">5.06</td>
<td style="text-align:left">4.94</td>
<td style="text-align:left">4.85</td>
<td style="text-align:left">4.71</td>
<td style="text-align:left">4.56</td>
<td style="text-align:left">4.41</td>
<td style="text-align:left">4.33</td>
<td style="text-align:left">4.25</td>
<td style="text-align:left">4.17</td>
<td style="text-align:left">4.08</td>
<td style="text-align:left">4.00</td>
<td style="text-align:left">3.91</td>
</tr>
<tr>
<td style="text-align:left"><strong>12</strong></td>
<td style="text-align:left">9.33</td>
<td style="text-align:left">6.93</td>
<td style="text-align:left">5.95</td>
<td style="text-align:left">5.41</td>
<td style="text-align:left">5.06</td>
<td style="text-align:left">4.82</td>
<td style="text-align:left">4.64</td>
<td style="text-align:left">4.50</td>
<td style="text-align:left">4.39</td>
<td style="text-align:left">4.30</td>
<td style="text-align:left">4.16</td>
<td style="text-align:left">4.01</td>
<td style="text-align:left">3.86</td>
<td style="text-align:left">3.78</td>
<td style="text-align:left">3.70</td>
<td style="text-align:left">3.62</td>
<td style="text-align:left">3.54</td>
<td style="text-align:left">3.45</td>
<td style="text-align:left">3.36</td>
</tr>
<tr>
<td style="text-align:left"><strong>15</strong></td>
<td style="text-align:left">8.68</td>
<td style="text-align:left">6.36</td>
<td style="text-align:left">5.42</td>
<td style="text-align:left">4.89</td>
<td style="text-align:left">4.56</td>
<td style="text-align:left">4.32</td>
<td style="text-align:left">4.14</td>
<td style="text-align:left">4.00</td>
<td style="text-align:left">3.89</td>
<td style="text-align:left">3.80</td>
<td style="text-align:left">3.67</td>
<td style="text-align:left">3.52</td>
<td style="text-align:left">3.37</td>
<td style="text-align:left">3.29</td>
<td style="text-align:left">3.21</td>
<td style="text-align:left">3.13</td>
<td style="text-align:left">3.05</td>
<td style="text-align:left">2.96</td>
<td style="text-align:left">2.87</td>
</tr>
<tr>
<td style="text-align:left"><strong>20</strong></td>
<td style="text-align:left">8.10</td>
<td style="text-align:left">5.85</td>
<td style="text-align:left">4.94</td>
<td style="text-align:left">4.43</td>
<td style="text-align:left">4.10</td>
<td style="text-align:left">3.87</td>
<td style="text-align:left">3.70</td>
<td style="text-align:left">3.56</td>
<td style="text-align:left">3.46</td>
<td style="text-align:left">3.37</td>
<td style="text-align:left">3.23</td>
<td style="text-align:left">3.09</td>
<td style="text-align:left">2.94</td>
<td style="text-align:left">2.86</td>
<td style="text-align:left">2.78</td>
<td style="text-align:left">2.69</td>
<td style="text-align:left">2.61</td>
<td style="text-align:left">2.52</td>
<td style="text-align:left">2.42</td>
</tr>
<tr>
<td style="text-align:left"><strong>24</strong></td>
<td style="text-align:left">7.82</td>
<td style="text-align:left">5.61</td>
<td style="text-align:left">4.72</td>
<td style="text-align:left">4.22</td>
<td style="text-align:left">3.90</td>
<td style="text-align:left">3.67</td>
<td style="text-align:left">3.50</td>
<td style="text-align:left">3.36</td>
<td style="text-align:left">3.26</td>
<td style="text-align:left">3.17</td>
<td style="text-align:left">3.03</td>
<td style="text-align:left">2.89</td>
<td style="text-align:left">2.74</td>
<td style="text-align:left">2.66</td>
<td style="text-align:left">2.58</td>
<td style="text-align:left">2.49</td>
<td style="text-align:left">2.40</td>
<td style="text-align:left">2.31</td>
<td style="text-align:left">2.21</td>
</tr>
<tr>
<td style="text-align:left"><strong>30</strong></td>
<td style="text-align:left">7.56</td>
<td style="text-align:left">5.39</td>
<td style="text-align:left">4.51</td>
<td style="text-align:left">4.02</td>
<td style="text-align:left">3.70</td>
<td style="text-align:left">3.47</td>
<td style="text-align:left">3.30</td>
<td style="text-align:left">3.17</td>
<td style="text-align:left">3.07</td>
<td style="text-align:left">2.98</td>
<td style="text-align:left">2.84</td>
<td style="text-align:left">2.70</td>
<td style="text-align:left">2.55</td>
<td style="text-align:left">2.47</td>
<td style="text-align:left">2.39</td>
<td style="text-align:left">2.30</td>
<td style="text-align:left">2.21</td>
<td style="text-align:left">2.11</td>
<td style="text-align:left">2.01</td>
</tr>
<tr>
<td style="text-align:left"><strong>40</strong></td>
<td style="text-align:left">7.31</td>
<td style="text-align:left">5.18</td>
<td style="text-align:left">4.31</td>
<td style="text-align:left">3.83</td>
<td style="text-align:left">3.51</td>
<td style="text-align:left">3.29</td>
<td style="text-align:left">3.12</td>
<td style="text-align:left">2.99</td>
<td style="text-align:left">2.89</td>
<td style="text-align:left">2.80</td>
<td style="text-align:left">2.66</td>
<td style="text-align:left">2.52</td>
<td style="text-align:left">2.37</td>
<td style="text-align:left">2.29</td>
<td style="text-align:left">2.20</td>
<td style="text-align:left">2.11</td>
<td style="text-align:left">2.02</td>
<td style="text-align:left">1.92</td>
<td style="text-align:left">1.80</td>
</tr>
<tr>
<td style="text-align:left"><strong>60</strong></td>
<td style="text-align:left">7.08</td>
<td style="text-align:left">4.98</td>
<td style="text-align:left">4.13</td>
<td style="text-align:left">3.65</td>
<td style="text-align:left">3.34</td>
<td style="text-align:left">3.12</td>
<td style="text-align:left">2.95</td>
<td style="text-align:left">2.82</td>
<td style="text-align:left">2.72</td>
<td style="text-align:left">2.63</td>
<td style="text-align:left">2.50</td>
<td style="text-align:left">2.35</td>
<td style="text-align:left">2.20</td>
<td style="text-align:left">2.12</td>
<td style="text-align:left">2.03</td>
<td style="text-align:left">1.94</td>
<td style="text-align:left">1.84</td>
<td style="text-align:left">1.73</td>
<td style="text-align:left">1.60</td>
</tr>
<tr>
<td style="text-align:left"><strong>120</strong></td>
<td style="text-align:left">6.85</td>
<td style="text-align:left">4.79</td>
<td style="text-align:left">3.95</td>
<td style="text-align:left">3.48</td>
<td style="text-align:left">3.17</td>
<td style="text-align:left">2.96</td>
<td style="text-align:left">2.79</td>
<td style="text-align:left">2.66</td>
<td style="text-align:left">2.56</td>
<td style="text-align:left">2.47</td>
<td style="text-align:left">2.34</td>
<td style="text-align:left">2.19</td>
<td style="text-align:left">2.03</td>
<td style="text-align:left">1.95</td>
<td style="text-align:left">1.86</td>
<td style="text-align:left">1.76</td>
<td style="text-align:left">1.66</td>
<td style="text-align:left">1.53</td>
<td style="text-align:left">1.38</td>
</tr>
<tr>
<td style="text-align:left"><code>$\infty$</code></td>
<td style="text-align:left">6.63</td>
<td style="text-align:left">4.61</td>
<td style="text-align:left">3.78</td>
<td style="text-align:left">3.32</td>
<td style="text-align:left">3.02</td>
<td style="text-align:left">2.80</td>
<td style="text-align:left">2.64</td>
<td style="text-align:left">2.51</td>
<td style="text-align:left">2.41</td>
<td style="text-align:left">2.32</td>
<td style="text-align:left">2.18</td>
<td style="text-align:left">2.04</td>
<td style="text-align:left">1.88</td>
<td style="text-align:left">1.79</td>
<td style="text-align:left">1.70</td>
<td style="text-align:left">1.59</td>
<td style="text-align:left">1.47</td>
<td style="text-align:left">1.32</td>
<td style="text-align:left">1.00</td>
</tr>
</tbody>
</table>
]]></description>
        </item>
        
        <item>
            <title>Queueing Notation</title>
            <link>https://roh.engineering/posts/2018/01/queueing-notation/</link>
            <pubDate>Sat, 13 Jan 2018 00:00:00 +0000</pubDate>
            
            <guid>https://roh.engineering/posts/2018/01/queueing-notation/</guid>
            <description><![CDATA[<p>Queueing theory has some commonly accepted shorthand to describe characteristics
of queuing models. Although across books and peer reviewed articles you will see
slight variations, this post outlines commonly accepted terms for reference.</p>
<h1 id="kendalls-notation">Kendall&rsquo;s Notation</h1>
<p>Kendall&rsquo;s notation was proposed as a standard for describing queueing models.
You may see some queueing models that omit the last two elements. The <em>Y</em> and
<em>Z</em> typically default to infinite and FCFS. The table below illustrates the
standard:</p>
<p><code>$$A/B/X/Y/Z$$</code></p>
<center>
<table class='gmisc_table' style='border-collapse: collapse; margin-top: 1em; margin-bottom: 1em;' >
<thead>
<tr>
<th style='font-weight: 900; border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;'>Notation</th>
<th style='font-weight: 900; border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;'>Description</th>
<th style='font-weight: 900; border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;'>Characteristic</th>
</tr>
</thead>
<tbody>
<tr>
<td style='text-align: center;'>A</td>
<td style='text-align: center;'>Interarrival Distribution</td>
<td style='text-align: center;'>Markovian, Deterministic, General</td>
</tr>
<tr>
<td style='text-align: center;'>B</td>
<td style='text-align: center;'>Service Time Distribution</td>
<td style='text-align: center;'>Markovian, Deterministic, General</td>
</tr>
<tr>
<td style='text-align: center;'>X</td>
<td style='text-align: center;'>Parallel Servers</td>
<td style='text-align: center;'>positive integer, infinity</td>
</tr>
<tr>
<td style='text-align: center;'>Y</td>
<td style='text-align: center;'>Max Queue Size</td>
<td style='text-align: center;'>non-negative integer, infinity</td>
</tr>
<tr>
<td style='border-bottom: 2px solid grey; text-align: center;'>Z</td>
<td style='border-bottom: 2px solid grey; text-align: center;'>Queue Discipline</td>
<td style='border-bottom: 2px solid grey; text-align: center;'>FCFS, LCFS, Random, Priority, General Discipline</td>
</tr>
</tbody>
</table>
</center>
<h2 id="interarrival-distribution">Interarrival Distribution</h2>
<p>The rate at which entities arrive to a queueing system to be processed. E.g.
customers arrive every 5 minutes or 12 customers arriver per hour.</p>
<h2 id="service-time-distribution">Service Time Distribution</h2>
<p>The rate at which entities are processed by a server in a queueing system. E.g.
Customers are serviced in 5 minutes or 12 customers are serviced per hour.</p>
<h3 id="distribution-classifications">Distribution Classifications</h3>
<h4 id="markovian-distributions">Markovian Distributions</h4>
<p>Markovian distributions, though few meet this classification, are
a very important in many queueing models and theory. They have one important
property that is <a href="https://en.wikipedia.org/wiki/Memorylessness">memorylessness</a>.
For distributions that are memoryless, the current sample from the distribution is
not dependent on the prior sample. In queueing context, an entity&rsquo;s current
processing time is independent on how much longer it will take to process. Markovian distributions are the
<a href="https://en.wikipedia.org/wiki/Exponential_distribution">exponential</a>,
<a href="https://en.wikipedia.org/wiki/Geometric_distribution">geometric</a>, and
<a href="https://en.wikipedia.org/wiki/Poisson_distribution">poisson</a>.
The exponential and poisson are the most commonly used and are closely
<a href="https://stats.stackexchange.com/questions/2092/relationship-between-poisson-and-exponential-distribution">related</a>. The shorthand
notation is <em>M</em>.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">library</span>(ggplot2)
<span style="color:#a6e22e">library</span>(trstyles)
x <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">data.frame</span>(x <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span><span style="color:#f92672">:</span><span style="color:#ae81ff">5</span>)
rate <span style="color:#f92672">&lt;-</span> <span style="color:#ae81ff">1</span><span style="color:#f92672">:</span><span style="color:#ae81ff">5</span>
rateGroups <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">factor</span>(<span style="color:#ae81ff">1</span><span style="color:#f92672">:</span><span style="color:#ae81ff">5</span>)
e <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">ggplot</span>(x, <span style="color:#a6e22e">aes</span>(x <span style="color:#f92672">=</span> x)) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">labs</span>(y <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;density&#39;</span>, title <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;Exponential PDF&#39;</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">theme_tr</span>()
<span style="color:#a6e22e">for </span>(i in <span style="color:#ae81ff">1</span><span style="color:#f92672">:</span><span style="color:#ae81ff">5</span>) {
e <span style="color:#f92672">&lt;-</span> e <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">stat_function</span>(fun <span style="color:#f92672">=</span> dexp, 
                <span style="color:#a6e22e">aes_</span>(color <span style="color:#f92672">=</span> rateGroups[i]),
                args <span style="color:#f92672">=</span> <span style="color:#a6e22e">list</span>(rate <span style="color:#f92672">=</span> rate[i]),
                size <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>)
}
e <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">scale_color_tr</span>(name <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;Rate&#34;</span>,
                 breaks <span style="color:#f92672">=</span> rateGroups)
</code></pre></div><p><img src="https://roh.engineering/posts/2018/01/queueing-notation/index_files/figure-html/markovian-1.svg" width="672" style="display: block; margin: auto;" /></p>
<h4 id="deterministic-distributions">Deterministic Distributions</h4>
<p>Deterministic means that the rate is always the same. It is a constant. The shorthand notation is <em>D</em>.</p>
<h4 id="general-distributions">General Distributions</h4>
<p>General probability distributions refer to when you make no assumptions
on the shape and form. It can be any probability distribution. The shorthand
notation is <em>G</em>. Below are some common distributions:</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">library</span>(fitur)
<span style="color:#a6e22e">library</span>(actuar)
<span style="color:#a6e22e">set.seed</span>(<span style="color:#ae81ff">438</span>)
x <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">rweibull</span>(<span style="color:#ae81ff">10000</span>, shape <span style="color:#f92672">=</span> <span style="color:#ae81ff">5</span>, scale <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>)
dists <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">c</span>(<span style="color:#e6db74">&#39;gamma&#39;</span>, <span style="color:#e6db74">&#39;lnorm&#39;</span>, <span style="color:#e6db74">&#39;weibull&#39;</span>, <span style="color:#e6db74">&#39;gamma&#39;</span>, <span style="color:#e6db74">&#39;llogis&#39;</span>)
fits <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">lapply</span>(dists, fit_univariate, x <span style="color:#f92672">=</span> x)
<span style="color:#a6e22e">plot_density</span>(x, fits, nbins <span style="color:#f92672">=</span> <span style="color:#ae81ff">30</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">scale_color_tr</span>(name <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;Distribution&#39;</span>) <span style="color:#f92672">+</span>
  <span style="color:#a6e22e">theme_tr</span>()
</code></pre></div><p><img src="https://roh.engineering/posts/2018/01/queueing-notation/index_files/figure-html/general-1.svg" width="672" style="display: block; margin: auto;" /></p>
<h2 id="parallel-servers">Parallel Servers</h2>
<p>The number of workers, servers, machines, etc. available to process entities.
An infinite server queue will have no waiting times since there is always
server capacity. Values include:</p>
<p><code>$$1,\:2,\:...,\:\infty$$</code></p>
<h2 id="maximum-queue-size">Maximum Queue Size</h2>
<p>The number of entities that are allowed to wait in the queue when all servers
are busy. Entities that arrive when the queue is full leave the queueing system.
Values include:</p>
<p><code>$$0,\:1,\:...,\:\infty$$</code></p>
<h2 id="queue-discipline">Queue Discipline</h2>
<p>The queue discipline refers to how entities are assigned to servers.</p>
<ul>
<li>First Come First Serve (FCFS)
<ul>
<li>Entities are prioritized by earliest arrival time</li>
<li>Customers waiting to checkout at a grocery store</li>
</ul>
</li>
<li>Last Come First Serve (LCFS)
<ul>
<li>Entities are prioritized by latest arrival time</li>
<li>A worker answering emails from the top of the inbox</li>
</ul>
</li>
<li>Random
<ul>
<li>All entities have equal probability of being selected</li>
<li>Customers waiting to be served at a bar</li>
</ul>
</li>
<li>Priority
<ul>
<li>Entities have some characteristics that would prioritize them over other
entities even if the other entities have been waiting longer.</li>
<li>Patients in an emergency department with assigned acuity</li>
</ul>
</li>
</ul>
<h1 id="mathematical-queueing-notation">Mathematical Queueing Notation</h1>
<p>$$\rho $$</p>
<center>Utilization</center>
<p><code>$$\mu$$</code></p>
<center>Service Rate </center>
<p><code>$$\lambda$$</code></p>
<center>Arrival Rate</center>
<p><code>$$c$$</code></p>
<center>number of parallel servers</center>
<p><code>$$W$$</code></p>
<center>Waiting time in system</center>
<p><code>$$W_q$$</code></p>
<center>Waiting time in queue</center>
<p><code>$$L$$</code></p>
<center>Entities in system</center>
<p><code>$$L_q$$</code></p>
<center>Entities in queue</center>
<p><code>$$L = \lambda W, L_q = \lambda W_q$$</code></p>
<center>Little's Law
<p><code>$$p_0$$</code></p>
<center>Probably of zero servers being busy</center>
<p><code>$$p_n$$</code></p>
<center>Probability of n servers being busy</center>
<p><code>$$r$$</code></p>
<center>Offered Load</center>
]]></description>
        </item>
        
        <item>
            <title>fitur 0.5.20 Release</title>
            <link>https://roh.engineering/posts/2017/12/fitur-0.5.20-release/</link>
            <pubDate>Wed, 20 Dec 2017 00:00:00 +0000</pubDate>
            
            <guid>https://roh.engineering/posts/2017/12/fitur-0.5.20-release/</guid>
            <description><![CDATA[<ul>
<li>
<p>DESCRIPTION summary has been updated</p>
</li>
<li>
<p>Examples have been updated for fit_univariate, fit_empirical</p>
</li>
<li>
<p>fit_empirical_discrete and fit_empirical_continuous are no longer exported</p>
</li>
<li>
<p>added plot_qq and plot_pp functions for diagnostic plotting of fits</p>
</li>
<li>
<p>Added a vignette Diagnostic Plots for Fitting Distributions</p>
</li>
<li>
<p>Introduction vignette has updated examples</p>
</li>
</ul>
<p>fitur on <a href="https://cran.r-project.org/web/packages/fitur/index.html">CRAN</a></p>
]]></description>
        </item>
        
        <item>
            <title>MMC Queues</title>
            <link>https://roh.engineering/posts/2017/12/mmc-queues/</link>
            <pubDate>Sun, 03 Dec 2017 00:00:00 +0000</pubDate>
            
            <guid>https://roh.engineering/posts/2017/12/mmc-queues/</guid>
            <description><![CDATA[<script src="https://roh.engineering/posts/2017/12/mmc-queues/index_files/htmlwidgets/htmlwidgets.js"></script>
<script src="https://roh.engineering/posts/2017/12/mmc-queues/index_files/viz/viz.js"></script>
<link href="https://roh.engineering/posts/2017/12/mmc-queues/index_files/DiagrammeR-styles/styles.css" rel="stylesheet" />
<script src="https://roh.engineering/posts/2017/12/mmc-queues/index_files/grViz-binding/grViz.js"></script>
<script src="https://roh.engineering/posts/2017/12/mmc-queues/index_files/htmlwidgets/htmlwidgets.js"></script>
<script src="https://roh.engineering/posts/2017/12/mmc-queues/index_files/viz/viz.js"></script>
<link href="https://roh.engineering/posts/2017/12/mmc-queues/index_files/DiagrammeR-styles/styles.css" rel="stylesheet" />
<script src="https://roh.engineering/posts/2017/12/mmc-queues/index_files/grViz-binding/grViz.js"></script>
<h1 id="introduction">Introduction</h1>
<p>Queueing Theory is the quantitative study of operational characteristics of a system of workflows for a service/process given a processing time, an arrival pattern, and a limitation of resources. It can answer questions such as:</p>
<ul>
<li>How long would a customer/part/etc. (entities) wait to be processed?</li>
<li>What is the probability of <em>x</em> or more entities being in the system at the same time?</li>
<li>What is my expected utilization of resources?</li>
</ul>
<p>A queue or waiting line is a natural occurence in a system when the demand of customers exceeds the currently available resources that can serve that demand. Queues occur everywhere in our daily life at the grocery store, movie theatre, emergency room, and restaurants.</p>
<h1 id="a-simple-queue">A Simple Queue</h1>
<p>The simplest model has an arrival pattern represented by a distribution of interarrival times. Typically, this is represented as an exponential distribution, which has the property of the mean being equal to the variance. This implies a large amount of variability as to when a entity is ready for processing. The second assumption is that the entity will be processed in the system given a service rate distribution. For simplicity we will start with a service rate that also follows an exponential distribution. The system is represented in the figure below in three stages: Arrival, Processing, and Exit.</p>
<div id="htmlwidget-1" style="width:672px;height:200px;" class="grViz html-widget"></div>
<script type="application/json" data-for="htmlwidget-1">{"x":{"diagram":"digraph simpleQueue {\n  graph[label = \"Simple Queue\"]\n\n  a[label = \"\", color = \"white\"];\n  b[label = \"Server\"];\n  c[label = \"\", color = \"white\"]\n     a -> b [label = \"Arrival Rate\"];\n     b -> c [label = \"Service Rate\"];\n  {rank = same; a, b, c}\n }","config":{"engine":"dot","options":null}},"evals":[],"jsHooks":[]}</script>
<h1 id="queue-modeling">Queue Modeling</h1>
<p>The queue model sets up the system as states of workload in a steady state. Steady state refers to if the system were to run continuously where would it reach equilibrium. The figure below illustrates the modeling in a birth-death process. The state is the number of entities in the system represented by the numbers in the ellipses. The transition rates represent the entrances and exits to each of those states.</p>
<div id="htmlwidget-2" style="width:700px;height:200px;" class="grViz html-widget"></div>
<script type="application/json" data-for="htmlwidget-2">{"x":{"diagram":"digraph birthdeath {\n  \n  graph[label = \"Birth-Death Process\"]\n\n  a[label = \"0\", size = 25];\n  b[label = \"1\"];\n  c[label = \"2\"];\n  d[label = \"3\"];\n  e[label = \"\", color = \"white\"];\n  f[label = \"\", color = \"white\"];\n  g[label = \"c\"];\n  a -> b [label = <&#955;<SUB>0<\/SUB>>];\n  b -> a [label = <&#956;<sub>1<\/sub>>];\n  b -> c [label = <&#955;<sub>1<\/sub>>];\n  c -> b [label = <&#956;<sub>2<\/sub>>];\n  c -> d [label = <&#955;<sub>2<\/sub>>];\n  d -> c [label = <&#956;<sub>3<\/sub>>];\n  d -> e [label = <&#955;<sub>3<\/sub>>];\n  e -> d [label = <&#956;<sub>4<\/sub>>];\n  e -> f [arrowhead = \"none\", style = \"dotted\"];\n  \n  g -> f [label = <&#956;<sub>c<\/sub>>];\n  f -> g [label = <&#955;<sub>c-1<\/sub>>];\n  \n  {rank = same; a, b, c, d, e, f, g}\n }","config":{"engine":"dot","options":null}},"evals":[],"jsHooks":[]}</script>
<p><code>\(\mu\)</code> represents the transitional service rate and <code>\(\lambda\)</code> represents the transitional arrival rate to the next state. c represents the number of servers that are currently busy.</p>
<h1 id="mmc-queue">M/M/C Queue</h1>
<p>An M/M/C queue is shorthand notation for Markovian arrival rate, Markovian Service Rate, and C the number of resources. In another <a href="https://roh.engineering/post/queueing-notation">post</a> I will dive into Queueing Theory notation and distribution classifications. The <code>queueing</code> package in R makes it very easy to set up queue models. Below, I have created a model that assumes an exponential arrival rate, an exponential service rate, and a limited number of resources processing the entities.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-r" data-lang="r"><span style="color:#a6e22e">library</span>(queueing)
arrivalRate <span style="color:#f92672">&lt;-</span> <span style="color:#ae81ff">4</span> <span style="color:#75715e">#arrivals per hour</span>
serviceRate <span style="color:#f92672">&lt;-</span> <span style="color:#ae81ff">1</span> <span style="color:#75715e">#entities processed per hour</span>
resources <span style="color:#f92672">&lt;-</span> <span style="color:#ae81ff">5</span>

mmcInput <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">NewInput.MMC</span>(arrivalRate, serviceRate, resources)
mmcQueue <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">QueueingModel</span>(mmcInput)
</code></pre></div><p>The expected utilization is 0.8.</p>
<p>The average waiting time in the queue is 0.55 hours.</p>
<p>The average number of entities in the system is 6.22.</p>
<h1 id="mmc-shiny-app">M/M/C Shiny App</h1>
<p>I’ve created a Shiny App that allows the user to play around with the inputs to a M/M/C queueing model and perform sensitivy analysis on varying the number of resources (servers in this case). Try it <a href="https://troh.shinyapps.io/MMCQueue/">here</a>:</p>
<iframe src="https://troh.shinyapps.io/MMCQueue/" width="100%" height="800px">
</iframe>
]]></description>
        </item>
        
    </channel>
</rss>
