https://github.com/cran/bayestestR
Raw File
Tip revision: 9985109256c08d654edb46adb9cb20c913fb1888 authored by Dominique Makowski on 29 May 2019, 14:10:02 UTC
version 0.2.0
Tip revision: 9985109
example1.html
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1">

<style type="text/css">
@font-face {
font-family: octicons-link;
src: url(data:font/woff;charset=utf-8;base64,d09GRgABAAAAAAZwABAAAAAACFQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABEU0lHAAAGaAAAAAgAAAAIAAAAAUdTVUIAAAZcAAAACgAAAAoAAQAAT1MvMgAAAyQAAABJAAAAYFYEU3RjbWFwAAADcAAAAEUAAACAAJThvmN2dCAAAATkAAAABAAAAAQAAAAAZnBnbQAAA7gAAACyAAABCUM+8IhnYXNwAAAGTAAAABAAAAAQABoAI2dseWYAAAFsAAABPAAAAZwcEq9taGVhZAAAAsgAAAA0AAAANgh4a91oaGVhAAADCAAAABoAAAAkCA8DRGhtdHgAAAL8AAAADAAAAAwGAACfbG9jYQAAAsAAAAAIAAAACABiATBtYXhwAAACqAAAABgAAAAgAA8ASm5hbWUAAAToAAABQgAAAlXu73sOcG9zdAAABiwAAAAeAAAAME3QpOBwcmVwAAAEbAAAAHYAAAB/aFGpk3jaTY6xa8JAGMW/O62BDi0tJLYQincXEypYIiGJjSgHniQ6umTsUEyLm5BV6NDBP8Tpts6F0v+k/0an2i+itHDw3v2+9+DBKTzsJNnWJNTgHEy4BgG3EMI9DCEDOGEXzDADU5hBKMIgNPZqoD3SilVaXZCER3/I7AtxEJLtzzuZfI+VVkprxTlXShWKb3TBecG11rwoNlmmn1P2WYcJczl32etSpKnziC7lQyWe1smVPy/Lt7Kc+0vWY/gAgIIEqAN9we0pwKXreiMasxvabDQMM4riO+qxM2ogwDGOZTXxwxDiycQIcoYFBLj5K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Eao0FEW14ckxC+TU8TxvsY6X0eLPmRhry2WVioLpkrbp84LLQPGI7c6sOiUzpWIWS5GzlSgUzzLBSikOPFTOXqly7rqx0Z1Q5BAIoZBSFihQYQOOBEdkCOgXTOHA07HAGjGWiIjaPZNW13/+lm6S9FT7rLHFJ6fQbkATOG1j2OFMucKJJsxIVfQORl+9Jyda6Sl1dUYhSCm1dyClfoeDve4qMYdLEbfqHf3O/AdDumsjAAB42mNgYoAAZQYjBmyAGYQZmdhL8zLdDEydARfoAqIAAAABAAMABwAKABMAB///AA8AAQAAAAAAAAAAAAAAAAABAAAAAA==) format('woff');
}
body {
-webkit-text-size-adjust: 100%;
text-size-adjust: 100%;
color: #333;
font-family: "Helvetica Neue", Helvetica, "Segoe UI", Arial, freesans, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
font-size: 16px;
line-height: 1.6;
word-wrap: break-word;
}
a {
background-color: transparent;
}
a:active,
a:hover {
outline: 0;
}
strong {
font-weight: bold;
}
h1 {
font-size: 2em;
margin: 0.67em 0;
}
img {
border: 0;
}
hr {
box-sizing: content-box;
height: 0;
}
pre {
overflow: auto;
}
code,
kbd,
pre {
font-family: monospace, monospace;
font-size: 1em;
}
input {
color: inherit;
font: inherit;
margin: 0;
}
html input[disabled] {
cursor: default;
}
input {
line-height: normal;
}
input[type="checkbox"] {
box-sizing: border-box;
padding: 0;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
td,
th {
padding: 0;
}
* {
box-sizing: border-box;
}
input {
font: 13px / 1.4 Helvetica, arial, nimbussansl, liberationsans, freesans, clean, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}
a {
color: #4078c0;
text-decoration: none;
}
a:hover,
a:active {
text-decoration: underline;
}
hr {
height: 0;
margin: 15px 0;
overflow: hidden;
background: transparent;
border: 0;
border-bottom: 1px solid #ddd;
}
hr:before {
display: table;
content: "";
}
hr:after {
display: table;
clear: both;
content: "";
}
h1,
h2,
h3,
h4,
h5,
h6 {
margin-top: 15px;
margin-bottom: 15px;
line-height: 1.1;
}
h1 {
font-size: 30px;
}
h2 {
font-size: 21px;
}
h3 {
font-size: 16px;
}
h4 {
font-size: 14px;
}
h5 {
font-size: 12px;
}
h6 {
font-size: 11px;
}
blockquote {
margin: 0;
}
ul,
ol {
padding: 0;
margin-top: 0;
margin-bottom: 0;
}
ol ol,
ul ol {
list-style-type: lower-roman;
}
ul ul ol,
ul ol ol,
ol ul ol,
ol ol ol {
list-style-type: lower-alpha;
}
dd {
margin-left: 0;
}
code {
font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
font-size: 12px;
}
pre {
margin-top: 0;
margin-bottom: 0;
font: 12px Consolas, "Liberation Mono", Menlo, Courier, monospace;
}
.select::-ms-expand {
opacity: 0;
}
.octicon {
font: normal normal normal 16px/1 octicons-link;
display: inline-block;
text-decoration: none;
text-rendering: auto;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.octicon-link:before {
content: '\f05c';
}
.markdown-body:before {
display: table;
content: "";
}
.markdown-body:after {
display: table;
clear: both;
content: "";
}
.markdown-body>*:first-child {
margin-top: 0 !important;
}
.markdown-body>*:last-child {
margin-bottom: 0 !important;
}
a:not([href]) {
color: inherit;
text-decoration: none;
}
.anchor {
display: inline-block;
padding-right: 2px;
margin-left: -18px;
}
.anchor:focus {
outline: none;
}
h1,
h2,
h3,
h4,
h5,
h6 {
margin-top: 1em;
margin-bottom: 16px;
font-weight: bold;
line-height: 1.4;
}
h1 .octicon-link,
h2 .octicon-link,
h3 .octicon-link,
h4 .octicon-link,
h5 .octicon-link,
h6 .octicon-link {
color: #000;
vertical-align: middle;
visibility: hidden;
}
h1:hover .anchor,
h2:hover .anchor,
h3:hover .anchor,
h4:hover .anchor,
h5:hover .anchor,
h6:hover .anchor {
text-decoration: none;
}
h1:hover .anchor .octicon-link,
h2:hover .anchor .octicon-link,
h3:hover .anchor .octicon-link,
h4:hover .anchor .octicon-link,
h5:hover .anchor .octicon-link,
h6:hover .anchor .octicon-link {
visibility: visible;
}
h1 {
padding-bottom: 0.3em;
font-size: 2.25em;
line-height: 1.2;
border-bottom: 1px solid #eee;
}
h1 .anchor {
line-height: 1;
}
h2 {
padding-bottom: 0.3em;
font-size: 1.75em;
line-height: 1.225;
border-bottom: 1px solid #eee;
}
h2 .anchor {
line-height: 1;
}
h3 {
font-size: 1.5em;
line-height: 1.43;
}
h3 .anchor {
line-height: 1.2;
}
h4 {
font-size: 1.25em;
}
h4 .anchor {
line-height: 1.2;
}
h5 {
font-size: 1em;
}
h5 .anchor {
line-height: 1.1;
}
h6 {
font-size: 1em;
color: #777;
}
h6 .anchor {
line-height: 1.1;
}
p,
blockquote,
ul,
ol,
dl,
table,
pre {
margin-top: 0;
margin-bottom: 16px;
}
hr {
height: 4px;
padding: 0;
margin: 16px 0;
background-color: #e7e7e7;
border: 0 none;
}
ul,
ol {
padding-left: 2em;
}
ul ul,
ul ol,
ol ol,
ol ul {
margin-top: 0;
margin-bottom: 0;
}
li>p {
margin-top: 16px;
}
dl {
padding: 0;
}
dl dt {
padding: 0;
margin-top: 16px;
font-size: 1em;
font-style: italic;
font-weight: bold;
}
dl dd {
padding: 0 16px;
margin-bottom: 16px;
}
blockquote {
padding: 0 15px;
color: #777;
border-left: 4px solid #ddd;
}
blockquote>:first-child {
margin-top: 0;
}
blockquote>:last-child {
margin-bottom: 0;
}
table {
display: block;
width: 100%;
overflow: auto;
word-break: normal;
word-break: keep-all;
}
table th {
font-weight: bold;
}
table th,
table td {
padding: 6px 13px;
border: 1px solid #ddd;
}
table tr {
background-color: #fff;
border-top: 1px solid #ccc;
}
table tr:nth-child(2n) {
background-color: #f8f8f8;
}
img {
max-width: 100%;
box-sizing: content-box;
background-color: #fff;
}
code {
padding: 0;
padding-top: 0.2em;
padding-bottom: 0.2em;
margin: 0;
font-size: 85%;
background-color: rgba(0,0,0,0.04);
border-radius: 3px;
}
code:before,
code:after {
letter-spacing: -0.2em;
content: "\00a0";
}
pre>code {
padding: 0;
margin: 0;
font-size: 100%;
word-break: normal;
white-space: pre;
background: transparent;
border: 0;
}
.highlight {
margin-bottom: 16px;
}
.highlight pre,
pre {
padding: 16px;
overflow: auto;
font-size: 85%;
line-height: 1.45;
background-color: #f7f7f7;
border-radius: 3px;
}
.highlight pre {
margin-bottom: 0;
word-break: normal;
}
pre {
word-wrap: normal;
}
pre code {
display: inline;
max-width: initial;
padding: 0;
margin: 0;
overflow: initial;
line-height: inherit;
word-wrap: normal;
background-color: transparent;
border: 0;
}
pre code:before,
pre code:after {
content: normal;
}
kbd {
display: inline-block;
padding: 3px 5px;
font-size: 11px;
line-height: 10px;
color: #555;
vertical-align: middle;
background-color: #fcfcfc;
border: solid 1px #ccc;
border-bottom-color: #bbb;
border-radius: 3px;
box-shadow: inset 0 -1px 0 #bbb;
}
.pl-c {
color: #969896;
}
.pl-c1,
.pl-s .pl-v {
color: #0086b3;
}
.pl-e,
.pl-en {
color: #795da3;
}
.pl-s .pl-s1,
.pl-smi {
color: #333;
}
.pl-ent {
color: #63a35c;
}
.pl-k {
color: #a71d5d;
}
.pl-pds,
.pl-s,
.pl-s .pl-pse .pl-s1,
.pl-sr,
.pl-sr .pl-cce,
.pl-sr .pl-sra,
.pl-sr .pl-sre {
color: #183691;
}
.pl-v {
color: #ed6a43;
}
.pl-id {
color: #b52a1d;
}
.pl-ii {
background-color: #b52a1d;
color: #f8f8f8;
}
.pl-sr .pl-cce {
color: #63a35c;
font-weight: bold;
}
.pl-ml {
color: #693a17;
}
.pl-mh,
.pl-mh .pl-en,
.pl-ms {
color: #1d3e81;
font-weight: bold;
}
.pl-mq {
color: #008080;
}
.pl-mi {
color: #333;
font-style: italic;
}
.pl-mb {
color: #333;
font-weight: bold;
}
.pl-md {
background-color: #ffecec;
color: #bd2c00;
}
.pl-mi1 {
background-color: #eaffea;
color: #55a532;
}
.pl-mdr {
color: #795da3;
font-weight: bold;
}
.pl-mo {
color: #1d3e81;
}
kbd {
display: inline-block;
padding: 3px 5px;
font: 11px Consolas, "Liberation Mono", Menlo, Courier, monospace;
line-height: 10px;
color: #555;
vertical-align: middle;
background-color: #fcfcfc;
border: solid 1px #ccc;
border-bottom-color: #bbb;
border-radius: 3px;
box-shadow: inset 0 -1px 0 #bbb;
}
.task-list-item {
list-style-type: none;
}
.task-list-item+.task-list-item {
margin-top: 3px;
}
.task-list-item input {
margin: 0 0.35em 0.25em -1.6em;
vertical-align: middle;
}
:checked+.radio-label {
z-index: 1;
position: relative;
border-color: #4078c0;
}
.sourceLine {
display: inline-block;
}
code .kw { color: #000000; }
code .dt { color: #ed6a43; }
code .dv { color: #009999; }
code .bn { color: #009999; }
code .fl { color: #009999; }
code .ch { color: #009999; }
code .st { color: #183691; }
code .co { color: #969896; }
code .ot { color: #0086b3; }
code .al { color: #a61717; }
code .fu { color: #63a35c; }
code .er { color: #a61717; background-color: #e3d2d2; }
code .wa { color: #000000; }
code .cn { color: #008080; }
code .sc { color: #008080; }
code .vs { color: #183691; }
code .ss { color: #183691; }
code .im { color: #000000; }
code .va {color: #008080; }
code .cf { color: #000000; }
code .op { color: #000000; }
code .bu { color: #000000; }
code .ex { color: #000000; }
code .pp { color: #999999; }
code .at { color: #008080; }
code .do { color: #969896; }
code .an { color: #008080; }
code .cv { color: #008080; }
code .in { color: #008080; }
</style>
<style>
body {
  box-sizing: border-box;
  min-width: 200px;
  max-width: 980px;
  margin: 0 auto;
  padding: 45px;
  padding-top: 0px;
}
</style>

</head>

<body>

<h1 id="example-1-initiation-to-bayesian-models">Example 1: Initiation to Bayesian models</h1>
<ul>
<li><a href="#loading-the-packages">Loading the packages</a></li>
<li><a href="#simple-linear-model-aka-a-regression">Simple linear model (<em>aka</em> a regression)</a>
<ul>
<li><a href="#fitting-the-model">Fitting the model</a></li>
<li><a href="#extracting-the-posterior">Extracting the posterior</a></li>
<li><a href="#describing-the-posterior">Describing the Posterior</a></li>
</ul></li>
<li><a href="#a-linear-model-with-a-categorical-predictor">A linear model with a categorical predictor</a>
<ul>
<li><a href="#data-preparation-and-model-fitting">Data preparation and model fitting</a></li>
<li><a href="#posterior-description">Posterior description</a></li>
<li><a href="#rope-percentage">ROPE Percentage</a></li>
<li><a href="#probability-of-direction-pd">Probability of Direction (pd)</a></li>
<li><a href="#comparison-to-frequentist">Comparison to frequentist</a></li>
</ul></li>
<li><a href="#all-with-one-function">All with one function</a></li>
</ul>
<p>This vignette can be referred to by citing the package:</p>
<ul>
<li>Makowski, D., Ben-Shachar M. S. &amp; Lüdecke, D. (2019). <em>Understand and Describe Bayesian Models and Posterior Distributions using bayestestR</em>. Available from <a href="https://github.com/easystats/bayestestR">https://github.com/easystats/bayestestR</a>. DOI: <a href="https://zenodo.org/record/2556486">10.5281/zenodo.2556486</a>.</li>
</ul>
<hr />
<p>Now that you’ve read the <a href="https://easystats.github.io/bayestestR/articles/bayestestR.html"><strong>Get started</strong></a> section, let’s dive in the <strong>subtleties of Bayesian modelling using R</strong>.</p>
<h2 id="loading-the-packages">Loading the packages</h2>
<p>Once you’ve <a href="https://easystats.github.io/bayestestR/articles/bayestestR.html#bayestestr-installation">installed</a> the necessary packages, we can load <code>rstanarm</code> (to fit the models), <code>bayestestR</code> (to compute useful indices) and <code>insight</code> (to access the parameters).</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb1-1" title="1"><span class="kw">library</span>(rstanarm)</a>
<a class="sourceLine" id="cb1-2" title="2"><span class="kw">library</span>(bayestestR)</a>
<a class="sourceLine" id="cb1-3" title="3"><span class="kw">library</span>(insight)</a></code></pre></div>
<h2 id="simple-linear-model-aka-a-regression">Simple linear model (<em>aka</em> a regression)</h2>
<p>We will begin by a simple regression to test the relationship between <strong>Petal.Length</strong> (our predictor, - or <em>independent</em>, variable) and <strong>Sepal.Length</strong> (our response, - or <em>dependent</em>, variable) from the <a href="https://en.wikipedia.org/wiki/Iris_flower_data_set"><code>iris</code></a> dataset, included by default in R.</p>
<h3 id="fitting-the-model">Fitting the model</h3>
<p>Let’s start by fitting the <strong>frequentist</strong> version of the model, just to have some <strong>reference</strong>:</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb2-1" title="1">model &lt;-<span class="st"> </span><span class="kw">lm</span>(Sepal.Length <span class="op">~</span><span class="st"> </span>Petal.Length, <span class="dt">data=</span>iris)</a>
<a class="sourceLine" id="cb2-2" title="2"><span class="kw">summary</span>(model)</a></code></pre></div>
<pre><code>&gt; 
&gt; Call:
&gt; lm(formula = Sepal.Length ~ Petal.Length, data = iris)
&gt; 
&gt; Residuals:
&gt;     Min      1Q  Median      3Q     Max 
&gt; -1.2468 -0.2966 -0.0152  0.2768  1.0027 
&gt; 
&gt; Coefficients:
&gt;              Estimate Std. Error t value Pr(&gt;|t|)    
&gt; (Intercept)    4.3066     0.0784    54.9   &lt;2e-16 ***
&gt; Petal.Length   0.4089     0.0189    21.6   &lt;2e-16 ***
&gt; ---
&gt; Signif. codes:  0 &#39;***&#39; 0.001 &#39;**&#39; 0.01 &#39;*&#39; 0.05 &#39;.&#39; 0.1 &#39; &#39; 1
&gt; 
&gt; Residual standard error: 0.41 on 148 degrees of freedom
&gt; Multiple R-squared:  0.76,    Adjusted R-squared:  0.758 
&gt; F-statistic:  469 on 1 and 148 DF,  p-value: &lt;2e-16
</code></pre>
<p>In this model, the linear relationship between <strong>Petal.Length</strong> and <strong>Sepal.Length</strong> is <strong>positive and significant</strong> (beta = 0.41, t(148) = 21.6, p &lt; .001). This means that for every increase of 1 in <strong>Petal.Length</strong> (the predictor), <strong>Sepal.Length</strong> (the response) increases by <strong>0.41</strong>. This can be visualized by plotting, using the <code>ggplot2</code> package, the predictor values on the <code>x</code> axis and the response values as <code>y</code>:</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb4-1" title="1"><span class="kw">library</span>(ggplot2)  <span class="co"># Load the package</span></a>
<a class="sourceLine" id="cb4-2" title="2"></a>
<a class="sourceLine" id="cb4-3" title="3"><span class="co"># The ggplot function takes the data as argument, and then the variables </span></a>
<a class="sourceLine" id="cb4-4" title="4"><span class="co"># related to aesthetic features such as the x and y axes.</span></a>
<a class="sourceLine" id="cb4-5" title="5"><span class="kw">ggplot</span>(iris, <span class="kw">aes</span>(<span class="dt">x=</span>Petal.Length, <span class="dt">y=</span>Sepal.Length)) <span class="op">+</span></a>
<a class="sourceLine" id="cb4-6" title="6"><span class="st">  </span><span class="kw">geom_point</span>() <span class="op">+</span><span class="st">  </span><span class="co"># This adds the points</span></a>
<a class="sourceLine" id="cb4-7" title="7"><span class="st">  </span><span class="kw">geom_smooth</span>(<span class="dt">method=</span><span class="st">&quot;lm&quot;</span>) <span class="co"># This adds a regression line</span></a></code></pre></div>
<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA8cAAAJACAMAAACXE+S8AAABHVBMVEUAAAAAADoAAGYAOjoAOpAAZrYzMzMzZv86AAA6ADo6AGY6ZmY6kNs9PT1NTU1NTW5NTY5NbqtNjo5NjshmAABmADpmAGZmOpBmZrZmkNtmtrZmtttmtv9uTU1uTW5uTY5ubqtuq+SOTU2OTW6OTY6ObquOjk2OjsiOq+SOyP+QOgCQOjqQOmaQZpCQkLaQkNuQtpCQtv+Q27aQ29uQ2/+rbk2rbo6rjk2rjqurq8ir5OSr5P+2ZgC2Zma225C2/7a2/9u2///Ijk3Ijo7Iq6vIyP/I///W1tbbkDrbkGbbkJDbtrbb25Db/7bb/9vb///kq27kq47k////tmb/tpD/yI7/yKv/yMj/25D/5Kv//7b//8j//9v//+T///9x07WQAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAX6ElEQVR4nO3dCZscR33A4bXjQ3G0S0AykMRgbBKCRTAhkXNJBmSCV5AEyxZKdKzm+3+MzLHHHH1U9/RR/+73fR7L2t3emdrjp+ruqek5WQDRnYw9AOBoOob4dAz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81uXHRdEfm21/dWGRKLjSVl3/Ph6Rt3aR07qeLW9jiPS8aRcd7w6EL693Ec+efPR4/Uh80HH6y2W5f7NvdUB9dOrF+J881e3Nu8hEh1Pyqrj57fe+uriZ6v/f7CK9/mf31+9e7/jzRZ/fffkjfvLj64m4uVH1tvfWr9nzK+CxnQ8KetpdVnqZnq9fRnvw5PDjre2WJa+iv35e482HW/aJxIdT8rVRPp0U+s63uVudsF8vLXF8r+Le7dX77nu2DFyMDqelOuON48urXpc/fWg4z/d39pivdXqSHqh46h0PClXHV/cW+1cr/eaHy/f9Xir41W/L7/7aGuL5X/Ld6w+qOOodDwh69Vam1PNq1PVb6/e8eavl3/7i1vLD7zxz/fe+uNmxddqo/UWyz/e+MdbJ2/809310fJmQdj6PQ6QQ9ExSxefLv94/l71Ui/ypWMWl0fNj6sXXpMxHbNIev4EOdMxxKdjiE/HEJ+OIT4dQ3w6hvh0DPH9P+x9ynNyClnoAAAAAElFTkSuQmCC" /><!-- --></p>
<p>Let’s fit a <strong>Bayesian version</strong> of the model:</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb5-1" title="1">model &lt;-<span class="st"> </span><span class="kw">stan_glm</span>(Sepal.Length <span class="op">~</span><span class="st"> </span>Petal.Length, <span class="dt">data=</span>iris)</a></code></pre></div>
<p>You can see the sampling algorithm being run.</p>
<h3 id="extracting-the-posterior">Extracting the posterior</h3>
<p>Once it is done, let us extract the parameters (<em>i.e.</em>, the coefficients) of the model.</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb6-1" title="1">posteriors &lt;-<span class="st"> </span>insight<span class="op">::</span><span class="kw">get_parameters</span>(model)</a>
<a class="sourceLine" id="cb6-2" title="2"></a>
<a class="sourceLine" id="cb6-3" title="3"><span class="kw">head</span>(posteriors)  <span class="co"># Show the first 6 rows</span></a></code></pre></div>
<pre><code>&gt;   (Intercept) Petal.Length
&gt; 1         4.4         0.40
&gt; 2         4.5         0.37
&gt; 3         4.3         0.41
&gt; 4         4.4         0.40
&gt; 5         4.3         0.41
&gt; 6         4.3         0.42
</code></pre>
<p>As we can see, the parameters take the form of a long dataframe with two columns, corresponding to the <strong>intercept</strong> and the effect of <strong>Petal.Length</strong>. These columns contain the <strong>posterior distributions</strong> of these two parameters, <em>i.e.</em>, a set of different plausible values.</p>
<h4 id="about-posterior-draws">About posterior draws</h4>
<p>Let’s look at the length of the posteriors.</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb8-1" title="1"><span class="kw">nrow</span>(posteriors)  <span class="co"># Size (number of rows)</span></a></code></pre></div>
<pre><code>&gt; [1] 4000
</code></pre>
<blockquote>
<p><strong>Why is the size 4000, and not more or less?</strong></p>
</blockquote>
<p>First of all, these observations (the rows) are usually referred to as <strong>posterior draws</strong>. The underlying idea is that the Bayesian sampling algorithm (such as <strong>Monte Carlo Markov Chains - MCMC</strong>) will <em>draw</em> from the hidden true posterior distribution. Thus, it is through these posterior draws that we can estimate the underlying true posterior distribution. <strong>The more draws you have, the better is your estimation of the posterior distribution</strong>. But it also takes longer to compute.</p>
<p>If we look at the documentation (<code>?sampling</code>) for the rstanarm <code>&quot;sampling&quot;</code> algorithm used by default in the model above, we can see several parameters that influence the number of posterior draws. By default, there are <strong>4</strong> <code>chains</code> (you can see it as distinct sampling runs), that each create <strong>2000</strong> <code>iter</code> (draws). However, only half of these iterations is kept, as half is used for <code>warm-up</code> (the convergence of the algorithm). The total is <strong><code>4 chains * (2000 iterations - 1000 warm-up) = 4000</code></strong> posterior draws. We can change that, for instance:</p>
<div class="sourceCode" id="cb10"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb10-1" title="1">model &lt;-<span class="st"> </span><span class="kw">stan_glm</span>(Sepal.Length <span class="op">~</span><span class="st"> </span>Petal.Length, <span class="dt">data=</span>iris, <span class="dt">chains =</span> <span class="dv">2</span>, <span class="dt">iter =</span> <span class="dv">1000</span>, <span class="dt">warmup =</span> <span class="dv">250</span>)</a>
<a class="sourceLine" id="cb10-2" title="2"> </a>
<a class="sourceLine" id="cb10-3" title="3"><span class="kw">nrow</span>(insight<span class="op">::</span><span class="kw">get_parameters</span>(model))  <span class="co"># Size (number of rows)</span></a></code></pre></div>
<pre><code>[1] 1500
</code></pre>
<p>In this case, we indeed have <strong><code>2 chains * (1000 iterations - 250 warm-up) = 1500</code></strong> posterior draws. Let’s keep our first model with the default setup.</p>
<h4 id="visualizing-the-posterior-distribution">Visualizing the posterior distribution</h4>
<p>Now that we’ve understood where do these values come from, let’s look at them. We will start by visualizing the distribution of our parameter of interest, the effect of <code>Petal.Length</code>.</p>
<div class="sourceCode" id="cb12"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb12-1" title="1"><span class="kw">ggplot</span>(posteriors, <span class="kw">aes</span>(<span class="dt">x =</span> Petal.Length)) <span class="op">+</span></a>
<a class="sourceLine" id="cb12-2" title="2"><span class="st">  </span><span class="kw">geom_density</span>(<span class="dt">fill =</span> <span class="st">&quot;orange&quot;</span>)</a></code></pre></div>
<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA8cAAAJACAMAAACXE+S8AAAA8FBMVEUAAAAAADoAAGYAOpAAZrYzMzM6AAA6ADo6AGY6ZmY6kNtNTU1NTW5NTY5NbqtNjshmAABmADpmAGZmZrZmkNtmtrZmtttmtv9uTU1uTY5ubqtuq+SOTU2OTW6OTY6ObquOq+SOyP+QOgCQOjqQOmaQZpCQkLaQkNuQtpCQ27aQ29uQ2/+rbk2rbo6rjk2rq8ir5P+2ZgC2Zma2kJC225C2/7a2/9u2///Ijk3Ijo7Iq6vI///bkDrbkGbbkJDb/9vb///kq27kq47k////pQD/tmb/tpD/yI7/yKv/25D/5Kv//7b//8j//9v//+T///80miZzAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAWEElEQVR4nO3dC1sbZ3qHcfnY1CTF3W5rx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ribution represents the probability (the y axis) of different effects (the x axis). The central values are more probable than the extreme values. As you can see, this distribution ranges from about <strong>0.35 to 0.50</strong>, with the bulk of it being at around <strong>0.41</strong>.</p>
<blockquote>
<p><strong>Congrats! You’ve just described your posterior distribution.</strong></p>
</blockquote>
<p>And this is at the heart of Bayesian analysis. We don’t need <em>p</em>-values, <em>t</em>-values or degrees of freedom: <strong>everything is there, under our nose</strong>, within this <strong>posterior distribution</strong>.</p>
<p>As you can see, our description is consistent with the values of the frequentist regression (which had a beta of <strong>0.41</strong>). This is reassuring! And indeed, in most cases, a <strong>Bayesian analysis does not drastically change the results</strong> or their interpretation. Rather, it makes the results more interpretable, intuitive and easy to understand and describe.</p>
<p>We can now go ahead and <strong>precisely characterize</strong> this posterior distribution.</p>
<h3 id="describing-the-posterior">Describing the Posterior</h3>
<p>Unfortunately, it is often not practical to report the whole posterior distributions as graphs. We need to find a <strong>concise way to summarize it</strong>. We recommend to describe the posterior distribution with <strong>3 elements</strong>. A <strong>point-estimate</strong>, a one-value summary (similar to the <em>beta</em> in frequentist regressions); a <strong>credible interval</strong>, representing the associated uncertainty and some <strong>indices of significance</strong>, giving information about the importance of this effect.</p>
<h4 id="point-estimate">Point-estimate</h4>
<p><strong>What single value can best represent my posterior distribution?</strong></p>
<p>Centrality indices, such as the <em>mean</em>, the <em>median</em> or the <em>mode</em> are usually used as point-estimates. What’s the difference? Let’s check the <strong>mean</strong>:</p>
<div class="sourceCode" id="cb13"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb13-1" title="1"><span class="kw">mean</span>(posteriors<span class="op">$</span>Petal.Length)</a></code></pre></div>
<pre><code>&gt; [1] 0.41
</code></pre>
<p>This is close to the frequentist beta. But as we know, the mean is quite sensitive to outliers or extremes values. Maybe the <strong>median</strong> could be more robust?</p>
<div class="sourceCode" id="cb15"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb15-1" title="1"><span class="kw">median</span>(posteriors<span class="op">$</span>Petal.Length)</a></code></pre></div>
<pre><code>&gt; [1] 0.41
</code></pre>
<p>Well, this is <strong>close to the mean</strong>. Maybe we could take the <strong>mode</strong>, the <em>peak</em> of the posterior distribution? In the Bayesian framework, this value is called the <strong>Maximum A Posteriori (MAP)</strong>. Let’s see:</p>
<div class="sourceCode" id="cb17"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb17-1" title="1"><span class="kw">map_estimate</span>(posteriors<span class="op">$</span>Petal.Length)</a></code></pre></div>
<pre><code>&gt; MAP = 0.41
</code></pre>
<p><strong>They are all very close!</strong> Let’s visualize these values on the posterior distribution:</p>
<div class="sourceCode" id="cb19"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb19-1" title="1"><span class="kw">ggplot</span>(posteriors, <span class="kw">aes</span>(<span class="dt">x =</span> Petal.Length)) <span class="op">+</span></a>
<a class="sourceLine" id="cb19-2" title="2"><span class="st">  </span><span class="kw">geom_density</span>(<span class="dt">fill =</span> <span class="st">&quot;orange&quot;</span>) <span class="op">+</span></a>
<a class="sourceLine" id="cb19-3" title="3"><span class="st">  </span><span class="co"># The mean in blue</span></a>
<a class="sourceLine" id="cb19-4" title="4"><span class="st">  </span><span class="kw">geom_vline</span>(<span class="dt">xintercept=</span><span class="kw">mean</span>(posteriors<span class="op">$</span>Petal.Length), <span class="dt">color=</span><span class="st">&quot;blue&quot;</span>, <span class="dt">size=</span><span class="dv">1</span>) <span class="op">+</span></a>
<a class="sourceLine" id="cb19-5" title="5"><span class="st">  </span><span class="co"># The median in red</span></a>
<a class="sourceLine" id="cb19-6" title="6"><span class="st">  </span><span class="kw">geom_vline</span>(<span class="dt">xintercept=</span><span class="kw">median</span>(posteriors<span class="op">$</span>Petal.Length), <span class="dt">color=</span><span class="st">&quot;red&quot;</span>, <span class="dt">size=</span><span class="dv">1</span>) <span class="op">+</span></a>
<a class="sourceLine" id="cb19-7" title="7"><span class="st">  </span><span class="co"># The MAP in purple</span></a>
<a class="sourceLine" id="cb19-8" title="8"><span class="st">  </span><span class="kw">geom_vline</span>(<span class="dt">xintercept=</span><span class="kw">map_estimate</span>(posteriors<span class="op">$</span>Petal.Length), <span class="dt">color=</span><span class="st">&quot;purple&quot;</span>, <span class="dt">size=</span><span class="dv">1</span>)</a></code></pre></div>
<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA8cAAAJACAMAAACXE+S8AAAA9lBMVEUAAAAAADoAAGYAOpAAZrYzMzM6AAA6ADo6AGY6ZmY6kNtNTU1NTW5NTY5NbqtNjshmAABmADpmAGZmZrZmkNtmtrZmtttmtv9uTU1uTY5ubqtuq+SOTU2OTW6OTY6ObquOq+SOyP+QOgCQOjqQOmaQZpCQkLaQkNuQtpCQ27aQ29uQ2/+gIPCrbk2rbo6rjk2rq8ir5P+2ZgC2Zma2kJC225C2/7a2/9u2///Ijk3Ijo7Iq6vI///bkDrbkGbbkJDb/9vb///kq27kq47k////AAD/pQD/tmb/tpD/yI7/yKv/25D/5Kv//7b//8j//9v//+T///9r+e0/AAAACXBIWXMAAA7DAAAOwwHHb6hkAAAXnElEQVR4nO3dC3sTx3rAcXFtipNCTy+QOEkPtE0vOGmd3iDFPScO2HUxNvr+X6ZayZZ1Wa1md+edeS////PEGHsOcMbvj9FKMppMich6k9p/ACIaHY6J7IdjIvvhmMh+OCayH46J7NfTMeyVd3Q0/+HDh8p/Diobjn2F45jh2Fc4jhmOfYXjmOHYVziOGY59heOY4dhXOI4Zjn2F45jh2Fc4jhmOfYXjmOHYVziOGY59heOY4dhXOI4Zjn2F45jh2Fc4jhmOfYXjmHXA/PzjwZfH0+nli+bt/uWkIRzHrAPmb8fTt3/2/uq748uv3yUsJw3hOGbdMGeCL57ODuaXacupejiO2R7H37w/fTqdvj1sfvJoFo6Vh+OYdcO8OJyeHt463r+cqofjmHXCvPqb9zi2FY5j1gnzl3ezI5nrY0vhOGZdME9fTi9/39xf/c37lOWkIBzHrAPm24OD5gFkHj821OToaDKZ4DhcPJ/LS5Oms6Oj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AAAAASUVORK5CYII=" /><!-- --></p>
<p>Well, all these values give very similar results. Thus, <strong>we will chose the median</strong>, as this value has a direct meaning from a probabilistic perspective: <strong>there is 50% chance that the true effect is higher and 50% chance that the effect is lower</strong> (as it <em>cuts</em> the distribution in two equal parts).</p>
<h4 id="uncertainty">Uncertainty</h4>
<p>Now that the have a point-estimate, we have to <strong>describe the uncertainty</strong>. We could compute the range:</p>
<div class="sourceCode" id="cb20"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb20-1" title="1"><span class="kw">range</span>(posteriors<span class="op">$</span>Petal.Length)</a></code></pre></div>
<pre><code>&gt; [1] 0.35 0.48
</code></pre>
<p>But does it make sense to include all these extreme values? Probably not. Thus, we will compute a <a href="https://easystats.github.io/bayestestR/articles/credible_interval.html"><strong>credible interval</strong></a>. Long story short, it’s kind of similar to a frequentist <strong>confidence interval</strong>, but it is easier to interpret and easier to compute. <em>And it makes more sense</em>.</p>
<p>We will compute this <strong>credible interval</strong> based on the <a href="https://easystats.github.io/bayestestR/articles/credible_interval.html#different-types-of-cis">Highest Density Interval (HDI)</a>. It will give us the range containing the 89% more probable effect values. <strong>Note that we will use 89% CIs instead of 95%</strong> CIs (as in the frequentist framework), as the 89% level gives more <a href="https://easystats.github.io/bayestestR/articles/credible_interval.html#why-is-the-default-89">stable results</a> (Kruschke 2014) and reminds us about the arbitrarity of such conventions (McElreath 2018).</p>
<div class="sourceCode" id="cb22"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb22-1" title="1"><span class="kw">hdi</span>(posteriors<span class="op">$</span>Petal.Length, <span class="dt">ci=</span><span class="fl">0.89</span>)</a></code></pre></div>
<pre><code>&gt; # Highest Density Interval
&gt; 
&gt;       89% HDI
&gt;  [0.38, 0.44]
</code></pre>
<p>Nice, so we can conclude that <strong>the effect has 89% chance of falling within the <code>[0.38, 0.44]</code> range</strong>. We have just computed the two most important information to describe our effects.</p>
<h4 id="effect-significance">Effect significance</h4>
<p>However, in many scientific fields, simply describing the effect is not enough. The readers also want to know if this effect <em><strong>means</strong></em> something. Is it important? Is it different from 0? In other words, <strong>assessing the <em>significance</em> of the effect</strong>. How can we do this?</p>
<p>Well, in this particular case, it is very eloquent: <strong>all possible effect values (<em>i.e.</em>, the whole posterior distribution) are positive and superior to 0.35, which is already a lot</strong>.</p>
<p>But still, we want some objective decision criterion, to say if <strong>yes or no the effect is significant</strong>. We could do similarly to the frequentist framework, and see if the <strong>Credible Interval</strong> contains 0. Here, it is not the case, which means that our <strong>effect is significant</strong>.</p>
<p>But this index is not very fine-grained, isn’t it? <strong>Can we do better? Yes.</strong></p>
<h2 id="a-linear-model-with-a-categorical-predictor">A linear model with a categorical predictor</h2>
<p>Let’s take interest in the <strong>weight of chickens</strong>, depending on 2 <strong>feed types</strong>. We will start by selecting, from the <code>chickwts</code> dataset (also available in base R), the 2 feed types that are of interest for us (<em>because reasons</em>): <strong>Meat meals</strong> and <strong>Sunflowers</strong>.</p>
<h3 id="data-preparation-and-model-fitting">Data preparation and model fitting</h3>
<div class="sourceCode" id="cb24"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb24-1" title="1"><span class="kw">library</span>(dplyr)</a>
<a class="sourceLine" id="cb24-2" title="2"></a>
<a class="sourceLine" id="cb24-3" title="3"><span class="co"># We keep only rows for which feed is meatmeal or sunflower</span></a>
<a class="sourceLine" id="cb24-4" title="4">data &lt;-<span class="st"> </span>chickwts <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb24-5" title="5"><span class="st">  </span><span class="kw">filter</span>(feed <span class="op">%in%</span><span class="st"> </span><span class="kw">c</span>(<span class="st">&quot;meatmeal&quot;</span>, <span class="st">&quot;sunflower&quot;</span>))</a></code></pre></div>
<p>Let’s run another Bayesian regression to predict the <strong>Weight</strong> with the <strong>2 types of feed type</strong>.</p>
<div class="sourceCode" id="cb25"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb25-1" title="1">model &lt;-<span class="st"> </span><span class="kw">stan_glm</span>(weight <span class="op">~</span><span class="st"> </span>feed, <span class="dt">data=</span>data)</a></code></pre></div>
<h3 id="posterior-description">Posterior description</h3>
<div class="sourceCode" id="cb26"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb26-1" title="1">posteriors &lt;-<span class="st"> </span>insight<span class="op">::</span><span class="kw">get_parameters</span>(model)</a>
<a class="sourceLine" id="cb26-2" title="2"></a>
<a class="sourceLine" id="cb26-3" title="3"><span class="kw">ggplot</span>(posteriors, <span class="kw">aes</span>(<span class="dt">x=</span>feedsunflower)) <span class="op">+</span></a>
<a class="sourceLine" id="cb26-4" title="4"><span class="st">  </span><span class="kw">geom_density</span>(<span class="dt">fill =</span> <span class="st">&quot;red&quot;</span>)</a></code></pre></div>
<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA8cAAAJACAMAAACXE+S8AAAA5FBMVEUAAAAAADoAAGYAOpAAZmYAZpAAZrYzMzM6AAA6ADo6AGY6OpA6ZmY6kNtNTU1NTW5NTY5NjshmAABmADpmAGZmZmZmZrZmkJBmkNtmtrZmtttmtv9uTU1uTY5ubqtuq+SOTU2OTW6OTY6OyP+QOgCQOjqQOmaQZpCQkLaQkNuQtpCQtv+Q2/+rbk2rbo6r5P+2ZgC2Zma2kJC2tma2/7a2/9u2///Ijk3Ijo7I///bkDrbkGbbkJDb/9vb///kq27kq47k////AAD/tmb/yI7/25D/5Kv//7b//8j//9v//+T///86xz7VAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAVH0lEQVR4nO3dDXsTV3qAYSVpgW0LidnttikkTgLtpi0JpB+wsNuQxGA+9P//TzWyZUuyPkajmTPnvOe+ryvyWHgwM3qfjGYk8GQKlG4y9h8AOJqOoXw6hvLpGMqnYyifjqF8x3Xs/wKQAx1D+XQM5dMxlE/HUD4dQ/l0DOXTMZRPx1A+HUP5dAzl0zGUT8dQPh1D+XQM5dMxlE/HUD4dQ/l0DOXTMZRPx1A+H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zx81Xfvbz7PbT/7k/W//s4pPZym/vfHn/0+djbxW76Dig5uj64V+fNB8vP8xPl59NHrz9+5+nf31+cQT+cl7rJ08uj8cfHt+dpdy02yQ9Ozz/9Pxi5X+cpa/izOk4oKbMs/mPub57+eHt757M735759b06pn0/MPvFh2fNbE2y6+alm9N3/1x8Xt40p0/HQc07/jievXlh1eLSN/emdxa6fjqw/xL3t2/26R99uXvn/zlyWJlHedPxwHNO754Lrz48MmTRY9nkwcbOz5rXnqaX+l+duun58/+9k8/L1bWcf50HND8/Hh2qjs9u3v54V1zoapp9j/nLxfPjrqv1nP+8Hj2Ja+aI/DZ5O50XvXlyjrOn47jaU5rZ+e395vb5Q8z/3Rn/tmzyeQf7lxcp57f/Tf3Ly9wz59Iv/vD8/l/lys3N0LOnI6hfDqG8ukYyqdjKJ+OoXw6hvLpGMqnYyifjqF8Ooby/T9UturhSMXYfAAAAABJRU5ErkJggg==" /><!-- --></p>
<p>This represents the <strong>posterior distribution of the difference between meat meals and Sunflowers</strong>. Seems that the difference is rather <strong>positive</strong>… Eating Sunflowers makes you more fat (if you’re a chicken). <strong>By how much?</strong> Let us compute the <strong>median</strong> and the <strong>CI</strong>:</p>
<div class="sourceCode" id="cb27"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb27-1" title="1"><span class="kw">median</span>(posteriors<span class="op">$</span>feedsunflower)</a></code></pre></div>
<pre><code>&gt; [1] 51
</code></pre>
<div class="sourceCode" id="cb29"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb29-1" title="1"><span class="kw">hdi</span>(posteriors<span class="op">$</span>feedsunflower)</a></code></pre></div>
<pre><code>&gt; # Highest Density Interval
&gt; 
&gt;        89% HDI
&gt;  [7.77, 87.66]
</code></pre>
<p>It makes you fat by around <code>51</code> (the median). However, the uncertainty is quite high: <strong>there is 89% chance that the difference between the two feed types is between <code>7.77</code> and <code>87.66</code>.</strong></p>
<blockquote>
<p><strong>Is this effect different from 0?</strong></p>
</blockquote>
<h3 id="rope-percentage">ROPE Percentage</h3>
<p>Testing whether this distribution is different from 0 doesn’t make sense, as 0 is a single value (<em>and the probability that any distribution is different from a single value is infinite</em>).</p>
<p>However, one way to assess <strong>significance</strong> could be to define an area around 0, which will consider as <em>equivalent</em> to zero (to no, - or negligible, effect). This is called the <a href="https://easystats.github.io/bayestestR/articles/region_of_practical_equivalence.html"><strong>Region of Practical Equivalence (ROPE)</strong></a>, and is one way of testing the significance of parameters.</p>
<p><strong>How can we define this region?</strong></p>
<blockquote>
<p><em><strong>Driing driiiing</strong></em></p>
</blockquote>
<p>– <em><strong>The easystats team speaking. How can we help?</strong></em></p>
<p>– <em><strong>I am Prof Howard. An expert in chicks… I mean chickens. Just calling to let you know that based on my expert knowledge, an effect between -20 and 20 is negligible. Bye.</strong></em></p>
<p>Well, that’s convenient. Now we know that we can define the ROPE as the <code>[-20, 20]</code> range. All effects within this range are considered as <em>null</em> (negligible). We can now compute the <strong>proportion of the 89% most probable values (the 89% CI) which are not null</strong>, <em>i.e.</em>, which are outside this range.</p>
<div class="sourceCode" id="cb31"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb31-1" title="1"><span class="kw">rope</span>(posteriors<span class="op">$</span>feedsunflower, <span class="dt">range =</span> <span class="kw">c</span>(<span class="op">-</span><span class="dv">20</span>, <span class="dv">20</span>), <span class="dt">ci=</span><span class="fl">0.89</span>)</a></code></pre></div>
<pre><code>&gt; # Proportion of samples inside the ROPE [-20.00, 20.00]:
&gt; 
&gt;  inside ROPE
&gt;       7.75 %
</code></pre>
<p><strong>7.75% of the 89% CI can be considered as null</strong>. Is that a lot? Based on our <a href="https://easystats.github.io/bayestestR/articles/guidelines.html"><strong>guidelines</strong></a>, yes, it is too much. <strong>Based on this particular definition of ROPE</strong>, we conclude that this effect is not significant (the probability of being negligible is too high).</p>
<p>Although, to be honest, I have <strong>some doubts about this Prof Howard</strong>. I don’t really trust <strong>his definition of ROPE</strong>. Is there a more <strong>objective</strong> way of defining it?</p>
<p><strong>Yes.</strong> One of the practice is for instance to use the <strong>tenth (<code>1/10 = 0.1</code>) of the standard deviation (SD)</strong> of the response variable, which can be considered as a “negligible” effect size.</p>
<div class="sourceCode" id="cb33"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb33-1" title="1">rope_value &lt;-<span class="st"> </span><span class="fl">0.1</span> <span class="op">*</span><span class="st"> </span><span class="kw">sd</span>(data<span class="op">$</span>weight)</a>
<a class="sourceLine" id="cb33-2" title="2">rope_range &lt;-<span class="st"> </span><span class="kw">c</span>(<span class="op">-</span>rope_value, rope_value)</a>
<a class="sourceLine" id="cb33-3" title="3">rope_range</a></code></pre></div>
<pre><code>&gt; [1] -6.2  6.2
</code></pre>
<p>Let’s redefine our ROPE as the region within the <code>[-6.2, 6.2]</code> range. <strong>Note that this can be directly obtained by the <code>rope_range</code> function :)</strong></p>
<div class="sourceCode" id="cb35"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb35-1" title="1">rope_value &lt;-<span class="st"> </span><span class="kw">rope_range</span>(model)</a>
<a class="sourceLine" id="cb35-2" title="2">rope_range</a></code></pre></div>
<pre><code>&gt; [1] -6.2  6.2
</code></pre>
<p>Let’s recompute the <strong>percentage in ROPE</strong>:</p>
<div class="sourceCode" id="cb37"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb37-1" title="1"><span class="kw">rope</span>(posteriors<span class="op">$</span>feedsunflower, <span class="dt">range =</span> rope_range, <span class="dt">ci=</span><span class="fl">0.89</span>)</a></code></pre></div>
<pre><code>&gt; # Proportion of samples inside the ROPE [-6.17, 6.17]:
&gt; 
&gt;  inside ROPE
&gt;       0.00 %
</code></pre>
<p>With this reasonable definition of ROPE, we observe that the 89% of the posterior distribution of the effect does <strong>not</strong> overlap with the ROPE. Thus, we can conclude that <strong>the effect is significant</strong> (in the sense of <em>important</em> enough to be noted).</p>
<h3 id="probability-of-direction-pd">Probability of Direction (pd)</h3>
<p>Maybe we are not interested in whether the effect is not-negligible. Maybe <strong>we just want to know if this effect is positive or negative</strong>. In this case, we can simply compute the proportion of the posterior that is positive, no matter the “size” of the effect.</p>
<div class="sourceCode" id="cb39"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb39-1" title="1">n_positive &lt;-<span class="st"> </span>posteriors <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb39-2" title="2"><span class="st">  </span><span class="kw">filter</span>(feedsunflower <span class="op">&gt;</span><span class="st"> </span><span class="dv">0</span>) <span class="op">%&gt;%</span><span class="st"> </span><span class="co"># select only positive values</span></a>
<a class="sourceLine" id="cb39-3" title="3"><span class="st">  </span><span class="kw">nrow</span>() <span class="co"># Get length</span></a>
<a class="sourceLine" id="cb39-4" title="4">n_positive <span class="op">/</span><span class="st"> </span><span class="kw">nrow</span>(posteriors) <span class="op">*</span><span class="st"> </span><span class="dv">100</span></a></code></pre></div>
<pre><code>&gt; [1] &quot;97.82&quot;
</code></pre>
<p>We can conclude that <strong>the effect is positive with a probability of 97.82%</strong>. We call this index the <a href="https://easystats.github.io/bayestestR/articles/probability_of_direction.html"><strong>Probability of Direction (pd)</strong></a>. It can, in fact, be computed more easily with the following:</p>
<div class="sourceCode" id="cb41"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb41-1" title="1"><span class="kw">p_direction</span>(posteriors<span class="op">$</span>feedsunflower)</a></code></pre></div>
<pre><code>&gt; # Probability of Direction (pd)
&gt; 
&gt; pd = 97.82%
</code></pre>
<p>Interestingly, it so happens that <strong>this index is usually highly correlated with the frequentist <em>p</em>-value</strong>. We could almost roughly infer the corresponding <em>p</em>-value with a simple transformation:</p>
<div class="sourceCode" id="cb43"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb43-1" title="1">pd &lt;-<span class="st"> </span><span class="fl">97.82</span></a>
<a class="sourceLine" id="cb43-2" title="2">onesided_p &lt;-<span class="st"> </span><span class="dv">1</span> <span class="op">-</span><span class="st"> </span>pd <span class="op">/</span><span class="st"> </span><span class="dv">100</span>  </a>
<a class="sourceLine" id="cb43-3" title="3">twosided_p &lt;-<span class="st"> </span>onesided_p <span class="op">*</span><span class="st"> </span><span class="dv">2</span></a>
<a class="sourceLine" id="cb43-4" title="4">twosided_p</a></code></pre></div>
<pre><code>&gt; [1] 0.044
</code></pre>
<p>If we ran our model in the frequentist framework, we should approximately observe an effect with a <em>p</em>-value of 0.04. <strong>Is that true?</strong></p>
<h3 id="comparison-to-frequentist">Comparison to frequentist</h3>
<div class="sourceCode" id="cb45"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb45-1" title="1"><span class="kw">lm</span>(weight <span class="op">~</span><span class="st"> </span>feed, <span class="dt">data=</span>data) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb45-2" title="2"><span class="st">  </span><span class="kw">summary</span>()</a></code></pre></div>
<pre><code>&gt; 
&gt; Call:
&gt; lm(formula = weight ~ feed, data = data)
&gt; 
&gt; Residuals:
&gt;     Min      1Q  Median      3Q     Max 
&gt; -123.91  -25.91   -6.92   32.09  103.09 
&gt; 
&gt; Coefficients:
&gt;               Estimate Std. Error t value Pr(&gt;|t|)    
&gt; (Intercept)      276.9       17.2   16.10  2.7e-13 ***
&gt; feedsunflower     52.0       23.8    2.18     0.04 *  
&gt; ---
&gt; Signif. codes:  0 &#39;***&#39; 0.001 &#39;**&#39; 0.01 &#39;*&#39; 0.05 &#39;.&#39; 0.1 &#39; &#39; 1
&gt; 
&gt; Residual standard error: 57 on 21 degrees of freedom
&gt; Multiple R-squared:  0.185,   Adjusted R-squared:  0.146 
&gt; F-statistic: 4.77 on 1 and 21 DF,  p-value: 0.0405
</code></pre>
<p>The frequentist model tells us that the difference is <strong>positive and significant</strong> (beta = 52, p = 0.04).</p>
<p><strong>Although we arrived to a similar conclusion, the Bayesian framework allowed us to develop a more profound and intuitive understanding of our effect, and of the uncertainty of its estimation.</strong></p>
<h2 id="all-with-one-function">All with one function</h2>
<p>And yet, I agree, it was a bit <strong>tedious</strong> to extract and compute all the indices. <strong>But what if I told you that we can do all of this, and more, with only one function?</strong></p>
<blockquote>
<p><strong>Behold, <code>describe_posterior</code>!</strong></p>
</blockquote>
<p>This function computes all of the adored mentioned indices, and can be run directly on the model:</p>
<div class="sourceCode" id="cb47"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb47-1" title="1"><span class="kw">describe_posterior</span>(model)</a></code></pre></div>
<pre><code>&gt;       Parameter Median CI CI_low CI_high  pd ROPE_CI ROPE_low ROPE_high
&gt; 1   (Intercept)    277 89  250.2     307 100      89     -6.2       6.2
&gt; 2 feedsunflower     51 89    7.8      88  98      89     -6.2       6.2
&gt;   ROPE_Percentage  ESS Rhat Prior_Distribution Prior_Location Prior_Scale
&gt; 1               0 3437    1             normal              0         617
&gt; 2               0 3316    1             normal              0         154
</code></pre>
<p><strong>Tada!</strong> There we have it! The <strong>median</strong>, the <strong>CI</strong>, the <strong>pd</strong> and the <strong>ROPE percentage</strong>!</p>
<p>Understanding and describing posterior distributions is just one aspect of Bayesian modelling… <strong>Are you ready for more?</strong> <a href="https://easystats.github.io/bayestestR/articles/example2_GLM.html"><strong>Click here</strong></a> to see the next example.</p>
<div id="refs" class="references">

<div id="ref-kruschke2014doing">

<p>Kruschke, John. 2014. <em>Doing Bayesian Data Analysis: A Tutorial with R, Jags, and Stan</em>. Academic Press.</p>
</div>

<div id="ref-mcelreath2018statistical">

<p>McElreath, Richard. 2018. <em>Statistical Rethinking: A Bayesian Course with Examples in R and Stan</em>. Chapman; Hall/CRC.</p>
</div>

</div>

</body>
</html>
back to top