Skip to content

Commit 3313b5d

Browse files
committed
misc updates
1 parent 535534b commit 3313b5d

File tree

2 files changed

+68
-8
lines changed

2 files changed

+68
-8
lines changed

examples/howto/hypothesis_testing.ipynb

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
" * Posterior probability statements\n",
6161
" * Highest Density Intervals (HDIs)\n",
6262
" * Regions of Practical Equivalence (ROPE)\n",
63-
" * Bayes Factors using ArviZ's `plot_bf` function\n",
63+
" * Bayes Factors\n",
6464
"\n",
6565
"We'll work through a scenario where we want to know if the mean of some metric (e.g., monthly profit) is different from zero."
6666
]
@@ -77,6 +77,22 @@
7777
":::"
7878
]
7979
},
80+
{
81+
"cell_type": "markdown",
82+
"id": "6292d775",
83+
"metadata": {},
84+
"source": [
85+
"### Parameter estimation vs model comparison\n",
86+
"\n",
87+
"The Bayesian evaluation of null values can proceed in two distinct ways (see {cite:t}`kruschke2011bayesian`):\n",
88+
"\n",
89+
"#### Parameter estimation\n",
90+
"The parameter estimation approach considers a model where the parameter is allowed to vary (which includes the null value). We then compute the posterior distribution of this value and come up with some kind of decision rule which determines if we accept or reject the null value.\n",
91+
"\n",
92+
"#### Model comparison\n",
93+
"Two competing models are considered. The first model assumes that the null value is true, or fixed, and the second model allows a range of values. The models are compared to see which is more supported by the data. An example would be in assessing if a coin is fair (null hypothesis) or biased (alternative hypothesis) - we would set up a model where the coin has a fixed probability of heads (0.5) and another model where the probability of heads is a free parameter. Readers are referred to the PyMC examples focussing on {ref}`pymc:model_comparison` for more details."
94+
]
95+
},
8096
{
8197
"cell_type": "markdown",
8298
"id": "5c268654",
@@ -525,6 +541,14 @@
525541
"az.plot_posterior(idata, var_names=[\"mu\"], rope=rope, figsize=(14, 3));"
526542
]
527543
},
544+
{
545+
"cell_type": "markdown",
546+
"id": "5fc84f7a",
547+
"metadata": {},
548+
"source": [
549+
"The intuition we can get from this is that if the ROPE is narrow, we would require quite a high level of precision to accept the null hypthesis. The posterior distribution would have to be very tightly centered around the null value to have a large probability of being within the ROPE."
550+
]
551+
},
528552
{
529553
"cell_type": "markdown",
530554
"id": "46cf08f2",
@@ -538,11 +562,15 @@
538562
"id": "de465219",
539563
"metadata": {},
540564
"source": [
541-
"{cite:t}`kruschke2018rejecting` outlines the HDI+ROPE decision rule, which is summarised in the figure taken from that paper:\n",
565+
"{cite:t}`kruschke2018rejecting` outlines the HDI+ROPE decision rule, which is summarised in the figure taken from that paper. Namely:\n",
566+
"\n",
567+
"* **Accept the null value**: If the HDI falls entirely within the ROPE. The HDI does not need to include the null value.\n",
568+
"* **Reject the null value**: If the HDI falls entirely outside the ROPE. \n",
569+
"* **Remain undecided**: If the HDI is partially or fully outside the ROPE.\n",
542570
"\n",
543-
"![](hdi_plus_rope_decision_rule.png)\n",
571+
"In our case, looking back at our posterior + ROPE plot above, we would remain undecided because the HDI does not fall entirely outside nor within the ROPE.\n",
544572
"\n",
545-
"In our case, we would remain undecided because the HDI does not fall entirely outside nor within the ROPE."
573+
"![](hdi_plus_rope_decision_rule.png)"
546574
]
547575
},
548576
{
@@ -602,6 +630,14 @@
602630
"We can see that the probability of $\\mu=0$ has gone _down_ after observing the data. This is reflected in the value of $BF_{01}=0.54$ in that it is less than 1."
603631
]
604632
},
633+
{
634+
"cell_type": "markdown",
635+
"id": "4283bdd3",
636+
"metadata": {},
637+
"source": [
638+
"Readers are referred to {ref}`Bayes_factor` for a more detailed look at Bayes Factors."
639+
]
640+
},
605641
{
606642
"cell_type": "markdown",
607643
"id": "650f409c",

examples/howto/hypothesis_testing.myst.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ In this tutorial, we'll use PyMC to:
4545
* Posterior probability statements
4646
* Highest Density Intervals (HDIs)
4747
* Regions of Practical Equivalence (ROPE)
48-
* Bayes Factors using ArviZ's `plot_bf` function
48+
* Bayes Factors
4949

5050
We'll work through a scenario where we want to know if the mean of some metric (e.g., monthly profit) is different from zero.
5151

@@ -59,6 +59,18 @@ However, in real-world scenarios—such as policy-making, resource allocation, o
5959

6060
+++
6161

62+
### Parameter estimation vs model comparison
63+
64+
The Bayesian evaluation of null values can proceed in two distinct ways (see {cite:t}`kruschke2011bayesian`):
65+
66+
#### Parameter estimation
67+
The parameter estimation approach considers a model where the parameter is allowed to vary (which includes the null value). We then compute the posterior distribution of this value and come up with some kind of decision rule which determines if we accept or reject the null value.
68+
69+
#### Model comparison
70+
Two competing models are considered. The first model assumes that the null value is true, or fixed, and the second model allows a range of values. The models are compared to see which is more supported by the data. An example would be in assessing if a coin is fair (null hypothesis) or biased (alternative hypothesis) - we would set up a model where the coin has a fixed probability of heads (0.5) and another model where the probability of heads is a free parameter. Readers are referred to the PyMC examples focussing on {ref}`pymc:model_comparison` for more details.
71+
72+
+++
73+
6274
## Setting up the example
6375

6476
Rather than focus on a complex example, we'll pick a trivial one were we are simply estimating the mean of a single variable. This will allow us to focus on the hypothesis testing. The important thing is what we do with our MCMC samples, not the particulars of the model.
@@ -179,15 +191,23 @@ Third time in a row, `arviz` has our back and can plot the ROPE and HDIs.
179191
az.plot_posterior(idata, var_names=["mu"], rope=rope, figsize=(14, 3));
180192
```
181193

194+
The intuition we can get from this is that if the ROPE is narrow, we would require quite a high level of precision to accept the null hypthesis. The posterior distribution would have to be very tightly centered around the null value to have a large probability of being within the ROPE.
195+
196+
+++
197+
182198
### HDI+ROPE decision criteria
183199

184200
+++
185201

186-
{cite:t}`kruschke2018rejecting` outlines the HDI+ROPE decision rule, which is summarised in the figure taken from that paper:
202+
{cite:t}`kruschke2018rejecting` outlines the HDI+ROPE decision rule, which is summarised in the figure taken from that paper. Namely:
187203

188-
![](hdi_plus_rope_decision_rule.png)
204+
* **Accept the null value**: If the HDI falls entirely within the ROPE. The HDI does not need to include the null value.
205+
* **Reject the null value**: If the HDI falls entirely outside the ROPE.
206+
* **Remain undecided**: If the HDI is partially or fully outside the ROPE.
189207

190-
In our case, we would remain undecided because the HDI does not fall entirely outside nor within the ROPE.
208+
In our case, looking back at our posterior + ROPE plot above, we would remain undecided because the HDI does not fall entirely outside nor within the ROPE.
209+
210+
![](hdi_plus_rope_decision_rule.png)
191211

192212
+++
193213

@@ -212,6 +232,10 @@ We can see that the probability of $\mu=0$ has gone _down_ after observing the d
212232

213233
+++
214234

235+
Readers are referred to {ref}`Bayes_factor` for a more detailed look at Bayes Factors.
236+
237+
+++
238+
215239
## Summary
216240

217241
**Posterior Probability Statements**

0 commit comments

Comments
 (0)