Bird
0
0

Find the mistake in this code:

medium📝 Debug Q7 of 15
SciPy - Statistical Functions (scipy.stats) Basics
Find the mistake in this code:
import numpy as np
from scipy import stats

data = np.array([3, 5, 7, 9])
ci = stats.t.interval(0.95, len(data), loc=np.mean(data), scale=stats.sem(data))
print(ci)
Aloc parameter should be median, not mean
BDegrees of freedom should be len(data)-1, not len(data)
Cscale parameter should be standard deviation, not SEM
Dt.interval does not accept confidence level as first argument
Step-by-Step Solution
Solution:
  1. Step 1: Check degrees of freedom parameter

    Degrees of freedom for t-distribution is sample size minus one, so it should be len(data)-1.
  2. Step 2: Verify other parameters

    loc as mean and scale as SEM are correct; confidence level as first argument is correct.
  3. Final Answer:

    Degrees of freedom should be len(data)-1, not len(data) -> Option B
  4. Quick Check:

    Degrees of freedom = sample size minus one [OK]
Quick Trick: Use df = n - 1 for t-distribution degrees of freedom [OK]
Common Mistakes:
MISTAKES
  • Using sample size instead of df
  • Confusing mean with median
  • Misusing scale parameter

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes