import numpy
import scipy.stats as stats
from datascience import *
%matplotlib inline
import matplotlib.pyplot as plots
plots.style.use('fivethirtyeight')
import numpy as np
import scipy.stats as stats
def biasdemo1():
np.random.seed(15)
Population = np.random.normal(15000,500,100000)
PopSigma = np.round(np.std(Population),0)
Biased = make_array()
Unbiased=make_array()
reps = 20
for i in np.arange(reps):
Sample = np.random.choice(Population, 3)
Biased = np.append(Biased, np.std(Sample))
Unbiased = np.append(Unbiased, stats.tstd(Sample))
biasedmean = np.round(np.mean(Biased),0)
unbiasedmean = np.round(np.mean(Unbiased),0)
plots.figure(figsize=(12,6))
plots.suptitle("Biased = Bad, Unbiased = Good")
plots.subplot(1,2,1)
plots.hist(Biased)
plots.scatter(PopSigma, -3, marker="^", zorder=5, s=80, color='green')
plots.scatter(np.mean(Biased),-3, marker = "s", zorder=5, s=80, color='red')
plots.title("Biased Estimator of Sigma")
plots.text(710, 0.1*reps, f"Estimator = {biasedmean}", color='red')
plots.text(710, 0.085*reps,f"True Value = {PopSigma}", color='green');
plots.subplot(1,2,2)
plots.hist(Unbiased)
plots.scatter(PopSigma, -3, marker="^", zorder=5, s=80, color='green')
plots.scatter(np.mean(Unbiased),-3, marker = "s", zorder=5, s=80, color='red')
plots.title("Unbiased Estimator of Sigma")
plots.text(710, 0.1*reps, f"Estimator = {unbiasedmean}", color='red')
plots.text(710, 0.085*reps,f"True Value = {PopSigma}", color='green');