Fisher's exact test
Now, you'll work with the Olympics dataset to look at the relative success of the American swimming and athletics teams. Whether each athlete received a medal is coded as True
or False
in the MedalTF
column of athletes
. Do a larger proportion of swimming or athletics participants come home with medals? A Fisher exact test is a useful way to compare proportions of samples falling into discrete categories. To test this, you'll need to perform a Fisher exact test on MedalTF
in relation to Sport
. pandas
and plotnine
have already been imported as pd
and p9
.
This is a part of the course
“Performing Experiments in Python”
Exercise instructions
- Using the
crosstab()
function, produce a cross-tabulation ofMedalTF
againstSport
, save the result astable
andprint()
it. - Perform a
fisher_exact()
test ontable
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.
# Create a table of cross-tabulations
table = pd.crosstab(____)
print(____)
# Perform the Fisher exact test
fisher = ____(____, alternative='two-sided')
____(____)
# Is the result significant?
alpha = 0.05
if ____ < ____
print("Proportions of medal winners differ significantly")
else:
print("No significant difference in proportions of medal winners found")