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 a one-sample t-test
What is the output of this code snippet performing a one-sample t-test?
Data Analysis Python
from scipy import stats import numpy as np data = np.array([5, 7, 8, 6, 9]) t_stat, p_value = stats.ttest_1samp(data, popmean=6) print(round(t_stat, 2), round(p_value, 3))
Attempts:
2 left
💡 Hint
Remember the t-statistic measures how far the sample mean is from the population mean in standard error units.
✗ Incorrect
The t-statistic is about 1.41 and the p-value is approximately 0.222, indicating the sample mean is not significantly different from 6 at 5% level.
❓ data_output
intermediate2:00remaining
Number of significant results in two-sample t-tests
Given two groups of data, how many of the following pairs show a significant difference at alpha=0.05 using independent two-sample t-tests?
Data Analysis Python
from scipy import stats import numpy as np pairs = [ (np.array([10, 12, 11, 13]), np.array([14, 15, 13, 16])), (np.array([20, 22, 21, 19]), np.array([18, 17, 20, 16])), (np.array([5, 7, 6, 8]), np.array([5, 6, 5, 7])) ] significant_count = 0 for g1, g2 in pairs: t_stat, p_val = stats.ttest_ind(g1, g2) if p_val < 0.05: significant_count += 1 print(significant_count)
Attempts:
2 left
💡 Hint
Check the p-values for each pair and count how many are below 0.05.
✗ Incorrect
The first two pairs have p-values below 0.05, indicating significant differences. The last pair does not.
🔧 Debug
advanced2:00remaining
Identify the error in paired t-test code
What error does this code raise when running a paired t-test?
Data Analysis Python
from scipy import stats import numpy as np before = np.array([100, 102, 98, 101]) after = np.array([102, 105, 100]) t_stat, p_val = stats.ttest_rel(before, after) print(t_stat, p_val)
Attempts:
2 left
💡 Hint
Check if the input arrays have the same length for paired tests.
✗ Incorrect
Paired t-test requires both samples to have the same number of observations. Here, 'before' has 4 and 'after' has 3, causing a broadcasting error.
🧠 Conceptual
advanced2:00remaining
Interpretation of p-value in t-test
If a two-sample t-test returns a p-value of 0.03, what does this mean?
Attempts:
2 left
💡 Hint
Remember what p-value measures in hypothesis testing.
✗ Incorrect
The p-value is the probability of observing data as extreme as this, assuming the null hypothesis is true. It is not the probability that the null hypothesis itself is true.
🚀 Application
expert2:00remaining
Choosing the correct t-test for data
You have two sets of exam scores: one from students before a training program and one from the same students after the program. Which t-test should you use to check if the training improved scores?
Attempts:
2 left
💡 Hint
Think about whether the samples are related or independent.
✗ Incorrect
Since the scores are from the same students before and after training, the samples are paired. A paired t-test accounts for this dependency.