In [1]:
# Imports
import os
import sys
import pandas as pd
import seaborn as sb
# Custom Imports
sys.path.insert(0, '../../')
import stats_toolbox as st
from stats_toolbox.utils.data_loaders import load_fem_preg_2002
# Graphics setup
%pylab inline --no-import-all
In [2]:
# Load and Clean Data
df = load_fem_preg_2002('../data')
full_term = df[df['prglngth'] >= 37]
weights = df.birthwgt_kg.dropna()
As twith histograms, and list like object or pandas Series can be converted to a Pmf object. Hist objects can also be converted using the Pmf constructor or with their to_pmf() method
In [4]:
# Convert to PMF
pmf = st.Pmf(full_term.totalwgt_lb, label='Total Birth Weight')
H = st.Hist(full_term.totalwgt_lb, label='Total Birth Weight')
In [5]:
pmf == H.to_pmf()
Out[5]:
In [ ]:
Individual probabilities can be looked up
In [7]:
pmf[8]
# same as pmf.prob(8)
Out[7]:
In [ ]:
pmf.mean()
pmf.var()
pmf.std()
pmf.maximum_likelihood()
In [ ]:
pmf.prob_less(3)
pmf.prob_greater(4)
In [9]:
# Arithmatic
pmf_first = st.Pmf(full_term.prglngth[full_term.birthord == 1], label='1st born')
pmf_other = st.Pmf(full_term.prglngth[full_term.birthord != 1], label='other')
In [10]:
(pmf_first - pmf_other).plot()
Out[10]:
In [24]:
fig = st.multiplot((pmf_first, pmf_other))
In [20]:
pmf_other
Out[20]:
In [21]:
pmf_first
Out[21]:
In [ ]: