Confidence interval by hand
There are two common ways that interviewers will touch on confidence intervals; they will either ask you to explain it in simple terms, or elaborate on how they are calculated, possibly having you implement one. In this exercise, you'll practice the latter by producing a confidence interval by hand, using no packages other than those imported for you.
We have gone ahead and assigned the appropriate z-score for a 95% confidence interval and sample mean to the z_score
and sample_mean
variables to simplify things a bit.
Diese Übung ist Teil des Kurses
Practicing Statistics Interview Questions in Python
Anleitung zur Übung
- Compute the standard error and the margin of error using the
sem()
function andz_score
variable imported for you. - Compute and print the lower boundary of our confidence interval using the
sample_mean
variable imported for you. - Compute and print the upper boundary of our confidence interval using the
sample_mean
variable imported for you.
Interaktive Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
from scipy.stats import sem, t
data = [1, 2, 3, 4, 5]
confidence = 0.95
# Compute the standard error and margin of error
std_err = sem(____)
margin_error = std_err * ____
# Compute and print the lower threshold
lower = sample_mean - ____
print(____)
# Compute and print the upper threshold
upper = sample_mean + ____
print(____)