Summary and Practical Guide to Hypothesis Testing › Complete Reporting Example

Michael BrenndoerferJanuary 10, 20262 min read
Machine Learning from ScratchAll chapters
Part 2 of 15Hypothesis Testing
Chapter 22Summary and Practical Guide to Hypothesis Testing › Complete Reporting Example
Reading section 8 of 12 · Complete Reporting Example · 2 minSection 8 of 12 · 2 min

Section 8 of 12 · 2 min read

Summary and Practical Guide to Hypothesis Testing › Complete Reporting ExampleSection view · Sections in this chapter8 / 12 ↓
Reading tools Definitions, links & notes

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Notes & comments

Here's an example of a complete analysis with proper reporting:

PythonIn [8]
CollapseExpand
import numpy as np
from scipy import stats

# Research question: Does a new teaching method improve test scores?
np.random.seed(42)
control = np.random.normal(75, 12, 30)  # Traditional method
treatment = np.random.normal(82, 11, 30)  # New method

# 1. Descriptive statistics
print("=" * 60)
print("DESCRIPTIVE STATISTICS")
print("=" * 60)
print(
    f"Control:   n = {len(control)}, M = {np.mean(control):.2f}, SD = {np.std(control, ddof=1):.2f}"
)
print(
    f"Treatment: n = {len(treatment)}, M = {np.mean(treatment):.2f}, SD = {np.std(treatment, ddof=1):.2f}"
)
print()

# 2. Check assumptions
print("=" * 60)
print("ASSUMPTION CHECKS")
print("=" * 60)

# Normality
_, p_norm_ctrl = stats.shapiro(control)
_, p_norm_treat = stats.shapiro(treatment)
print(
    f"Shapiro-Wilk (Control):   W = {stats.shapiro(control)[0]:.3f}, p = {p_norm_ctrl:.3f}"
)
print(
    f"Shapiro-Wilk (Treatment): W = {stats.shapiro(treatment)[0]:.3f}, p = {p_norm_treat:.3f}"
)
print("  → Normality assumption supported (p > 0.05 for both groups)")
print()

# Equal variances
_, p_levene = stats.levene(control, treatment)
print(
    f"Levene's test: F = {stats.levene(control, treatment)[0]:.3f}, p = {p_levene:.3f}"
)
print("  → Equal variances assumption supported (p > 0.05)")
print()

# 3. Conduct test
print("=" * 60)
print("HYPOTHESIS TEST")
print("=" * 60)
t_stat, p_value = stats.ttest_ind(treatment, control, equal_var=True)
df = len(control) + len(treatment) - 2
print(f"Two-sample t-test: t({df}) = {t_stat:.3f}, p = {p_value:.4f}")
print()

# 4. Effect size
mean_diff = np.mean(treatment) - np.mean(control)
pooled_std = np.sqrt(
    (
        (len(control) - 1) * np.var(control, ddof=1)
        + (len(treatment) - 1) * np.var(treatment, ddof=1)
    )
    / (len(control) + len(treatment) - 2)
)
cohens_d = mean_diff / pooled_std
print("=" * 60)
print("EFFECT SIZE")
print("=" * 60)
print(f"Mean difference: {mean_diff:.2f} points")
print(f"Cohen's d = {cohens_d:.3f} (large effect)")
print()

# 5. Confidence interval for difference
se_diff = pooled_std * np.sqrt(1 / len(control) + 1 / len(treatment))
t_crit = stats.t.ppf(0.975, df)
ci_lower = mean_diff - t_crit * se_diff
ci_upper = mean_diff + t_crit * se_diff
print("=" * 60)
print("CONFIDENCE INTERVAL")
print("=" * 60)
print(f"95% CI for difference: [{ci_lower:.2f}, {ci_upper:.2f}]")
print()

# 6. Complete report
print("=" * 60)
print("COMPLETE REPORT (APA STYLE)")
print("=" * 60)
print(
    f"Students in the new teaching method condition (M = {np.mean(treatment):.1f}, "
)
print(
    f"SD = {np.std(treatment, ddof=1):.1f}) scored significantly higher than those in the "
)
print(
    f"traditional method condition (M = {np.mean(control):.1f}, SD = {np.std(control, ddof=1):.1f}), "
)
print(
    f"t({df}) = {t_stat:.2f}, p {'< 0.001' if p_value < 0.001 else f'= {p_value:.3f}'}, "
)
print(f"95% CI [{ci_lower:.1f}, {ci_upper:.1f}], Cohen's d = {cohens_d:.2f}.")
ConsoleOut [8]
CollapseExpand
============================================================
DESCRIPTIVE STATISTICS
============================================================
Control:   n = 30, M = 72.74, SD = 10.80
Treatment: n = 30, M = 80.67, SD = 10.24

============================================================
ASSUMPTION CHECKS
============================================================
Shapiro-Wilk (Control):   W = 0.975, p = 0.687
Shapiro-Wilk (Treatment): W = 0.984, p = 0.913
  → Normality assumption supported (p > 0.05 for both groups)

Levene's test: F = 0.002, p = 0.963
  → Equal variances assumption supported (p > 0.05)

============================================================
HYPOTHESIS TEST
============================================================
Two-sample t-test: t(58) = 2.916, p = 0.0050

============================================================
EFFECT SIZE
============================================================
Mean difference: 7.92 points
Cohen's d = 0.753 (large effect)

============================================================
CONFIDENCE INTERVAL
============================================================
95% CI for difference: [2.49, 13.36]

============================================================
COMPLETE REPORT (APA STYLE)
============================================================
Students in the new teaching method condition (M = 80.7, 
SD = 10.2) scored significantly higher than those in the 
traditional method condition (M = 72.7, SD = 10.8), 
t(58) = 2.92, p = 0.005, 
95% CI [2.5, 13.4], Cohen's d = 0.75.

Comments

Add to the conversation

A question, a correction, or an example from your own work.

No comments yet. Be the first to share your thoughts!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy