Skip to content

Instantly share code, notes, and snippets.

@panicpotatoe
Created March 12, 2019 03:04
Show Gist options
  • Select an option

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

Select an option

Save panicpotatoe/d3baa69f59f2bfba040a2abcbd1fb756 to your computer and use it in GitHub Desktop.
# STEP 3: CALCULATE THE CHI SQUARE VALUE and CRITICAL VALUE
"""
Chi square formula:
chi square = total of [(observed - expected)^2]/expected
Note: We call .sum() twice: once to get the column sums
and a second time to add the column sums together,
returning the sum of the entire 2D table.
"""
chi_squared_stat = (((observed-expected)**2)/expected).sum().sum()
print(chi_squared_stat)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment