Compute a Confidence Interval
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 lessonGiven the response_times array, compute the 95% confidence interval for the mean using stats.t.interval(). Print the lower bound and upper bound, each rounded to 2 decimal places, on separate lines.
import numpy as np
from scipy import stats
np.random.seed(99)
response_times = np.random.normal(loc=250, scale=30, size=40) # milliseconds
mean = np.mean(response_times)
sem = stats.sem(response_times)
n = len(response_times)
# Compute 95% confidence interval
# Print lower and upper bounds (2 decimals each)
More SciPy Statistics exercises
All Python exercises · 50 practice problems · Data Science & Machine Learning quiz