Skip to content

Commit 281b04d

Browse files
add blogpost
1 parent f44eaca commit 281b04d

File tree

4 files changed

+188
-74
lines changed

4 files changed

+188
-74
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
layout: post
3+
title: "Easy APA Formatted Bayesian Correlation"
4+
author: Dominique Makowski
5+
author_web: https://dominiquemakowski.github.io/
6+
date: 2018-06-11
7+
summary: Perform, interpret and format Bayesian correlations in one line.
8+
---
9+
10+
11+
12+
- [Traditional Correlation](#traditional-correlation)
13+
- [Bayesian APA formatted Correlation](#bayesian-apa-formatted-correlation)
14+
- [Indices](#indices)
15+
- [Posterior](#posterior)
16+
- [Credits](#credits)
17+
18+
19+
**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.
20+
21+
Traditional Correlation
22+
=======================
23+
24+
Let's first perform a traditional correlation.
25+
26+
``` r
27+
# devtools::install_github("neuropsychology/psycho.R") # Install the latest psycho version
28+
29+
# Load packages
30+
library(tidyverse)
31+
library(psycho)
32+
33+
# Import data
34+
df <- psycho::affective
35+
36+
cor.test(df$Concealing, df$Tolerating)
37+
```
38+
39+
40+
Pearson's product-moment correlation
41+
42+
data: df$Concealing and df$Tolerating
43+
t = 2.611, df = 1249, p-value = 0.009136
44+
alternative hypothesis: true correlation is not equal to 0
45+
95 percent confidence interval:
46+
0.01832974 0.12857724
47+
sample estimates:
48+
cor
49+
0.07367859
50+
51+
There is a **significant** (*whatever that means*), yet **weak positive** correlation between Concealing and Tolerating affective styles.
52+
53+
Bayesian APA formatted Correlation
54+
==================================
55+
56+
And now, see how quickly we can do a Bayesian correlation:
57+
58+
``` r
59+
bayes_cor.test(df$Concealing, df$Tolerating)
60+
```
61+
62+
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%.
63+
64+
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.
65+
66+
Indices
67+
=======
68+
69+
We can have access to more indices with the `summary`:
70+
71+
``` r
72+
results <- bayes_cor.test(df$Concealing, df$Tolerating)
73+
summary(results)
74+
```
75+
76+
| | Median| MAD| Mean| SD| CI\_lower| CI\_higher| MPE| BF| Overlap| Rope |
77+
|---------------------------------------------------|-------:|-----:|-----:|-----:|----------:|-----------:|------:|-----:|--------:|:----------|
78+
| df\$Concealing/df\$Tolerating | 0.07| 0.03| 0.07| 0.03| 0.03| 0.12| 99.56| 1.95| 19.43| Undecided |
79+
80+
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).
81+
82+
Posterior
83+
=========
84+
85+
We can easily extract the posterior distribution to visualize the probability of possible effects.
86+
87+
``` r
88+
posterior <- results$values$posterior
89+
90+
plot(density(posterior))
91+
```
92+
93+
<img src="https://raw.githubusercontent.com/neuropsychology/psycho.R/master/docs/_posts/2018-06-11-bayesian_correlation_files/figure-markdown_github/unnamed-chunk-6-1.png" style="display: block; margin: auto;" />
94+
95+
Credits
96+
=======
97+
98+
This package helped you? Don't forget to cite the various packages you used :)
99+
100+
You can cite `psycho` as follows:
101+
102+
- 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>
5.85 KB
Loading

docs/_posts/preparation/bayesian_correlation.Rmd

Lines changed: 0 additions & 74 deletions
This file was deleted.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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

Comments
 (0)