Skip to content

Commit

Permalink
fix boolean typo OR AND
Browse files Browse the repository at this point in the history
  • Loading branch information
mmiots9 committed Feb 23, 2024
1 parent df6e68d commit 75a95dc
Show file tree
Hide file tree
Showing 86 changed files with 56,748 additions and 55,682 deletions.
2 changes: 1 addition & 1 deletion 07-Booleans.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ expr <- 50
</ul>
An easy trick to remember is: if at least one is TRUE, then the result is TRUE, otherwise if are all FALSE, the result is FALSE.
<br>
In R, AND operator is the `|`, some examples:
In R, OR operator is the `|`, some examples:
```{r}
expr <- 50
Expand Down
3,222 changes: 1,612 additions & 1,610 deletions _bookdown_files/_main_files/figure-html/aod_pmi_base_dotplot-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6,652 changes: 3,327 additions & 3,325 deletions _bookdown_files/_main_files/figure-html/aod_pmi_comparison_dotplot-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3,456 changes: 1,729 additions & 1,727 deletions _bookdown_files/_main_files/figure-html/aod_pmi_thresh_dotplot-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
403 changes: 209 additions & 194 deletions _bookdown_files/_main_files/figure-html/chi_squared_mosaic-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,191 changes: 610 additions & 581 deletions _bookdown_files/_main_files/figure-html/chi_squared_mosaic2-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
399 changes: 207 additions & 192 deletions _bookdown_files/_main_files/figure-html/chi_squared_yates_mosaic-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,275 changes: 642 additions & 633 deletions _bookdown_files/_main_files/figure-html/chi_squared_yates_mosaic2-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
415 changes: 218 additions & 197 deletions _bookdown_files/_main_files/figure-html/fisher_mosaic-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,275 changes: 651 additions & 624 deletions _bookdown_files/_main_files/figure-html/fisher_mosaic2-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
310 changes: 156 additions & 154 deletions _bookdown_files/_main_files/figure-html/males_females_barplot-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
482 changes: 242 additions & 240 deletions _bookdown_files/_main_files/figure-html/males_females_barplot2-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,198 changes: 601 additions & 597 deletions _bookdown_files/_main_files/figure-html/more_groups_boxplots-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,064 changes: 1,035 additions & 1,029 deletions _bookdown_files/_main_files/figure-html/more_groups_boxplots2-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
538 changes: 271 additions & 267 deletions _bookdown_files/_main_files/figure-html/more_groups_task3_boxplot-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
596 changes: 300 additions & 296 deletions _bookdown_files/_main_files/figure-html/more_groups_weight_lineplot-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,573 changes: 1,289 additions & 1,284 deletions _bookdown_files/_main_files/figure-html/parametric_visual_inspection-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,529 changes: 1,267 additions & 1,262 deletions ...kdown_files/_main_files/figure-html/parametric_visual_inspection_filtered-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,527 changes: 1,266 additions & 1,261 deletions ...own_files/_main_files/figure-html/parametric_visual_inspection_filtered_2-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,523 changes: 1,264 additions & 1,259 deletions ...own_files/_main_files/figure-html/parametric_visual_inspection_filtered_3-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3,058 changes: 1,532 additions & 1,526 deletions ...les/_main_files/figure-html/parametric_visual_inspection_filtered_pvalues-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,582 changes: 793 additions & 789 deletions _bookdown_files/_main_files/figure-html/pearson-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
710 changes: 356 additions & 354 deletions _bookdown_files/_main_files/figure-html/rin_area_basic_boxplot-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,079 changes: 542 additions & 537 deletions _bookdown_files/_main_files/figure-html/rin_area_boxplot_classic-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,259 changes: 632 additions & 627 deletions _bookdown_files/_main_files/figure-html/rin_area_boxplot_labs-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
728 changes: 365 additions & 363 deletions _bookdown_files/_main_files/figure-html/rin_area_boxplot_manual-1.svg

Large diffs are not rendered by default.

959 changes: 482 additions & 477 deletions _bookdown_files/_main_files/figure-html/rin_area_boxplot_theme-1.svg

Large diffs are not rendered by default.

1,372 changes: 687 additions & 685 deletions _bookdown_files/_main_files/figure-html/rin_area_boxplots-1.svg

Large diffs are not rendered by default.

1,060 changes: 532 additions & 528 deletions _bookdown_files/_main_files/figure-html/two_groups_boxplot-1.svg

Large diffs are not rendered by default.

1,700 changes: 853 additions & 847 deletions _bookdown_files/_main_files/figure-html/two_groups_boxplot2-1.svg

Large diffs are not rendered by default.

5,347 changes: 2,676 additions & 2,671 deletions _bookdown_files/_main_files/figure-html/two_groups_boxplot3-1.svg

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions docs/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<meta name="author" content="Matteo Miotto" />


<meta name="date" content="2023-12-09" />
<meta name="date" content="2024-02-23" />

<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
Expand All @@ -33,7 +33,7 @@



<script src="libs/header-attrs-2.25/header-attrs.js"></script>
<script src="libs/header-attrs-2.11/header-attrs.js"></script>
<script src="libs/jquery-3.6.0/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/fuse.js@6.4.6/dist/fuse.min.js"></script>
<link href="libs/gitbook-2.6.7/css/style.css" rel="stylesheet" />
Expand All @@ -51,9 +51,8 @@



<link href="libs/anchor-sections-1.1.0/anchor-sections.css" rel="stylesheet" />
<link href="libs/anchor-sections-1.1.0/anchor-sections-hash.css" rel="stylesheet" />
<script src="libs/anchor-sections-1.1.0/anchor-sections.js"></script>
<link href="libs/anchor-sections-1.0.1/anchor-sections.css" rel="stylesheet" />
<script src="libs/anchor-sections-1.0.1/anchor-sections.js"></script>
<meta property="og:description" content="To you, who never gives up, for your future. You can make it!">
<meta name="keywords" content="R, biology, data analysis">
<meta name="author" content="Matteo Miotto">
Expand All @@ -71,7 +70,7 @@

<style type="text/css">
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { line-height: 1.25; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
Expand Down
3,222 changes: 1,612 additions & 1,610 deletions docs/_main_files/figure-html/aod_pmi_base_dotplot-1.svg

Large diffs are not rendered by default.

6,652 changes: 3,327 additions & 3,325 deletions docs/_main_files/figure-html/aod_pmi_comparison_dotplot-1.svg

Large diffs are not rendered by default.

3,456 changes: 1,729 additions & 1,727 deletions docs/_main_files/figure-html/aod_pmi_thresh_dotplot-1.svg

Large diffs are not rendered by default.

403 changes: 209 additions & 194 deletions docs/_main_files/figure-html/chi_squared_mosaic-1.svg

Large diffs are not rendered by default.

1,191 changes: 610 additions & 581 deletions docs/_main_files/figure-html/chi_squared_mosaic2-1.svg

Large diffs are not rendered by default.

399 changes: 207 additions & 192 deletions docs/_main_files/figure-html/chi_squared_yates_mosaic-1.svg

Large diffs are not rendered by default.

1,275 changes: 642 additions & 633 deletions docs/_main_files/figure-html/chi_squared_yates_mosaic2-1.svg

Large diffs are not rendered by default.

415 changes: 218 additions & 197 deletions docs/_main_files/figure-html/fisher_mosaic-1.svg

Large diffs are not rendered by default.

1,275 changes: 651 additions & 624 deletions docs/_main_files/figure-html/fisher_mosaic2-1.svg

Large diffs are not rendered by default.

310 changes: 156 additions & 154 deletions docs/_main_files/figure-html/males_females_barplot-1.svg

Large diffs are not rendered by default.

482 changes: 242 additions & 240 deletions docs/_main_files/figure-html/males_females_barplot2-1.svg

Large diffs are not rendered by default.

1,198 changes: 601 additions & 597 deletions docs/_main_files/figure-html/more_groups_boxplots-1.svg

Large diffs are not rendered by default.

2,064 changes: 1,035 additions & 1,029 deletions docs/_main_files/figure-html/more_groups_boxplots2-1.svg

Large diffs are not rendered by default.

538 changes: 271 additions & 267 deletions docs/_main_files/figure-html/more_groups_task3_boxplot-1.svg

Large diffs are not rendered by default.

596 changes: 300 additions & 296 deletions docs/_main_files/figure-html/more_groups_weight_lineplot-1.svg

Large diffs are not rendered by default.

685 changes: 344 additions & 341 deletions docs/_main_files/figure-html/normal_vs_non_normal_distribution-1.svg

Large diffs are not rendered by default.

2,573 changes: 1,289 additions & 1,284 deletions docs/_main_files/figure-html/parametric_visual_inspection-1.svg

Large diffs are not rendered by default.

2,529 changes: 1,267 additions & 1,262 deletions docs/_main_files/figure-html/parametric_visual_inspection_filtered-1.svg

Large diffs are not rendered by default.

2,527 changes: 1,266 additions & 1,261 deletions docs/_main_files/figure-html/parametric_visual_inspection_filtered_2-1.svg

Large diffs are not rendered by default.

2,523 changes: 1,264 additions & 1,259 deletions docs/_main_files/figure-html/parametric_visual_inspection_filtered_3-1.svg

Large diffs are not rendered by default.

3,058 changes: 1,532 additions & 1,526 deletions docs/_main_files/figure-html/parametric_visual_inspection_filtered_pvalues-1.svg

Large diffs are not rendered by default.

1,582 changes: 793 additions & 789 deletions docs/_main_files/figure-html/pearson-1.svg

Large diffs are not rendered by default.

710 changes: 356 additions & 354 deletions docs/_main_files/figure-html/rin_area_basic_boxplot-1.svg

Large diffs are not rendered by default.

1,079 changes: 542 additions & 537 deletions docs/_main_files/figure-html/rin_area_boxplot_classic-1.svg

Large diffs are not rendered by default.

1,259 changes: 632 additions & 627 deletions docs/_main_files/figure-html/rin_area_boxplot_labs-1.svg

Large diffs are not rendered by default.

728 changes: 365 additions & 363 deletions docs/_main_files/figure-html/rin_area_boxplot_manual-1.svg

Large diffs are not rendered by default.

959 changes: 482 additions & 477 deletions docs/_main_files/figure-html/rin_area_boxplot_theme-1.svg

Large diffs are not rendered by default.

1,372 changes: 687 additions & 685 deletions docs/_main_files/figure-html/rin_area_boxplots-1.svg

Large diffs are not rendered by default.

1,060 changes: 532 additions & 528 deletions docs/_main_files/figure-html/two_groups_boxplot-1.svg

Large diffs are not rendered by default.

1,700 changes: 853 additions & 847 deletions docs/_main_files/figure-html/two_groups_boxplot2-1.svg

Large diffs are not rendered by default.

5,347 changes: 2,676 additions & 2,671 deletions docs/_main_files/figure-html/two_groups_boxplot3-1.svg

Large diffs are not rendered by default.

229 changes: 114 additions & 115 deletions docs/aggregate-data-with-tidyverse.html

Large diffs are not rendered by default.

391 changes: 195 additions & 196 deletions docs/association-between-categorical-variables.html

Large diffs are not rendered by default.

165 changes: 82 additions & 83 deletions docs/boolean-chapter.html

Large diffs are not rendered by default.

185 changes: 92 additions & 93 deletions docs/character.html

Large diffs are not rendered by default.

357 changes: 178 additions & 179 deletions docs/comparing-more-groups.html

Large diffs are not rendered by default.

365 changes: 182 additions & 183 deletions docs/comparing-two-groups.html

Large diffs are not rendered by default.

69 changes: 34 additions & 35 deletions docs/correlation.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<meta name="author" content="Matteo Miotto" />


<meta name="date" content="2023-12-09" />
<meta name="date" content="2024-02-23" />

<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
Expand All @@ -33,7 +33,7 @@

<link rel="prev" href="comparing-more-groups.html"/>
<link rel="next" href="farewell.html"/>
<script src="libs/header-attrs-2.25/header-attrs.js"></script>
<script src="libs/header-attrs-2.11/header-attrs.js"></script>
<script src="libs/jquery-3.6.0/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/fuse.js@6.4.6/dist/fuse.min.js"></script>
<link href="libs/gitbook-2.6.7/css/style.css" rel="stylesheet" />
Expand All @@ -51,9 +51,8 @@



<link href="libs/anchor-sections-1.1.0/anchor-sections.css" rel="stylesheet" />
<link href="libs/anchor-sections-1.1.0/anchor-sections-hash.css" rel="stylesheet" />
<script src="libs/anchor-sections-1.1.0/anchor-sections.js"></script>
<link href="libs/anchor-sections-1.0.1/anchor-sections.css" rel="stylesheet" />
<script src="libs/anchor-sections-1.0.1/anchor-sections.js"></script>
<meta property="og:description" content="To you, who never gives up, for your future. You can make it!">
<meta name="keywords" content="R, biology, data analysis">
<meta name="author" content="Matteo Miotto">
Expand All @@ -71,7 +70,7 @@

<style type="text/css">
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { line-height: 1.25; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
Expand Down Expand Up @@ -384,8 +383,8 @@ <h1>
<div class="page-inner">

<section class="normal" id="section-">
<div id="correlation" class="section level1 hasAnchor" number="19">
<h1><span class="header-section-number">19</span> Correlation<a href="correlation.html#correlation" class="anchor-section" aria-label="Anchor link to header"></a></h1>
<div id="correlation" class="section level1" number="19">
<h1><span class="header-section-number">19</span> Correlation</h1>
<p>Here we are to one of the most controversial statistical test: the correlation. Why controversial? “Pull off the band-aid” and let’s answer this question at first: usually correlation is used by some scientist as a synonym of <em>causation</em>, but it is not like this! To express this concept, we have to understand what correlation is.
Correlation is the measure of the relation of changes of data between two variables; it can answer these questions: “If A changes, does B do the same?”, “If A increases, does B increase? Or decrease?” So, many people then say “An increase in A leads to an increase of B”, but it is totally <strong>wrong</strong> if we do not know and demonstrates that B is caused by A.</p>
<p><strong>Remember:</strong> correlation is not causation.
Expand All @@ -411,25 +410,25 @@ <h1><span class="header-section-number">19</span> Correlation<a href="correlatio
</ul>
<p>We’ll see in detail the Pearson test, as in our example we have two continuous variables, then we will briefly see the other two tests.</p>
<p>Let’s load the data:</p>
<div class="sourceCode" id="cb587"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb587-1"><a href="correlation.html#cb587-1" tabindex="-1"></a><span class="co"># 1. Load packages </span></span>
<span id="cb587-2"><a href="correlation.html#cb587-2" tabindex="-1"></a><span class="fu">suppressPackageStartupMessages</span>(<span class="fu">library</span>(tidyverse))</span>
<span id="cb587-3"><a href="correlation.html#cb587-3" tabindex="-1"></a><span class="fu">suppressPackageStartupMessages</span>(<span class="fu">library</span>(ggplot2))</span>
<span id="cb587-4"><a href="correlation.html#cb587-4" tabindex="-1"></a><span class="fu">suppressPackageStartupMessages</span>(<span class="fu">library</span>(ggpubr))</span>
<span id="cb587-5"><a href="correlation.html#cb587-5" tabindex="-1"></a><span class="fu">suppressPackageStartupMessages</span>(<span class="fu">library</span>(gginnards))</span>
<span id="cb587-6"><a href="correlation.html#cb587-6" tabindex="-1"></a><span class="fu">suppressPackageStartupMessages</span>(<span class="fu">library</span>(glue))</span>
<span id="cb587-7"><a href="correlation.html#cb587-7" tabindex="-1"></a></span>
<span id="cb587-8"><a href="correlation.html#cb587-8" tabindex="-1"></a><span class="co"># 2. Load data</span></span>
<span id="cb587-9"><a href="correlation.html#cb587-9" tabindex="-1"></a>df <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="st">&quot;data/Stat-test-dataset.csv&quot;</span>)</span>
<span id="cb587-10"><a href="correlation.html#cb587-10" tabindex="-1"></a></span>
<span id="cb587-11"><a href="correlation.html#cb587-11" tabindex="-1"></a><span class="co"># 3. Change come column types</span></span>
<span id="cb587-12"><a href="correlation.html#cb587-12" tabindex="-1"></a>df <span class="ot">&lt;-</span> df <span class="sc">%&gt;%</span></span>
<span id="cb587-13"><a href="correlation.html#cb587-13" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="st">&quot;sex&quot;</span> <span class="ot">=</span> <span class="fu">factor</span>(sex),</span>
<span id="cb587-14"><a href="correlation.html#cb587-14" tabindex="-1"></a> <span class="st">&quot;treatment&quot;</span> <span class="ot">=</span> <span class="fu">factor</span>(treatment, <span class="at">levels =</span> <span class="fu">c</span>(<span class="st">&quot;T1&quot;</span>, <span class="st">&quot;Untreated&quot;</span>)),</span>
<span id="cb587-15"><a href="correlation.html#cb587-15" tabindex="-1"></a> <span class="st">&quot;Task1&quot;</span> <span class="ot">=</span> <span class="fu">factor</span>(Task1, <span class="at">levels =</span> <span class="fu">c</span>(<span class="dv">1</span>, <span class="dv">0</span>)),</span>
<span id="cb587-16"><a href="correlation.html#cb587-16" tabindex="-1"></a> <span class="st">&quot;Task2&quot;</span> <span class="ot">=</span> <span class="fu">factor</span>(Task2, <span class="at">levels =</span> <span class="fu">c</span>(<span class="dv">1</span>, <span class="dv">0</span>)),</span>
<span id="cb587-17"><a href="correlation.html#cb587-17" tabindex="-1"></a> )</span>
<span id="cb587-18"><a href="correlation.html#cb587-18" tabindex="-1"></a></span>
<span id="cb587-19"><a href="correlation.html#cb587-19" tabindex="-1"></a><span class="fu">str</span>(df)</span></code></pre></div>
<div class="sourceCode" id="cb587"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb587-1"><a href="correlation.html#cb587-1" aria-hidden="true" tabindex="-1"></a><span class="co"># 1. Load packages </span></span>
<span id="cb587-2"><a href="correlation.html#cb587-2" aria-hidden="true" tabindex="-1"></a><span class="fu">suppressPackageStartupMessages</span>(<span class="fu">library</span>(tidyverse))</span>
<span id="cb587-3"><a href="correlation.html#cb587-3" aria-hidden="true" tabindex="-1"></a><span class="fu">suppressPackageStartupMessages</span>(<span class="fu">library</span>(ggplot2))</span>
<span id="cb587-4"><a href="correlation.html#cb587-4" aria-hidden="true" tabindex="-1"></a><span class="fu">suppressPackageStartupMessages</span>(<span class="fu">library</span>(ggpubr))</span>
<span id="cb587-5"><a href="correlation.html#cb587-5" aria-hidden="true" tabindex="-1"></a><span class="fu">suppressPackageStartupMessages</span>(<span class="fu">library</span>(gginnards))</span>
<span id="cb587-6"><a href="correlation.html#cb587-6" aria-hidden="true" tabindex="-1"></a><span class="fu">suppressPackageStartupMessages</span>(<span class="fu">library</span>(glue))</span>
<span id="cb587-7"><a href="correlation.html#cb587-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb587-8"><a href="correlation.html#cb587-8" aria-hidden="true" tabindex="-1"></a><span class="co"># 2. Load data</span></span>
<span id="cb587-9"><a href="correlation.html#cb587-9" aria-hidden="true" tabindex="-1"></a>df <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="st">&quot;data/Stat-test-dataset.csv&quot;</span>)</span>
<span id="cb587-10"><a href="correlation.html#cb587-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb587-11"><a href="correlation.html#cb587-11" aria-hidden="true" tabindex="-1"></a><span class="co"># 3. Change come column types</span></span>
<span id="cb587-12"><a href="correlation.html#cb587-12" aria-hidden="true" tabindex="-1"></a>df <span class="ot">&lt;-</span> df <span class="sc">%&gt;%</span></span>
<span id="cb587-13"><a href="correlation.html#cb587-13" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="st">&quot;sex&quot;</span> <span class="ot">=</span> <span class="fu">factor</span>(sex),</span>
<span id="cb587-14"><a href="correlation.html#cb587-14" aria-hidden="true" tabindex="-1"></a> <span class="st">&quot;treatment&quot;</span> <span class="ot">=</span> <span class="fu">factor</span>(treatment, <span class="at">levels =</span> <span class="fu">c</span>(<span class="st">&quot;T1&quot;</span>, <span class="st">&quot;Untreated&quot;</span>)),</span>
<span id="cb587-15"><a href="correlation.html#cb587-15" aria-hidden="true" tabindex="-1"></a> <span class="st">&quot;Task1&quot;</span> <span class="ot">=</span> <span class="fu">factor</span>(Task1, <span class="at">levels =</span> <span class="fu">c</span>(<span class="dv">1</span>, <span class="dv">0</span>)),</span>
<span id="cb587-16"><a href="correlation.html#cb587-16" aria-hidden="true" tabindex="-1"></a> <span class="st">&quot;Task2&quot;</span> <span class="ot">=</span> <span class="fu">factor</span>(Task2, <span class="at">levels =</span> <span class="fu">c</span>(<span class="dv">1</span>, <span class="dv">0</span>)),</span>
<span id="cb587-17"><a href="correlation.html#cb587-17" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb587-18"><a href="correlation.html#cb587-18" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb587-19"><a href="correlation.html#cb587-19" aria-hidden="true" tabindex="-1"></a><span class="fu">str</span>(df)</span></code></pre></div>
<pre class="code-out"><code>&#39;data.frame&#39;: 600 obs. of 7 variables:
$ sex : Factor w/ 2 levels &quot;Female&quot;,&quot;Male&quot;: 2 1 2 1 2 1 2 1 2 1 ...
$ age : int 3 3 3 3 3 3 3 3 3 3 ...
Expand All @@ -438,18 +437,18 @@ <h1><span class="header-section-number">19</span> Correlation<a href="correlatio
$ Task1 : Factor w/ 2 levels &quot;1&quot;,&quot;0&quot;: 1 2 2 2 1 1 1 1 2 1 ...
$ Task2 : Factor w/ 2 levels &quot;1&quot;,&quot;0&quot;: 1 2 2 1 1 2 2 1 1 1 ...
$ Task3 : num 222.4 202.3 36.7 221.8 178.8 ...</code></pre>
<div id="pearsons-test" class="section level2 unnumbered hasAnchor">
<h2>Pearson’s test<a href="correlation.html#pearsons-test" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<div id="pearsons-test" class="section level2 unnumbered">
<h2>Pearson’s test</h2>
<p>We want to know if weight and Task3 are correlated in both males and females.
The first thing to do is, as always, plot the variables to have a look at them:</p>
<div class="sourceCode" id="cb589"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb589-1"><a href="correlation.html#cb589-1" tabindex="-1"></a><span class="fu">ggplot</span>(df) <span class="sc">+</span></span>
<span id="cb589-2"><a href="correlation.html#cb589-2" tabindex="-1"></a> <span class="fu">geom_point</span>(<span class="fu">aes</span>(<span class="at">x =</span> weight, <span class="at">y =</span> Task3, <span class="at">color =</span> sex)) <span class="sc">+</span></span>
<span id="cb589-3"><a href="correlation.html#cb589-3" tabindex="-1"></a> <span class="fu">labs</span>(<span class="at">y =</span> <span class="st">&quot;Task3 (s)&quot;</span>, <span class="at">x =</span> <span class="st">&quot;Weight (g)&quot;</span>, <span class="at">color =</span> <span class="st">&quot;Sex&quot;</span>) <span class="sc">+</span></span>
<span id="cb589-4"><a href="correlation.html#cb589-4" tabindex="-1"></a> <span class="fu">theme_classic</span>()</span></code></pre></div>
<div class="sourceCode" id="cb589"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb589-1"><a href="correlation.html#cb589-1" aria-hidden="true" tabindex="-1"></a><span class="fu">ggplot</span>(df) <span class="sc">+</span></span>
<span id="cb589-2"><a href="correlation.html#cb589-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_point</span>(<span class="fu">aes</span>(<span class="at">x =</span> weight, <span class="at">y =</span> Task3, <span class="at">color =</span> sex)) <span class="sc">+</span></span>
<span id="cb589-3"><a href="correlation.html#cb589-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">labs</span>(<span class="at">y =</span> <span class="st">&quot;Task3 (s)&quot;</span>, <span class="at">x =</span> <span class="st">&quot;Weight (g)&quot;</span>, <span class="at">color =</span> <span class="st">&quot;Sex&quot;</span>) <span class="sc">+</span></span>
<span id="cb589-4"><a href="correlation.html#cb589-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme_classic</span>()</span></code></pre></div>
<p><img src="_main_files/figure-html/pearson-1.svg" width="85%" style="display: block; margin: auto;" /></p>
<p>Just visually, we can say that there is no positive or negative correlation between them. To claim it, let’s apply the Pearson’s test: the function to use is <code>cor.test()</code>, specifying <code>method = "pearson"</code>; the order of the variables is not important.</p>
<div class="sourceCode" id="cb590"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb590-1"><a href="correlation.html#cb590-1" tabindex="-1"></a>pearson_res <span class="ot">&lt;-</span> <span class="fu">cor.test</span>(df<span class="sc">$</span>weight, df<span class="sc">$</span>Task3, <span class="at">method =</span> <span class="st">&quot;pearson&quot;</span>)</span>
<span id="cb590-2"><a href="correlation.html#cb590-2" tabindex="-1"></a>pearson_res</span></code></pre></div>
<div class="sourceCode" id="cb590"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb590-1"><a href="correlation.html#cb590-1" aria-hidden="true" tabindex="-1"></a>pearson_res <span class="ot">&lt;-</span> <span class="fu">cor.test</span>(df<span class="sc">$</span>weight, df<span class="sc">$</span>Task3, <span class="at">method =</span> <span class="st">&quot;pearson&quot;</span>)</span>
<span id="cb590-2"><a href="correlation.html#cb590-2" aria-hidden="true" tabindex="-1"></a>pearson_res</span></code></pre></div>
<pre class="code-out"><code>
Pearson&#39;s product-moment correlation

Expand Down
Loading

0 comments on commit 75a95dc

Please sign in to comment.