Formulating and simulating a hypothesis

Statistical Thinking in Python (Part 2)

Justin Bois

Lecturer at the California Institute of Technology

2008 US swing state election results

ch3-1.002.png

1 Data retrieved from Data.gov (https://www.data.gov/)
Statistical Thinking in Python (Part 2)

ch3-1.004.png

Statistical Thinking in Python (Part 2)

Hypothesis testing

  • Assessment of how reasonable the observed data are assuming a hypothesis is true
Statistical Thinking in Python (Part 2)

Null hypothesis

  • Another name for the hypothesis you are testing
Statistical Thinking in Python (Part 2)

ECDFs of swing state election results

ch3-1.009.png

1 Data retrieved from Data.gov (https://www.data.gov/)
Statistical Thinking in Python (Part 2)

Percent vote for Obama

ch3-1.011.png

1 Data retrieved from Data.gov (https://www.data.gov/)
Statistical Thinking in Python (Part 2)

Simulating the hypothesis

ch3-1.013.png

1 Data retrieved from Data.gov (https://www.data.gov/)
Statistical Thinking in Python (Part 2)

Simulating the hypothesis

ch3-1.015.png

1 Data retrieved from Data.gov (https://www.data.gov/)
Statistical Thinking in Python (Part 2)

Simulating the hypothesis

ch3-1.017.png

1 Data retrieved from Data.gov (https://www.data.gov/)
Statistical Thinking in Python (Part 2)

Simulating the hypothesis

ch3-1.019.png

Statistical Thinking in Python (Part 2)

Permutation

  • Random reordering of entries in an array
Statistical Thinking in Python (Part 2)

Generating a permutation sample

import numpy as np
dem_share_both = np.concatenate(
                       (dem_share_PA, dem_share_OH))

dem_share_perm = np.random.permutation(dem_share_both)
perm_sample_PA = dem_share_perm[:len(dem_share_PA)] perm_sample_OH = dem_share_perm[len(dem_share_PA):]
Statistical Thinking in Python (Part 2)

Let's practice!

Statistical Thinking in Python (Part 2)

Preparing Video For Download...