0
0
SciPydata~20 mins

t-test (ttest_ind, ttest_rel) in SciPy - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
T-Test Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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)))
A(0.45, 0.655)
B(4.03, 0.000)
C(-4.03, 0.000)
D(-0.45, 0.655)
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.
data_output
intermediate
2: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)))
AStatistic: -1.414, p-value: 0.197
BStatistic: 1.414, p-value: 0.197
CStatistic: -2.828, p-value: 0.025
DStatistic: 2.828, p-value: 0.025
Attempts:
2 left
💡 Hint
Paired t-test compares means of differences. The sign depends on which sample is larger on average.
🔧 Debug
advanced
2: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)
ATypeError: unsupported operand type(s) for -: 'int' and 'str'
BValueError: operands could not be broadcast together
CIndexError: index out of bounds
DNo error, outputs t-statistic and p-value
Attempts:
2 left
💡 Hint
Check if ttest_ind requires equal length arrays.
🧠 Conceptual
advanced
2:00remaining
Choosing between ttest_ind and ttest_rel
Which situation correctly describes when to use ttest_rel instead of ttest_ind?
AComparing test scores of students before and after a training program
BComparing heights of men and women in a population
CComparing sales of two different stores in different cities
DComparing average temperatures of two different months
Attempts:
2 left
💡 Hint
ttest_rel is for paired or related samples.
🚀 Application
expert
3: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?
AThere is no significant change in blood pressure because p-value is greater than 0.01.
BThe treatment caused a significant change in blood pressure (p < 0.05), so we reject the null hypothesis.
CThe treatment has no effect because the t-statistic is positive.
DThe sample size is too small to conclude anything from the test.
Attempts:
2 left
💡 Hint
Check the p-value against common significance levels.