Challenge - 5 Problems
T-Test Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of independent t-test on two samples
What is the output of the following code snippet that performs an independent t-test between two groups?
SciPy
from scipy.stats import ttest_ind import numpy as np np.random.seed(0) group1 = np.random.normal(10, 2, 30) group2 = np.random.normal(12, 2, 30) result = ttest_ind(group1, group2) print((round(result.statistic, 2), round(result.pvalue, 3)))
Attempts:
2 left
💡 Hint
Remember that ttest_ind returns a statistic and p-value. The sign of the statistic depends on which group mean is larger.
✗ Incorrect
The independent t-test compares means of two independent samples. Since group2 has a higher mean, the t-statistic is negative. The p-value is very small, indicating a significant difference.
❓ data_output
intermediate2:00remaining
Number of significant paired differences
Given the paired samples below, how many pairs show a significant difference at alpha=0.05 using a paired t-test?
SciPy
from scipy.stats import ttest_rel import numpy as np np.random.seed(1) before = np.array([20, 22, 19, 24, 30, 28, 25, 27]) after = np.array([21, 23, 18, 25, 29, 30, 26, 28]) result = ttest_rel(before, after) print((round(result.statistic, 3), round(result.pvalue, 3)))
Attempts:
2 left
💡 Hint
Paired t-test compares means of differences. The sign depends on which sample is larger on average.
✗ Incorrect
The paired t-test statistic is negative because the 'before' values are slightly greater than 'after' values on average. The p-value is above 0.05, so differences are not significant.
🔧 Debug
advanced2:00remaining
Identify the error in t-test code
What error will this code raise when run?
SciPy
from scipy.stats import ttest_ind import numpy as np a = np.array([1, 2, 3]) b = np.array([4, 5]) result = ttest_ind(a, b) print(result)
Attempts:
2 left
💡 Hint
Check if ttest_ind requires equal length arrays.
✗ Incorrect
ttest_ind works with arrays of different lengths because it compares independent samples. No error occurs.
🧠 Conceptual
advanced2:00remaining
Choosing between ttest_ind and ttest_rel
Which situation correctly describes when to use ttest_rel instead of ttest_ind?
Attempts:
2 left
💡 Hint
ttest_rel is for paired or related samples.
✗ Incorrect
ttest_rel is used when samples are related or paired, like measurements before and after treatment on the same subjects.
🚀 Application
expert3:00remaining
Interpreting t-test results for clinical trial data
A clinical trial measures blood pressure before and after treatment for 15 patients. The paired t-test returns statistic=3.25 and p-value=0.006. What is the correct interpretation?
Attempts:
2 left
💡 Hint
Check the p-value against common significance levels.
✗ Incorrect
A p-value of 0.006 is less than 0.05, indicating a statistically significant difference. The positive t-statistic shows the direction of change.