|
| 1 | +--- |
| 2 | +title: "Easy APA Formatted Bayesian Correlation" |
| 3 | +layout: post |
| 4 | +output: |
| 5 | + html_document: |
| 6 | + df_print: paged |
| 7 | + toc: yes |
| 8 | + md_document: |
| 9 | + toc: yes |
| 10 | + variant: markdown_github |
| 11 | +author: "Dominique Makowski" |
| 12 | +date: "`r Sys.Date()`" |
| 13 | +editor_options: |
| 14 | + chunk_output_type: console |
| 15 | +--- |
| 16 | + |
| 17 | + |
| 18 | +```{r message=FALSE, warning=FALSE, include=FALSE} |
| 19 | +library(knitr) |
| 20 | +``` |
| 21 | + |
| 22 | +**The Bayesian framework is the right way to go for psychological science.** To facilitate its use for newcommers, we implemented the `bayes_cor.test` function in the [psycho package](https://github.com/neuropsychology/psycho.R), a **user-friendly wrapper** for the `correlationBF` function of the great [`BayesFactor`](https://richarddmorey.github.io/BayesFactor/) package by Richard D. Morey. |
| 23 | + |
| 24 | +# Traditional Correlation |
| 25 | + |
| 26 | +Let's first perform a traditional correlation. |
| 27 | + |
| 28 | +```{r, fig.width=7, fig.height=4.5, eval = TRUE, results='markup', fig.align='center', comment=NA, message=FALSE, warning=FALSE} |
| 29 | +# devtools::install_github("neuropsychology/psycho.R") # Install the latest psycho version |
| 30 | +
|
| 31 | +# Load packages |
| 32 | +library(tidyverse) |
| 33 | +library(psycho) |
| 34 | +
|
| 35 | +# Import data |
| 36 | +df <- psycho::affective |
| 37 | +
|
| 38 | +cor.test(df$Concealing, df$Tolerating) |
| 39 | +``` |
| 40 | + |
| 41 | +There is a **significant** (*whatever that means*), yet **weak positive** correlation between Concealing and Tolerating affective styles. |
| 42 | + |
| 43 | + |
| 44 | +# Bayesian APA formatted Correlation |
| 45 | + |
| 46 | +And now, see how quickly we can do a Bayesian correlation: |
| 47 | + |
| 48 | +```{r, fig.width=7, fig.height=4.5, eval = TRUE, results='markup', fig.align='center', comment=NA, message=FALSE, warning=FALSE} |
| 49 | +bayes_cor.test(df$Concealing, df$Tolerating) |
| 50 | +``` |
| 51 | + |
| 52 | +The results are roughly the same, but neatly dissociate the likelihood in favour or against the null hypothesis (using the [Bayes Factor](https://www.r-bloggers.com/what-does-a-bayes-factor-feel-like/)), from the "significance" (wether a portion of the *Credible Interval* covers 0), from the effect size (interpreted here with [Cohen's (1988) rules of thumb](https://github.com/neuropsychology/psycho.R/blob/master/R/interpret_r.R#L142)). Critically, **you can, now, simply copy/paste this output to your manuscript!** It includes and formats the Bayes Factor, the median (a good point-estimate, close to the *r* estimated in frequentist correlation), MAD (robust equivalent of SD for median) and *credible* interval (CI) of the posterior distribution, as well as effect size interpretation. |
| 53 | + |
| 54 | +# Indices |
| 55 | + |
| 56 | +We can have access to more indices with the `summary`: |
| 57 | + |
| 58 | +```{r, fig.width=7, fig.height=4.5, eval = TRUE, results='hide', fig.align='center', comment=NA, message=FALSE, warning=FALSE} |
| 59 | +results <- bayes_cor.test(df$Concealing, df$Tolerating) |
| 60 | +summary(results) |
| 61 | +``` |
| 62 | +```{r, fig.width=7, fig.height=4.5, echo=FALSE, eval = TRUE, fig.align='center', comment=NA, message=FALSE, warning=FALSE} |
| 63 | +knitr::kable(summary(results), digits=2) |
| 64 | +``` |
| 65 | + |
| 66 | +Those indices include the ROPE decision criterion (see [Kruschke, 2018](http://journals.sagepub.com/doi/abs/10.1177/2515245918771304)) as well as the Maximum Probability of Effect (MPE, the probability that an effect is negative or positive and different from 0). |
| 67 | + |
| 68 | +# Posterior |
| 69 | + |
| 70 | +We can easily extract the posterior distribution to visualize the probability of possible effects. |
| 71 | + |
| 72 | +```{r, fig.width=7, fig.height=4.5, eval = TRUE, fig.align='center', comment=NA, message=FALSE, warning=FALSE} |
| 73 | +posterior <- results$values$posterior |
| 74 | +
|
| 75 | +plot(density(posterior)) |
| 76 | +``` |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | +# Credits |
| 81 | + |
| 82 | +This package helped you? Don't forget to cite the various packages you used :) |
| 83 | + |
| 84 | +You can cite `psycho` as follows: |
| 85 | + |
| 86 | +- Makowski, (2018). *The psycho Package: an Efficient and Publishing-Oriented Workflow for Psychological Science*. Journal of Open Source Software, 3(22), 470. https://doi.org/10.21105/joss.00470 |
0 commit comments