<jupyter_start><jupyter_text>Simpson's paradox **[Sex Bias in Graduate Admissions: Data from Berkeley](https://pdfs.semanticscholar.org/b704/3d57d399bd28b2d3e84fb9d342a307472458.pdf)***[https://pdfs.semanticscholar.org/b704/3d57d399bd28b2d3e84fb9d342a307472458.pdf](https://pdfs.semanticscholar.org/b704/3d57d399bd28b2d3e84fb9d342a307472458.pdf)*  Example from article  Actual data<jupyter_code>admission_rate = (3738 + 1494) / 12763
admission_rate
total_men = 3738 + 4704
total_men
expect_men_admitted = total_men * admission_rate
expect_men_admitted
total_women = 1494 + 2827
total_women
expect_women_admitted = total_women * admission_rate
expect_women_admitted<jupyter_output><empty_output><jupyter_text>Data in the example<jupyter_code>admission_rate = (250 + 250) / (250 + 250 + 300 + 400)
admission_rate
total_men = 250 + 300
total_men
total_women = 250 + 400
total_women
expect_men_admitted = total_men * admission_rate
expect_men_admitted
expect_women_admitted = total_women * admission_rate
expect_women_admitted<jupyter_output><empty_output><jupyter_text>Regression example<jupyter_code>import pandas as pd
import seaborn as sns
import numpy as np
men = pd.DataFrame({"height": np.random.normal(1.8, 0.05, 100), "weight": np.random.normal(85, 1, 100)})
men['bmi'] = men['weight'] / men['height']**2
men
sns.lmplot(x='height', y='bmi', data=men)
women = pd.DataFrame({"height": np.random.normal(1.6, 0.05, 100), "weight": np.random.normal(60, 1, 100)})
women['bmi'] = women['weight'] / women['height']**2
women
sns.lmplot(x='height', y='bmi', data=women)
men['gender'] = 'male'
women['gender'] = 'female'
people = pd.concat([men, women])
people
sns.lmplot(x='height', y='bmi', data=people)<jupyter_output>C:\Users\mclou\Anaconda3\lib\site-packages\scipy\stats\stats.py:1713: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
  return np.add.reduce(sorted[indexer] * weights, axis=axis) / sumval
StarcoderdataJupyterStructuredCleanDedup