Statistical Inference for EveryoneXYZ Homework Edition

⇩ Download ▾

7.6 Computer Examples

from sie import *

Estimating Lengths

Known deviation, σ\sigma

x=[5.1, 4.9, 4.7, 4.9, 5.0]
sigma=0.5
mu=sample_mean(x)
N=len(x)
dist=normal(mu,sigma/sqrt(N))
distplot(dist)
Show expected output
<matplotlib.figure.Figure at 0x10713c710>
Posterior curve for the true length computed by the sample code, with dashed percentile lines: 1% at 4.40, 5% at 4.55, 25% at 4.77, 50% at 4.92, 75% at 5.07, 95% at 5.29 and 99% at 5.44.
credible_interval(dist)
Show expected output
(4.4817387297117088, 4.9199999999999999, 5.358261270288291)

Unknown σ\sigma

mu=sample_mean(x)
s=sample_deviation(x)
print mu,s
Show expected output
4.92 0.148323969742
dist=tdist(N-1,mu,s/sqrt(N))
distplot(dist,xlim=[4.6,5.4])
Show expected output
<matplotlib.figure.Figure at 0x1085b5c50>
A narrower posterior curve for the true length from the Student-t form, with dashed percentile lines: 1% at 4.67, 5% at 4.78, 25% at 4.87, 50% at 4.92, 75% at 4.97, 95% at 5.06 and 99% at 5.17.
credible_interval(dist)
Show expected output
(4.7358314667008017, 4.9199999999999999, 5.1041685332991982)

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.