Chi-square test
In this exercise, you will be working with the Olympics dataset. Here, we're going to look at the sex ratio of the American Olympic squads. Is a bias present? That is to say, does the ratio of male to female athletes significantly depart from 50-50? To test this, you'll need to perform a Chi-square test on the Sex
data. Data on American athletes is provided as athletes
. pandas
, and plotnine
have been loaded into the workspace as pd
and p9
.
This exercise is part of the course
Performing Experiments in Python
Exercise instructions
- Using
value_counts()
, extract the number of individuals of eachSex
fromathletes
, saving the result assexratio
. - Perform a
chisquare()
test onsexratio
and print the result. - Compare the p-value to the given
alpha
and print the message.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Extract sex ratio
sexratio = athletes[____].____
# Perform Chi-square test
chi= stats.____(____)
print(____)
# Test significance
alpha= 0.05
if ____ < alpha:
print("Difference between sexes is statistically significant")
else:
print("No significant difference between sexes found")