<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/easy-apa-formatted-bayesian-correlation/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://neuropsychology.github.io/psycho.R//2018/06/11/bayesian_correlation.html"> Dominique Makowski</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<ul>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R//2018/06/11/bayesian_correlation.html#traditional-correlation" target="_blank">Traditional Correlation</a></li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R//2018/06/11/bayesian_correlation.html#bayesian-apa-formatted-correlation" target="_blank">Bayesian APA formatted Correlation</a></li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R//2018/06/11/bayesian_correlation.html#indices" target="_blank">Indices</a></li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R//2018/06/11/bayesian_correlation.html#posterior" target="_blank">Posterior</a></li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R//2018/06/11/bayesian_correlation.html#credits" target="_blank">Credits</a></li>
</ul>
<p><strong>The Bayesian framework is the right way to go for psychological science.</strong> To facilitate its use for newcommers, we implemented the <code>bayes_cor.test</code> function in the <a rel="nofollow" href="https://github.com/neuropsychology/psycho.R" target="_blank">psycho package</a>, a <strong>user-friendly wrapper</strong> for the <code>correlationBF</code> function of the great <a rel="nofollow" href="https://richarddmorey.github.io/BayesFactor/" target="_blank"><code>BayesFactor</code></a> package by Richard D. Morey.</p>
<h1>Traditional Correlation</h1>
<p>Let’s first perform a traditional correlation.</p>
<div>
<div>
<pre><code><span># devtools::install_github(&quot;neuropsychology/psycho.R&quot;) # Install the latest psycho version</span><span>
</span><span># Load packages</span><span>
</span><span>library</span><span>(</span><span>tidyverse</span><span>)</span><span>
</span><span>library</span><span>(</span><span>psycho</span><span>)</span><span>
</span><span># Import data</span><span>
</span><span>df</span><span> </span><span>&lt;-</span><span> </span><span>psycho</span><span>::</span><span>affective</span><span>
</span><span>cor.test</span><span>(</span><span>df</span><span>$</span><span>Concealing</span><span>,</span><span> </span><span>df</span><span>$</span><span>Tolerating</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<div>
<div>
<pre><code>    Pearson's product-moment correlation

data:  df$Concealing and df$Tolerating
t = 2.611, df = 1249, p-value = 0.009136
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 0.01832974 0.12857724
sample estimates:
       cor 
0.07367859 
</code></pre>
</div>
</div>
<p>There is a <strong>significant</strong> (<em>whatever that means</em>), yet <strong>weak positive</strong> correlation between Concealing and Tolerating affective styles.</p>
<h1>Bayesian APA formatted Correlation</h1>
<p>And now, see how quickly we can do a Bayesian correlation:</p>
<div>
<div>
<pre><code><span>bayes_cor.test</span><span>(</span><span>df</span><span>$</span><span>Concealing</span><span>,</span><span> </span><span>df</span><span>$</span><span>Tolerating</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<div>
<div>
<pre><code>Results of the Bayesian correlation indicate anecdotal evidence (BF = 1.95) in favour of a positive association between df$Concealing and df$Tolerating (r = 0.073, MAD = 0.028, 90% CI [0.023, 0.12]). The correlation can be considered as small or very small with respective probabilities of 16.55% and 83.06%.
</code></pre>
</div>
</div>
<p>The results are roughly the same, but neatly dissociate the likelihood in favour or against the null hypothesis (using the <a rel="nofollow" href="https://www.r-bloggers.com/what-does-a-bayes-factor-feel-like/" target="_blank">Bayes Factor</a>), from the “significance” (wether a portion of the <em>Credible Interval</em> covers 0), from the effect size (interpreted here with <a rel="nofollow" href="https://github.com/neuropsychology/psycho.R/blob/master/R/interpret_r.R#L142" target="_blank">Cohen’s (1988) rules of thumb</a>). Critically, <strong>you can, now, simply copy/paste this output to your manuscript!</strong> It includes and formats the Bayes Factor, the median (a good point-estimate, close to the <em>r</em> estimated in frequentist correlation), MAD (robust equivalent of SD for median) and <em>credible</em> interval (CI) of the posterior distribution, as well as effect size interpretation.</p>
<h1>Indices</h1>
<p>We can have access to more indices with the <code>summary</code>:</p>
<div>
<div>
<pre><code><span>results</span><span> </span><span>&lt;-</span><span> </span><span>bayes_cor.test</span><span>(</span><span>df</span><span>$</span><span>Concealing</span><span>,</span><span> </span><span>df</span><span>$</span><span>Tolerating</span><span>)</span><span>
</span><span>summary</span><span>(</span><span>results</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<table>
<thead>
<tr>
<th> </th>
<th>Median</th>
<th>MAD</th>
<th>Mean</th>
<th>SD</th>
<th>CI_lower</th>
<th>CI_higher</th>
<th>MPE</th>
<th>BF</th>
<th>Overlap</th>
<th>Rope</th>
</tr>
</thead>
<tbody>
<tr>
<td>df$Concealing/df$Tolerating</td>
<td>0.07</td>
<td>0.03</td>
<td>0.07</td>
<td>0.03</td>
<td>0.03</td>
<td>0.12</td>
<td>99.56</td>
<td>1.95</td>
<td>19.43</td>
<td>Undecided</td>
</tr>
</tbody>
</table>
<p>Those indices include the ROPE decision criterion (see <a rel="nofollow" href="http://journals.sagepub.com/doi/abs/10.1177/2515245918771304" target="_blank">Kruschke, 2018</a>) as well as the Maximum Probability of Effect (MPE, the probability that an effect is negative or positive and different from 0).</p>
<h1>Posterior</h1>
<p>We can easily extract the posterior distribution to visualize the probability of possible effects.</p>
<div>
<div>
<pre><code><span>posterior</span><span> </span><span>&lt;-</span><span> </span><span>results</span><span>$</span><span>values</span><span>$</span><span>posterior</span><span>
</span><span>plot</span><span>(</span><span>density</span><span>(</span><span>posterior</span><span>))</span><span>
</span></code></pre>
</div>
</div>
<p><img src="https://i1.wp.com/raw.githubusercontent.com/neuropsychology/psycho.R/master/docs/_posts/2018-06-11-bayesian_correlation_files/figure-markdown_github/unnamed-chunk-6-1.png?w=456&ssl=1" data-recalc-dims="1"></p>
<h1>Contribute</h1>
<p>Of course, these reporting standards should change, depending on new expert recommandations or official guidelines. <strong>The goal of this package is to flexibly adaptive to new changes and good practices evolution</strong>. Therefore, if you have any advices, opinions or such, we encourage you to either let us know by opening an <a rel="nofollow" href="https://github.com/neuropsychology/psycho.R/issues" target="_blank">issue</a> or, even better, try to implement them yourself by <a rel="nofollow" href="https://github.com/neuropsychology/psycho.R/blob/master/.github/CONTRIBUTING.md" target="_blank">contributing</a> to the code.</p>
<h1>Credits</h1>
<p>This package helped you? Don’t forget to cite the various packages you used <img alt="🙂" src="https://s.w.org/images/core/emoji/2.4/72x72/1f642.png" class="wp-smiley"></p>
<p>You can cite <code>psycho</code> as follows:</p>
<ul>
<li>Makowski, (2018). <em>The psycho Package: an Efficient and Publishing-Oriented Workflow for Psychological Science</em>. Journal of Open Source Software, 3(22), 470. <a rel="nofollow" href="https://doi.org/10.21105/joss.00470" target="_blank">https://doi.org/10.21105/joss.00470</a></li>
</ul>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://neuropsychology.github.io/psycho.R//2018/06/11/bayesian_correlation.html"> Dominique Makowski</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/fhZClQfnf1g" height="1"></a></div>