0
0
Data Analysis Pythondata~20 mins

t-test with scipy.stats in Data Analysis Python - 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 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))
A1.87 0.045
B1.87 0.150
C1.41 0.222
D2.24 0.045
Attempts:
2 left
💡 Hint
Remember the t-statistic measures how far the sample mean is from the population mean in standard error units.
data_output
intermediate
2: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)
A2
B1
C3
D0
Attempts:
2 left
💡 Hint
Check the p-values for each pair and count how many are below 0.05.
🔧 Debug
advanced
2: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)
AValueError: operands could not be broadcast together with shapes (4,) (3,)
BTypeError: ttest_rel() missing 1 required positional argument
CNo error, outputs t-statistic and p-value
DIndexError: index out of range
Attempts:
2 left
💡 Hint
Check if the input arrays have the same length for paired tests.
🧠 Conceptual
advanced
2: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?
AThe alternative hypothesis is true with 97% confidence.
BThere is a 3% chance the null hypothesis is true.
CThe difference between groups is practically significant.
DThere is a 3% chance of observing the data if the null hypothesis is true.
Attempts:
2 left
💡 Hint
Remember what p-value measures in hypothesis testing.
🚀 Application
expert
2: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?
AIndependent two-sample t-test
BPaired t-test
CWelch's t-test
DOne-sample t-test
Attempts:
2 left
💡 Hint
Think about whether the samples are related or independent.