0
0
SciPydata~20 mins

Why hypothesis testing validates claims in SciPy - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Hypothesis Testing Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
What does the p-value represent in hypothesis testing?

In hypothesis testing, what does the p-value tell us about the claim we are testing?

AThe probability that the observed data is incorrect.
BThe probability that the alternative hypothesis is true given the data.
CThe probability that the null hypothesis is false.
DThe probability of observing the data, or something more extreme, assuming the null hypothesis is true.
Attempts:
2 left
💡 Hint

Think about what the p-value measures under the assumption that the null hypothesis holds.

Predict Output
intermediate
2:00remaining
Output of a t-test on sample data

Given the following Python code using scipy.stats, what is the output of the t-statistic and p-value?

SciPy
from scipy import stats

sample = [5, 7, 8, 6, 9, 7, 5]
# Test if the sample mean is different from 6
result = stats.ttest_1samp(sample, 6)
print(round(result.statistic, 2), round(result.pvalue, 3))
A1.26 0.250
B0.87 0.412
C2.45 0.045
D3.12 0.015
Attempts:
2 left
💡 Hint

Calculate the sample mean and standard deviation, then apply the t-test formula or run the code.

data_output
advanced
2:30remaining
Result of a two-sample t-test on two groups

Two groups have the following data:

Group A: [12, 15, 14, 10, 13]

Group B: [8, 9, 7, 6, 10]

Using a two-sample t-test, what is the t-statistic and p-value?

SciPy
from scipy import stats

group_a = [12, 15, 14, 10, 13]
group_b = [8, 9, 7, 6, 10]
result = stats.ttest_ind(group_a, group_b)
print(round(result.statistic, 2), round(result.pvalue, 3))
A4.31 0.002
B2.13 0.075
C3.58 0.010
D1.98 0.120
Attempts:
2 left
💡 Hint

Calculate the means and variances of both groups, then apply the two-sample t-test or run the code.

visualization
advanced
2:00remaining
Interpreting a p-value distribution plot

Below is a plot showing the distribution of p-values from many hypothesis tests under the null hypothesis. What does the uniform distribution of p-values indicate?

SciPy
import matplotlib.pyplot as plt
import numpy as np

np.random.seed(0)
p_values = np.random.uniform(0, 1, 1000)
plt.hist(p_values, bins=20, edgecolor='black')
plt.title('Distribution of p-values under Null Hypothesis')
plt.xlabel('p-value')
plt.ylabel('Frequency')
plt.show()
AMost p-values cluster near zero indicating strong evidence against the null hypothesis.
BP-values are equally likely across the range 0 to 1 when the null hypothesis is true.
CP-values cluster near one indicating the null hypothesis is always true.
DP-values follow a normal distribution centered at 0.5.
Attempts:
2 left
💡 Hint

Think about what the p-value distribution looks like if the null hypothesis is true for all tests.

🔧 Debug
expert
1:30remaining
Identify the error in hypothesis testing code

What error will this code raise when running a one-sample t-test?

from scipy import stats
sample = [2, 4, 6, 8]
result = stats.ttest_1samp(sample)
print(result)
ANo error, prints t-statistic and p-value
BValueError: Sample size must be greater than 1
CTypeError: ttest_1samp() missing 1 required positional argument: 'popmean'
DNameError: name 'stats' is not defined
Attempts:
2 left
💡 Hint

Check the required arguments for ttest_1samp function.