Login
📚 Statistical Inference for Everyone
Chapters ▾

11.4 Hierarchical Model Example - Kruschke BEST Test

A comparison between means is a standard statistical technique. However, using a hierarchical model can be superior to the typical tests.

In this example, we use the Kruschke BEST Test to compare the difference between a treatment and control - we want to obtain the best estimate of the difference between the means of variables. With the MCMC technique, we can achieve it with the following,

from sie import *
drug = (101,100,102,104,102,97,105,105,98,
        101,100,123,105,103,100,95,102,106,
        109,102,82,102,100,102,102,101,102,
        102,103,103,97,97,103,101,97,104,
        96,103,124,101,101,100,101,101,104,
        100,101)
placebo = (99,101,100,101,102,100,97,101,
           104,101,102,102,100,105,88,101,100,
           104,100,100,100,101,102,103,97,101,
           101,100,101,99,101,100,100,
           101,100,99,101,100,102,99,100,99)


model=mcmc.BESTModel(drug,placebo)
model.run_mcmc()
Show expected output
Running MCMC...
Done.
5.80 s
model.names
Show expected output
['mu1', 'mu2', 'sigma1', 'sigma2', 'nu']
model.plot_chains('mu1')
Dense overlaid MCMC chains for μ1, the mean of the drug group, over 100 time steps: a solid black band oscillating between about 100.5 and 102.5, centered near 101.5, with no drift.
Figure 11.6. Chains for parameter mu1, the mean of the drug group.
model.plot_distribution('mu1')
Sampled posterior distribution for μ1, the drug-group mean: a jagged bell peaking near 101.5, titled μ1=101.560 (+0.730/-0.743), spanning roughly 100 to 103.
Figure 11.7. Distribution for parameter mu1, the mean of the drug group.
model.plot_distribution('mu2')
model.plot_distribution(r'$\delta$=mu1-mu2')
Sampled posterior for δ, the drug-minus-placebo difference in means: a jagged bell titled δ=1.033 (+0.848/-0.864), peaking near 1.0 and spanning about -0.5 to 2.5; most of the area lies above zero.
Figure 11.8. Distribution for parameter δ, the mean of the difference between the drug group and the placebo group.

We can clearly see from the distribution of δ, as well as the credible ranges, that there is significant evidence for a non-zero effect. We would want to extend this to include the effect size, and explore the prior probability of the the drug working, in order to reasonably assess whether this is an effect worth pursuing.

Adapted from Statistical Inference for Everyone, by Brian Blais (Bryant University), licensed under CC BY-SA 4.0 (dual-licensed under the GNU FDL 1.2 or later; this adaptation uses the CC BY-SA grant). Changes were made; this adaptation is distributed under the same license. License: CC-BY-SA-4.0.