Bird
0
0

What is wrong with this code snippet that attempts to perform a paired t-test?

medium📝 Debug Q6 of 15
SciPy - Statistical Tests

What is wrong with this code snippet that attempts to perform a paired t-test?

from scipy.stats import ttest_rel
control = [10, 12, 14]
treatment = [11, 13]
result = ttest_rel(control, treatment)
print(result.pvalue)
AThe print statement should print result.statistic instead of result.pvalue.
BThe function ttest_rel is used incorrectly; it should be ttest_ind for paired data.
CThe two input arrays have different lengths, which is invalid for a paired t-test.
DThe arrays should be converted to numpy arrays before passing to ttest_rel.
Step-by-Step Solution
Solution:
  1. Step 1: Check input arrays length

    Paired t-test requires both samples to have the same length because it compares paired observations.
  2. Step 2: Identify the error

    Here, 'control' has 3 elements, 'treatment' has 2 elements, so ttest_rel will raise an error.
  3. Final Answer:

    The arrays have different lengths, invalid for paired t-test. -> Option C
  4. Quick Check:

    Paired tests need equal-length arrays. [OK]
Quick Trick: Paired t-test needs equal-length samples. [OK]
Common Mistakes:
MISTAKES
  • Using ttest_rel with arrays of different lengths
  • Confusing ttest_rel with ttest_ind for paired data
  • Ignoring the error raised due to unequal sample sizes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes