Skip to content

Commit

Permalink
fix white lines in Power plots
Browse files Browse the repository at this point in the history
  • Loading branch information
ccmothes committed Sep 27, 2024
1 parent 3e8216c commit 71cf076
Show file tree
Hide file tree
Showing 14 changed files with 19 additions and 19 deletions.
8 changes: 4 additions & 4 deletions 08-power.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ penguins %>%
filter(species %in% c("Adelie", "Gentoo")) %>%
ggplot() +
geom_histogram(aes(x = bill_length_mm, fill = species), alpha = 0.50) +
geom_vline(xintercept = 38.8) +
geom_vline(xintercept = 47.5)
geom_vline(xintercept = 38.8, col = "black") +
geom_vline(xintercept = 47.5, col = "black")
```

In the grand scheme of things the difference between these two populations is relatively small in magnitude: their histograms overlap, indicating that some penguins in both species often have similar bill lengths. But, what if the bills of all of the Gentoo penguins *magically* grew an extra 15 mm?
Expand All @@ -116,8 +116,8 @@ penguins %>%
mutate(bill_length_mm = if_else(species == "Gentoo", bill_length_mm + 15, bill_length_mm)) %>%
ggplot() +
geom_histogram(aes(x = bill_length_mm, fill = species), alpha = 0.56) +
geom_vline(xintercept = 38.8) +
geom_vline(xintercept = 62.5) # I found this from the new mutated values separately
geom_vline(xintercept = 38.8, col = "black") +
geom_vline(xintercept = 62.5, col = "black") # I found this from the new mutated values separately
```

And now perform the t-test on this new *magical* data:
Expand Down
Binary file modified _bookdown_files/_main_files/figure-html/unnamed-chunk-162-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified _bookdown_files/_main_files/figure-html/unnamed-chunk-163-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified _bookdown_files/_main_files/figure-html/unnamed-chunk-6-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified _bookdown_files/_main_files/figure-html/unnamed-chunk-7-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_main_files/figure-html/unnamed-chunk-162-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_main_files/figure-html/unnamed-chunk-163-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_main_files/figure-html/unnamed-chunk-6-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_main_files/figure-html/unnamed-chunk-7-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/correlation-and-simple-linear-regression.html
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,13 @@ <h5><span class="header-section-number">7.1.0.1.1</span> Parametric vs. non-par
## Shapiro-Wilk normality test
##
## data: sal_sub$length_2_mm
## W = 0.93331, p-value &lt; 2.2e-16</code></pre>
## W = 0.93584, p-value &lt; 2.2e-16</code></pre>
<div class="sourceCode" id="cb151"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb151-1"><a href="correlation-and-simple-linear-regression.html#cb151-1" tabindex="-1"></a><span class="fu">shapiro.test</span>(sal_sub<span class="sc">$</span>weight_g)</span></code></pre></div>
<pre><code>##
## Shapiro-Wilk normality test
##
## data: sal_sub$weight_g
## W = 0.56817, p-value &lt; 2.2e-16</code></pre>
## W = 0.5666, p-value &lt; 2.2e-16</code></pre>
<p>The <strong>null hypothesis of the Shapiro-Wilk normality test is that the variable is normally distributed</strong>, so a p-value less than 0.05, at 95% confidence (as we see for both of our variables here) tells use that <em>our data does not fit a normal distribution</em>.</p>
<p>Therefore we have two options as we did with our t-test example in the previous lesson: transform the variables and see if that helps, or use a non-parametric test. Here, we will go ahead with the non-parametric Spearman correlation test.</p>
<div class="alert alert-info">
Expand Down
4 changes: 2 additions & 2 deletions docs/data-visualization-in-r.html

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions docs/power.html
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,9 @@ <h4><span class="header-section-number">9.0.1.1</span> Sample size<a href="power
<span id="cb181-8"><a href="power.html#cb181-8" tabindex="-1"></a> <span class="fu">ungroup</span>() <span class="sc">%&gt;%</span> </span>
<span id="cb181-9"><a href="power.html#cb181-9" tabindex="-1"></a> <span class="fu">t_test</span>(bill_length_mm <span class="sc">~</span> species, <span class="at">var.equal =</span> <span class="cn">FALSE</span>, <span class="at">detailed =</span> <span class="cn">TRUE</span>)</span></code></pre></div>
<pre><code>## # A tibble: 1 × 15
## estimate estimate1 estimate2 .y. group1 group2 n1 n2 statistic p df conf.low
## * &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;chr&gt; &lt;chr&gt; &lt;chr&gt; &lt;int&gt; &lt;int&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;
## 1 -13.4 37.2 50.6 bill_length_… Adelie Gentoo 2 2 -15.7 0.00449 1.95 -17.2
## estimate estimate1 estimate2 .y. group1 group2 n1 n2 statistic p df conf.low
## * &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;chr&gt; &lt;chr&gt; &lt;chr&gt; &lt;int&gt; &lt;int&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;
## 1 -8.65 39.6 48.3 bill_length_mm Adelie Gentoo 2 2 -4.20 0.0884 1.45 -21.7
## # ℹ 3 more variables: conf.high &lt;dbl&gt;, method &lt;chr&gt;, alternative &lt;chr&gt;</code></pre>
<p>Compared to the p-value in the previous test, this p-value is much larger and, depending on which random samples were chosen in <code>slice_sample</code>, likely higher than our cut-off of 0.05 and would lead to an insignificant difference in bill length between the two species.</p>
<p>Therefore, as sample size decreases, so does our power in identifying true trends.</p>
Expand All @@ -382,8 +382,8 @@ <h4><span class="header-section-number">9.0.1.2</span> Magnitude of effect<a hre
<span id="cb183-2"><a href="power.html#cb183-2" tabindex="-1"></a> <span class="fu">filter</span>(species <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">&quot;Adelie&quot;</span>, <span class="st">&quot;Gentoo&quot;</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb183-3"><a href="power.html#cb183-3" tabindex="-1"></a> <span class="fu">ggplot</span>() <span class="sc">+</span></span>
<span id="cb183-4"><a href="power.html#cb183-4" tabindex="-1"></a> <span class="fu">geom_histogram</span>(<span class="fu">aes</span>(<span class="at">x =</span> bill_length_mm, <span class="at">fill =</span> species), <span class="at">alpha =</span> <span class="fl">0.50</span>) <span class="sc">+</span></span>
<span id="cb183-5"><a href="power.html#cb183-5" tabindex="-1"></a> <span class="fu">geom_vline</span>(<span class="at">xintercept =</span> <span class="fl">38.8</span>) <span class="sc">+</span></span>
<span id="cb183-6"><a href="power.html#cb183-6" tabindex="-1"></a> <span class="fu">geom_vline</span>(<span class="at">xintercept =</span> <span class="fl">47.5</span>)</span></code></pre></div>
<span id="cb183-5"><a href="power.html#cb183-5" tabindex="-1"></a> <span class="fu">geom_vline</span>(<span class="at">xintercept =</span> <span class="fl">38.8</span>, <span class="at">col =</span> <span class="st">&quot;black&quot;</span>) <span class="sc">+</span></span>
<span id="cb183-6"><a href="power.html#cb183-6" tabindex="-1"></a> <span class="fu">geom_vline</span>(<span class="at">xintercept =</span> <span class="fl">47.5</span>, <span class="at">col =</span> <span class="st">&quot;black&quot;</span>)</span></code></pre></div>
<p><img src="_main_files/figure-html/unnamed-chunk-162-1.png" width="864" /></p>
<p>In the grand scheme of things the difference between these two populations is relatively small in magnitude: their histograms overlap, indicating that some penguins in both species often have similar bill lengths. But, what if the bills of all of the Gentoo penguins <em>magically</em> grew an extra 15 mm?</p>
<div class="sourceCode" id="cb184"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb184-1"><a href="power.html#cb184-1" tabindex="-1"></a>penguins <span class="sc">%&gt;%</span></span>
Expand All @@ -392,8 +392,8 @@ <h4><span class="header-section-number">9.0.1.2</span> Magnitude of effect<a hre
<span id="cb184-4"><a href="power.html#cb184-4" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">bill_length_mm =</span> <span class="fu">if_else</span>(species <span class="sc">==</span> <span class="st">&quot;Gentoo&quot;</span>, bill_length_mm <span class="sc">+</span> <span class="dv">15</span>, bill_length_mm)) <span class="sc">%&gt;%</span> </span>
<span id="cb184-5"><a href="power.html#cb184-5" tabindex="-1"></a> <span class="fu">ggplot</span>() <span class="sc">+</span> </span>
<span id="cb184-6"><a href="power.html#cb184-6" tabindex="-1"></a> <span class="fu">geom_histogram</span>(<span class="fu">aes</span>(<span class="at">x =</span> bill_length_mm, <span class="at">fill =</span> species), <span class="at">alpha =</span> <span class="fl">0.56</span>) <span class="sc">+</span></span>
<span id="cb184-7"><a href="power.html#cb184-7" tabindex="-1"></a> <span class="fu">geom_vline</span>(<span class="at">xintercept =</span> <span class="fl">38.8</span>) <span class="sc">+</span></span>
<span id="cb184-8"><a href="power.html#cb184-8" tabindex="-1"></a> <span class="fu">geom_vline</span>(<span class="at">xintercept =</span> <span class="fl">62.5</span>) <span class="co"># I found this from the new mutated values separately</span></span></code></pre></div>
<span id="cb184-7"><a href="power.html#cb184-7" tabindex="-1"></a> <span class="fu">geom_vline</span>(<span class="at">xintercept =</span> <span class="fl">38.8</span>, <span class="at">col =</span> <span class="st">&quot;black&quot;</span>) <span class="sc">+</span></span>
<span id="cb184-8"><a href="power.html#cb184-8" tabindex="-1"></a> <span class="fu">geom_vline</span>(<span class="at">xintercept =</span> <span class="fl">62.5</span>, <span class="at">col =</span> <span class="st">&quot;black&quot;</span>) <span class="co"># I found this from the new mutated values separately</span></span></code></pre></div>
<p><img src="_main_files/figure-html/unnamed-chunk-163-1.png" width="864" /></p>
<p>And now perform the t-test on this new <em>magical</em> data:</p>
<div class="sourceCode" id="cb185"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb185-1"><a href="power.html#cb185-1" tabindex="-1"></a>penguins <span class="sc">%&gt;%</span></span>
Expand Down Expand Up @@ -429,7 +429,7 @@ <h4><span class="header-section-number">9.0.1.2</span> Magnitude of effect<a hre
<pre><code>## # A tibble: 1 × 15
## estimate estimate1 estimate2 .y. group1 group2 n1 n2 statistic p df conf.low
## * &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;chr&gt; &lt;chr&gt; &lt;chr&gt; &lt;int&gt; &lt;int&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;
## 1 -24.8 39.1 64.0 bill_length_mm Adelie Gentoo 2 2 -6.88 0.0252 1.84 -41.7
## 1 -19.8 40.4 60.1 bill_length_mm Adelie Gentoo 2 2 -15.2 0.0125 1.51 -27.5
## # ℹ 3 more variables: conf.high &lt;dbl&gt;, method &lt;chr&gt;, alternative &lt;chr&gt;</code></pre>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions docs/r-skills-review.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/search_index.json

Large diffs are not rendered by default.

0 comments on commit 71cf076

Please sign in to comment.