Skip to content

Instantly share code, notes, and snippets.

@panicpotatoe
Created March 12, 2019 02:58
Show Gist options
  • Select an option

  • Save panicpotatoe/5adb4139d59c73463bad4ab11974a506 to your computer and use it in GitHub Desktop.

Select an option

Save panicpotatoe/5adb4139d59c73463bad4ab11974a506 to your computer and use it in GitHub Desktop.
"""
Calculate the "expected" table:
"Expected" table can be calculated using below formula:
total_rows x total_columns / total_observations
And these factors can be get by:
- total_rows = voter_tab["row_totals"]
- total_columns = voter_tab["col_totals"]
- total_observations = 1000
Please note that the "loc" function in below code is used to switch the
index base on column name to row name
"""
expected = np.outer(voter_tab["row_totals"][0:5],
voter_tab.loc["col_totals"][0:3]) / 1000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment