Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Practicing Statistics Interview Questions in Python

Cursus bekijken

Oefeninstructies

  • Compute the standard error and the margin of error using the sem() function and z_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.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

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(____)
Code bewerken en uitvoeren