Editor

Test Survey Results with Chi-Square

Advanced · Write the code · from SciPy Statistics: Distributions, Hypothesis Tests, and Correlations

From the lesson: SciPy Statistics: Distributions, Hypothesis Tests, and Correlations

A pharmaceutical company develops a new headache medicine. They give it to 100 patients and a placebo to another 100. The treatment group reports slightly fewer headaches. But is that difference real, or just random chance? This is the question statistics answers.

Read the lesson

A survey asked 200 people to choose their favorite season. The results were: Spring=60, Summer=70, Fall=45, Winter=25. If there were no preference, each season would get 50 votes. Use scipy.stats.chisquare() to test whether the distribution is uniform. Print the chi-square statistic (rounded to 1 decimal) and whether preferences are 'Significant' or 'Not significant' at alpha=0.05.

import numpy as np
from scipy import stats
observed = np.array([60, 70, 45, 25])
# Run chi-square goodness of fit test
# Print chi-square statistic (1 decimal)
# Print significance

More SciPy Statistics exercises

All Python exercises · 50 practice problems · Data Science & Machine Learning quiz