CMSC 320 • PART 03
Hypothesis Testing:
Different Types of Statistical Tests
Instructor: Fardina F Alam
Course Overview
Topics We Will Cover
Primary Focus
Parametric Tests for Means
These tests are used to compare means. They assume that your data follows a normal distribution and that you have a sufficient sample size.
1 Z-Test
2 T-Test
3 One vs Two Sample Test
4 Paired Sample T-Test
5 ANOVA
Alternative
Non-Parametric Tests
Used when distribution assumptions are not met.
1 Chi-squared test
More …..
Follow-Up
Post-Hoc Analysis
Determines specific group differences after overall ANOVA testing.
Key Objective:
Identify which specific means differ from each other.
Hypothesis Testing Overview
Parametric vs. Non-Parametric Tests
A statistical hypothesis test is a method of statistical inference used to decide whether the data at hand sufficiently support a particular hypothesis.
ASSUMES DISTRIBUTION
Parametric Tests
Examples: t-test, ANOVA
DISTRIBUTION-FREE
Non-Parametric Tests
Examples: Mann–Whitney U, Wilcoxon, Kruskal–Wallis
Key Idea: Choose the test based on your data, research question, and assumptions.
In hypothesis testing, a test statistic reduces sample data to a single value (such as a Z, t, or F value). This statistic is then compared to a critical value or p-value to decide whether to reject the null hypothesis.
Parametric Tests (Comparing Means)
Overview & Key Assumptions
Assumes data follow a continuous, normally distributed scale with equal variances.
Core Parametric Tests (Comparing Means)
Decision Rule (Sample Size & Groups)
Use Z-Test for n > 30, t-Test for n < 30 or unknown variance, and ANOVA when evaluating 3 or more sample groups.
Statistical Hypothesis Tests Overview
Test | What are we comparing? | Key Condition | When to Use — Example |
Z-test | Sample mean vs. population mean | Population SD σ known; data approx. normal or sample large (typically n>30) | Is average package weight different from 500 g? |
One-sample t-test | Sample mean vs. reference mean | Numerical data; Population σ unknown | Is average sleep time different from 7 hours? |
Two-sample t-test | Means of 2 independent groups | Independent groups, σ unknown | Do men and women have different average heights? |
Paired t-test | Means of 2 related measurements | Same/matched subjects | Is blood pressure different before vs. after treatment? |
ANOVA | Means of 3+ groups | Multiple independent groups | Do 3 teaching methods produce different mean scores? |
Chi-square (χ²) | Categorical counts | Categorical variables | Is product preference related to age group? |
Mann–Whitney U | 2 independent groups | Non-parametric | Compare satisfaction ratings from two independent groups |
Wilcoxon signed-rank | 2 related measurements | Non-parametric | Compare ratings before vs. after an intervention |
Kruskal–Wallis | 3+ independent groups | Non-parametric | Compare satisfaction ratings across 3+ groups |
Means + assumptions reasonable → Z / t / ANOVA | Rank-based/non-parametric approach → Mann–Whitney / Wilcoxon / Kruskal–Wallis | Categorical counts → χ²
Z-Test vs. T-Test: When to Use
Z-Test
Use when population standard deviation (σ) is known.
Z = (x̄ - μ) / (σ / √n)
Think: σ known → Z-test
T-Test
Use when population standard deviation (σ) is unknown.
t = (x̄ - μ) / (s / √n)
Think: σ unknown → t-test
x̄ = sample mean | μ = population mean | σ = population std. deviation | s = sample std. deviation | n = sample size
KEY TAKEAWAY: Main distinction is σ known vs. unknown, not sample size alone.
Hypothesis Testing Context
Comparing Male vs. Female Heights
We have noticed most humans fall into one of two distinct categories—male or female.
We would like to know if our sample of males is taller than our sample of females.
Key Research Question
Can we just take the average of the two samples?
Types of T-Tests
Choose the t-test based on what you are comparing
One-Sample T-Test
Compare one sample mean with a known/reference value.
Example: Is average sleep time different from 7 hours?
Two-Sample T-Test (Independent)
Compare the means of two independent groups.
Example: Is average height different between Group A and Group B?
Paired T-Test
Compare two related measurements from the same/matched subjects.
Example: Blood pressure before vs. after treatment.
Often measured from the same subjects at different times or under different conditions.
KEY DECISION GUIDE
• One group vs. a value? → One-Sample T-Test | • Two independent groups? → Two-Sample T-Test
• Same subjects twice? → Paired T-Test
If the two groups have very different spreads, use Welch’s t-test.
Simply taking the average of two samples is not sufficient to determine if groups differ (doesn't account for variability). Conduct a statistical test to determine significant differences.
How to run a one-sample t-test:
import numpy as np
from scipy import stats
stats.ttest_1samp(your_data, popmean=0.5)
>>> TtestResult(statistic=2.456, pvalue=0.0176, df=49)
Why Comparing Means Alone Is Not Enough
Why Simple Comparison Is Not Enough
Two groups can have different sample means, but that alone does not tell us whether the difference is statistically significant.
We also need to consider:
The Statistical Solution
A Two-Sample T-Test helps determine whether the difference between the means of two independent groups is statistically significant.
Example: Is the average height different between Group A and Group B?
Key Takeaway: Difference in means + Variability + Sample size → Statistical evidence
T-Test Assumptions
Core statistical requirements for valid hypothesis testing
Continuous Outcome
Outcome is numerical / continuous.
Independence of Observations
Observations are appropriately independent (except paired t-test).
Normality Assumption
Data are approximately normal, especially important for small samples.
Non-Parametric Alternative
If normality is not reasonable → consider a non-parametric alternative.
Paired Sample T-Test: Example
Statistical experiment setup and hypothesis formulation
The Experiment Scenario
The aliens monitor a bunch of humans, test them for intelligence, and then run one half of them through a machine to make them smarter. Afterwards, they want to know if their machine worked.
Experimental Method: This study design is analyzed using a paired t-test.
Null Hypothesis (H₀)
The machine did nothing
Assumes no significant difference in intelligence before and after the intervention.
Alternative Hypothesis (H₁)
The machine came from a different distribution
Assumes the machine produced a real, statistically measurable effect on intelligence.
Question for Discussion
The aliens get a p-value of .05. What can they conclude?
Consider the standard significance threshold (α = 0.05) and whether this provides sufficient evidence to reject the null hypothesis.
ANOVA: Comparing Multiple Groups
Statistical scenario, hypothesis formulation, and group variance logic
The Scenario
The aliens want to know whether human growth differs across diets. They observe three groups: Vegan Diet, Meat Diet, & Vegetarian Diet.
Question: Do the groups have different average growth over the next few years?
ANOVA
When comparing the means of 3 or more groups, we use ANOVA (Analysis of Variance). Tests if at least one group mean differs.
H₀: All group means are equal.
Hₐ: At least one group mean is different.
Remember: ANOVA considers both within-group and between-group variability.
Key Idea & Rule
2 groups → T-Test | 3+ groups → ANOVA
Important: A significant ANOVA tells us that a difference exists, but not which groups differ.�→ That's where post-hoc tests come next.
Nonparametric Tests (Comparing Medians)
Overview & Key Assumptions
Used when data do not meet assumptions of parametric tests (e.g., normality, equal variances).
Rank-Based Tests (work on ranked data)
Frequency-Based Tests (categorical counts)
Nonparametric Tests: Alternatives to Parametric Tests
Kruskal–Wallis Test Alt to One-Way ANOVA
Mann–Whitney U Test Alt to Independent t-Test
Wilcoxon Signed-Rank Test Alt to Paired-Samples t-Test
Spearman’s Rank Correlation
Measures correlation between two variables based on ranks. Useful for ordinal/non-normal data.
Key Takeaway
Nonparametric tests are mostly based on ranked data instead of raw values, making them significantly more robust when the underlying assumptions of parametric tests are not met.
How Ranking Works
Instead of using actual numerical values (raw scores), nonparametric tests convert data into ranks (positions).
Example: Exam Scores
Raw: 45, 80, 60, 90, 75
45 → Rank 1
60 → Rank 2
75 → Rank 3
80 → Rank 4
90 → Rank 5
Why use ranks?
Tests look at rank distributions rather than exact values. Ranks are less sensitive to outliers and don't require normal distributions.
Chi-Square Test: Categorical Data
What does it test?
The Chi-Square (χ²) test checks whether there is an association between categorical variables.
Works with:
Key Takeaway:
Numerical means → t-test / ANOVA
Categorical counts → Chi-Square
Example:
Is bird species associated with location?
H₀ (Null Hypothesis):
Bird species and location are independent.
Hₐ (Alternative Hypothesis):
Bird species and location are associated.
Example: Are Bird Species Related to Location?
We observe bird species at Location A and Location B.
Question: Is the distribution of bird species the same across the two locations?
Bird Type | Location A | Location B |
Grackle | 7 | 13 |
Pigeon | 2 | 7 |
Sea pigeon | 15 | 1 |
One of those big fish-beak things | 13 | 0 |
Big long bird | 22 | 0 |
Bat | 3 | 4 |
Analysis Process
Observed counts → Chi-Square Test
→ Compare observed vs. expected counts
Hypotheses
H₀ (Null Hypothesis):
Bird species and location are independent.
Hₐ (Alternative Hypothesis):
Bird species and location are associated.
Selecting the Right Statistical Test
Key considerations to guide your statistical decision-making
01
Research Goal
What are you curious about?
Mean? Standard deviation? Frequency?
02
Data Type
Is your data categorical or continuous?
03
Sample Count
Do you have one or two samples?
04
Distribution
Is your data normally distributed?
If normal, use a parametric test. If very non-normal, use a non-parametric test.
05
Dependency
Is your data paired?
Is there a before and after?
Post Hoc Tests for ANOVA
Post Hoc Test / Analysis
Identifying specific group differences following a significant ANOVA
WHEN TO USE
ANOVA tells us that at least one group differs, but not which groups are different.
Post-hoc analysis identifies specific group differences after ANOVA is significant when more than two groups are compared.
PURPOSE
Core Objectives
COMMON POST-HOC TESTS
Key Idea: Post-hoc tests show which group means differ significantly from each other.
Post-Hoc Tests: Which Groups Are Different?
Identifying specific group differences following a significant ANOVA
WHY POST-HOC TESTS?
Why Do We Need Post-Hoc Tests?
A significant ANOVA tells us that at least one group mean is different, but it does not tell us which groups differ.
Example: Suppose we compare three diets:
Vegan | Meat | Vegetarian
ANOVA gives p = 0.01 → Significant
Question: Which groups are actually different?
→ Post-hoc tests make comparisons between groups to find out.
COMMON METHODS
Common Post-Hoc Methods
Tukey’s HSD
Compares all pairs of groups while controlling the overall Type I error rate.
Bonferroni Correction
Uses a stricter significance level (α) when making multiple comparisons.
Duncan’s Multiple Range Test
Compares group means but is less conservative than Tukey or Bonferroni.
Example: Post-Hoc Tests — Which Schools Differ?
Evaluating test score variation across multiple groups
SCENARIO
We conducted a study to compare the test scores of students from three different schools: School A, School B, and School C.
Initial Assessment: More than 2 groups (A, B, C) → Apply ANOVA
ANOVA Result: p-value < 0.05 (indicating significant overall differences among schools).
Next Step: Post-hoc testing is required to pinpoint which specific schools differ.
Apply Tukey’s HSD: Balanced Approach
HSD = Honestly Significant Difference
Tukey compares all pairs of group means and controls the overall chance of making one or more Type I errors across that family of comparisons.
Goal: Find which pairs differ — Ideal when comparing every group with every other group.
Interpretation: School A and School B, as well as School A and School C, have significantly different test scores (p < 0.05).
Key Result: There is no significant difference in test scores between School B and School C.
Bonferroni Correction: More Conservative Adjustment
Bonferroni changes the significance threshold based on the number of comparisons.
Next Step: Compare all three pairs while using a stricter significance level to control Type I error.
Adjusted α = 0.05 / 3 = 0.0167(3 comparisons) — Goal: Strong protection against false positives by using a stricter threshold.
Interpretation: Using the Bonferroni-adjusted threshold (α = 0.0167), none of the pairwise comparisons are statistically significant.
Key Idea: Bonferroni is more conservative because it uses a stricter threshold to reduce false positives.
Significant? (α = .0167)
No
No
Summary: Key Statistical Tests
Overview of core testing methods and their application criteria
Statistical tests let us reason about one or more samples and how they relate to each other and the population.
LARGE SAMPLE
z-test
A test we can use if your data is normally distributed and we have a large number of samples.
SMALL SAMPLE
t-test
A test we can use if your data is normally distributed and we have a small number of samples.
LONGITUDINAL
Paired tests
Used when we follow specific population members through time.
DIRECTIONALITY
One tailed vs two tailed tests
Two tailed: Look for any difference in population.
One tailed: Require us to pick a specific direction.
Summary: Main Steps of Hypothesis Testing
1
1. State the Null Hypothesis: Assumption what you're trying to test
2
2. State the Alternative Hypothesis: what you believe might be true
3
3. Pick a Level of Significance α: the probability of rejecting the null hypothesis when it's actually true. Common values for α are 0.05 or 0.01.
4
4. Choose a Test: Select the right tool to check your guesses based on your data.
5
5. Collect Data: Get the information/data you need through observation or experimentation.
6
6. Calculate a test statistic: Using the collected data, calculate the appropriate test statistic.
7
7. Calculate P-Value and compare with α: Based on the comparison, decide if you have enough evidence to believe your guess is right or if you need to keep looking.
8
8. Draw a Conclusion: Based on your decision in the previous step, draw a conclusion regarding the null hypothesis. If you reject it, you accept the alternative hypothesis. If you fail to reject it, you do not have enough evidence to support the alternative hypothesis.