Jupyter Snippet CB2nd 02_z_test

Jupyter Snippet CB2nd 02_z_test

7.2. Getting started with statistical hypothesis testing — a simple z-test

import numpy as np
import scipy.stats as st
import scipy.special as sp
n = 100  # number of coin flips
h = 61  # number of heads
q = .5  # null-hypothesis of fair coin
xbar = float(h) / n
z = (xbar - q) * np.sqrt(n / (q * (1 - q)))
# We don't want to display more than 4 decimals.
z
 2.2000
pval = 2 * (1 - st.norm.cdf(z))
pval
 0.0278