Statistical Inference for EveryoneXYZ Homework Edition

⇩ Download ▾

6.11 Computer Examples

from sie import *

Beta Distribution Example

3 heads and 9 tails

Plot a beta distribution with 3 heads and 9 tails...

dist=beta(h=1,N=3)
distplot(dist,xlim=[0,1],show_quartiles=False)
Smooth posterior curve for a proportion computed in the sample code: it rises from zero at 0, peaks near 0.33 at a density of about 1.8, and returns to zero at 1.

The median of this distribution...

dist.median()
Show expected output
0.27527583248615201

the 95

credible_interval(dist)
Show expected output
(0.067585986488542985, 0.38572756813238962, 0.80587955031675662)

1 heads and 3 tails

This should be about the same fraction as the previous example, but broader

dist=beta(h=1,N=4)
distplot(dist,xlim=[0,1])
Show expected output
<matplotlib.figure.Figure at 0x108768cd0>
The same posterior curve annotated with dashed percentile lines from the distribution object: 1% at 0.03, 5% at 0.08, 10% at 0.11, 25% at 0.19, 50% at 0.31, 75% at 0.45, 90% at 0.58, 95% at 0.66 and 99% at 0.78.
credible_interval(dist)
Show expected output
(0.052744950526316919, 0.31381017045569742, 0.71641793611808946)

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.

These eBooks are a prerelease and are not yet certified conformant with WCAG 2.1 AA or ADA Title II. Every page is built against an automated accessibility gate, and the published editions will meet ADA Title II requirements when they release in late September 2026. If something is unusable, please tell us.