hypothesis testing for non parametric tests. complete notes with examples. easy

Searching the Web

non parametric hypothesis testing complete notes Mann-Whitney Wilcoxon Kruskal-Wallis

Here are your complete, easy notes on Hypothesis Testing for Non-Parametric Tests:

📊 Non-Parametric Hypothesis Testing - Complete Notes


1. What Are Non-Parametric Tests?

Non-parametric tests are statistical tests that do NOT assume a specific distribution (like normality) for the data. They work on ranks instead of actual values.

When to Use Non-Parametric Tests?

Use When...Example
Data is NOT normally distributedSkewed income data
Small sample size (n < 30)Pilot studies
Data is ordinal (ranked categories)Likert scale (1-5)
Outliers are presentExtreme values in dataset
Comparing medians, not meansNon-symmetric distributions

Parametric vs Non-Parametric - Quick Comparison

Parametric TestNon-Parametric EquivalentUse Case
One-sample t-testWilcoxon Signed-Rank1 group vs. known value
Paired t-testWilcoxon Signed-Rank2 matched/paired groups
Independent t-testMann-Whitney U Test2 independent groups
One-way ANOVAKruskal-Wallis Test3+ independent groups
Repeated Measures ANOVAFriedman Test3+ matched/repeated groups
Pearson CorrelationSpearman's Rank CorrelationAssociation between 2 variables
Chi-square (expected)Chi-square (non-param version)Categorical data

2. Sign Test

The simplest non-parametric test. Tests whether the median of a population equals a specific value.

How It Works

  • Replace each value with + (above median) or - (below median)
  • Count number of positives and negatives
  • Use binomial distribution to test

Hypotheses

  • H₀: Median = M₀ (no difference)
  • H₁: Median ≠ M₀ (two-tailed) OR Median > M₀ / Median < M₀ (one-tailed)

Example

A company claims median salary = ₹50,000. Sample of 10 employees: 45, 55, 62, 48, 70, 53, 41, 60, 49, 58
Step 1: Compare each to M₀ = 50,000
ValueSign
45,000-
55,000+
62,000+
48,000-
70,000+
53,000+
41,000-
60,000+
49,000-
58,000+
Step 2: Count: Positives (S⁺) = 6, Negatives (S⁻) = 4, n = 10
Step 3: Test statistic = min(6, 4) = 4
Step 4: At α = 0.05, n = 10 → Critical value = 1 (from Sign Test table)
Step 5: Since 4 > 1, Fail to Reject H₀. No evidence median ≠ 50,000.

3. Wilcoxon Signed-Rank Test

More powerful than the Sign Test. Used for one sample or paired samples. It considers both the direction AND magnitude of differences.

When to Use

  • Testing one sample against a known median
  • Comparing two related/paired groups (before-after data)

Hypotheses (Paired)

  • H₀: Median difference = 0
  • H₁: Median difference ≠ 0

Steps

  1. Calculate the difference (d = X₁ - X₂) for each pair
  2. Drop zero differences
  3. Rank the absolute values of differences (smallest = rank 1)
  4. Assign the sign (+/-) back to each rank
  5. Calculate W⁺ (sum of positive ranks) and W⁻ (sum of negative ranks)
  6. Test statistic W = min(W⁺, W⁻)
  7. Compare W to critical value from Wilcoxon table

Example

Before and after blood pressure readings for 8 patients:
| Patient | Before | After | d = B-A | |d| | Rank | Signed Rank | |---|---|---|---|---|---|---| | 1 | 120 | 115 | +5 | 5 | 4 | +4 | | 2 | 135 | 130 | +5 | 5 | 4 | +4 | | 3 | 125 | 128 | -3 | 3 | 2 | -2 | | 4 | 140 | 132 | +8 | 8 | 6 | +6 | | 5 | 118 | 125 | -7 | 7 | 5 | -5 | | 6 | 130 | 120 | +10 | 10 | 7 | +7 | | 7 | 122 | 120 | +2 | 2 | 1 | +1 | | 8 | 145 | 133 | +12 | 12 | 8 | +8 |
Note: Ties (ranks 4 and 4 for patients 1 and 2) are averaged.
W⁺ = 4 + 4 + 6 + 7 + 1 + 8 = 30 W⁻ = 2 + 5 = 7
W = min(30, 7) = 7
At α = 0.05, n = 8 → Critical value = 4
Since 7 > 4, Fail to Reject H₀. Blood pressure did not significantly change.

4. Mann-Whitney U Test

Non-parametric equivalent of the independent samples t-test. Compares two independent groups.

Hypotheses

  • H₀: The two populations have identical distributions (same median)
  • H₁: The distributions differ (medians differ)

Steps

  1. Combine all values from both groups and rank them (1 = smallest)
  2. Sum the ranks for each group: R₁ and R₂
  3. Calculate U statistics:
    • U₁ = n₁·n₂ + n₁(n₁+1)/2 − R₁
    • U₂ = n₁·n₂ + n₂(n₂+1)/2 − R₂
    • (Or simply: U₂ = n₁·n₂ − U₁)
  4. Test statistic: U = min(U₁, U₂)
  5. Compare to critical value (or compute Z for large samples)

Example

Two teaching methods tested on students. Method A scores: 78, 82, 65, 91, 73. Method B scores: 88, 76, 95, 84, 69
Step 1: Combine and rank all 10 values:
ValueGroupRank
65A1
69B2
73A3
76B4
78A5
82A6
84B7
88B8
91A9
95B10
Step 2: Sum ranks:
  • R₁ (Group A) = 1 + 3 + 5 + 6 + 9 = 24
  • R₂ (Group B) = 2 + 4 + 7 + 8 + 10 = 31
Step 3: Calculate U:
  • U₁ = (5×5) + 5×6/2 − 24 = 25 + 15 − 24 = 16
  • U₂ = (5×5) + 5×6/2 − 31 = 25 + 15 − 31 = 9
Step 4: U = min(16, 9) = 9
Step 5: At α = 0.05, n₁ = 5, n₂ = 5 → Critical value = 2
Since 9 > 2, Fail to Reject H₀. No significant difference between the two methods.
For large samples (n > 20): Use Z = (U − n₁n₂/2) / √(n₁n₂(n₁+n₂+1)/12)

5. Kruskal-Wallis Test

Non-parametric alternative to one-way ANOVA. Compares 3 or more independent groups.

Hypotheses

  • H₀: All k groups have the same population distribution (medians equal)
  • H₁: At least one group has a different median

Steps

  1. Combine all observations and assign ranks (1 = smallest)
  2. Sum ranks for each group: R₁, R₂, ..., Rₖ
  3. Calculate H statistic:
$$H = \frac{12}{N(N+1)} \sum_{i=1}^{k} \frac{R_i^2}{n_i} - 3(N+1)$$
  1. Compare H to Chi-square critical value with df = k − 1

Example

Three diet plans tested on weight loss (kg):
  • Diet A: 3, 5, 4, 6
  • Diet B: 7, 9, 6, 8
  • Diet C: 2, 4, 1, 3
Step 1: Combine and rank all 12 values:
ValueGroupRank
1C1
2C2
3A3.5
3C3.5
4A5.5
4C5.5
5A7
6A8.5
6B8.5
7B10
8B11
9B12
(Tied values get average ranks)
Step 2: Sum of ranks per group:
  • R_A = 3.5 + 5.5 + 7 + 8.5 = 24.5
  • R_B = 8.5 + 10 + 11 + 12 = 41.5
  • R_C = 1 + 2 + 3.5 + 5.5 = 12
Step 3: N = 12, n_A = n_B = n_C = 4
H = [12/(12×13)] × [(24.5²/4) + (41.5²/4) + (12²/4)] − 3×13
H = [12/156] × [150.0625 + 430.5625 + 36] − 39
H = 0.0769 × 616.625 − 39
H = 47.37 − 39 = 8.37
Step 4: df = k − 1 = 2, χ² critical at α = 0.05 = 5.991
Since H = 8.37 > 5.991, Reject H₀. At least one diet produces significantly different weight loss.
Post-hoc: After rejection, use Dunn's test (pairwise comparisons) to find which groups differ.

6. Friedman Test

Non-parametric equivalent of Repeated Measures ANOVA. Used when the same subjects are measured under 3+ conditions.

Hypotheses

  • H₀: All treatment conditions have the same distribution
  • H₁: At least one condition differs

Steps

  1. Arrange data with rows = subjects, columns = treatments
  2. Rank values within each row (1 = smallest in that row)
  3. Sum ranks for each treatment column: R_j
  4. Calculate Friedman statistic:
$$\chi^2_r = \frac{12}{nk(k+1)} \sum_{j=1}^{k} R_j^2 - 3n(k+1)$$
  1. Compare to χ² critical value with df = k − 1

Example

4 students rated 3 teaching methods (scores out of 10):
StudentMethod 1Method 2Method 3
1795
2864
3576
4987
Step 1: Rank within each row:
StudentM1 RankM2 RankM3 Rank
1231
2321
3132
4321
Sum (Rj)9105
Step 2: n = 4, k = 3
χ²r = [12/(4×3×4)] × (9² + 10² + 5²) − 3×4×4
χ²r = [12/48] × (81 + 100 + 25) − 48
χ²r = 0.25 × 206 − 48
χ²r = 51.5 − 48 = 3.5
Step 3: df = k − 1 = 2, χ² critical at α = 0.05 = 5.991
Since 3.5 < 5.991, Fail to Reject H₀. No significant difference between teaching methods.

7. Spearman's Rank Correlation

Non-parametric version of Pearson's correlation. Measures the strength of a monotonic relationship between two ranked variables.

Formula

$$r_s = 1 - \frac{6 \sum d_i^2}{n(n^2-1)}$$
where d = difference between ranks of paired observations.

Hypotheses

  • H₀: No correlation (ρ = 0)
  • H₁: Correlation exists (ρ ≠ 0)

Example

Rank students by Math (X) and English (Y) scores:
StudentMathEnglishRank XRank Yd = Rx - Ry
A857812-11
B78823124
C90742 (wait: 90 is highest)4......
Let me redo with proper ranks (1 = highest):
StudentMathEnglishRank XRank Yd
A908512-11
B85882111
C757034-11
D70724311
E60655500
Σd² = 4
rₛ = 1 − [6×4] / [5×(25−1)] rₛ = 1 − 24/120 = 1 − 0.2 = 0.8
Interpretation: rₛ = 0.8 → Strong positive correlation between Math and English performance.
Critical value test: For n = 5, α = 0.05 → Critical value ≈ 0.9 → Since 0.8 < 0.9, Fail to Reject H₀ (but practically, the correlation is strong).

8. Chi-Square Test (χ²) for Independence

Tests whether two categorical variables are independent or associated.

Hypotheses

  • H₀: The two variables are independent
  • H₁: The two variables are associated

Formula

$$\chi^2 = \sum \frac{(O - E)^2}{E}$$
  • O = Observed frequency
  • E = Expected frequency = (Row Total × Column Total) / Grand Total

Example

Is there a relationship between gender and preference for a product?
Prefer APrefer BTotal
Male302050
Female153550
Total4555100
Expected frequencies:
  • E(Male, A) = 50×45/100 = 22.5
  • E(Male, B) = 50×55/100 = 27.5
  • E(Female, A) = 50×45/100 = 22.5
  • E(Female, B) = 50×55/100 = 27.5
χ² calculation:
χ² = (30-22.5)²/22.5 + (20-27.5)²/27.5 + (15-22.5)²/22.5 + (35-27.5)²/27.5
χ² = 56.25/22.5 + 56.25/27.5 + 56.25/22.5 + 56.25/27.5
χ² = 2.5 + 2.045 + 2.5 + 2.045 = 9.09
df = (rows−1)(cols−1) = 1×1 = 1
Critical value at α = 0.05, df = 1 = 3.841
Since 9.09 > 3.841, Reject H₀. Gender and product preference are NOT independent (they are associated).

9. Summary - Decision Rules

W (Wilcoxon) or U (Mann-Whitney) or H (Kruskal-Wallis) or χ²Decision
Test statistic > Critical value (for H, χ²)Reject H₀
Test statistic < Critical value (for W, U)Reject H₀
p-value < αReject H₀
p-value > αFail to Reject H₀

10. Advantages and Disadvantages

Advantages ✅

  • No normality assumption needed
  • Work with small samples
  • Handle ordinal data and outliers well
  • Simpler to compute by hand

Disadvantages ❌

  • Less powerful than parametric tests when data IS normal
  • Cannot estimate parameters like mean differences directly
  • Fewer options for complex designs (interactions, covariates)

11. Quick Reference - Which Test to Use?

How many groups?
│
├─ 1 group
│    └─ vs. known value → Sign Test / Wilcoxon Signed-Rank
│
├─ 2 groups
│    ├─ Independent → Mann-Whitney U Test
│    └─ Paired / Matched → Wilcoxon Signed-Rank Test
│
└─ 3+ groups
     ├─ Independent → Kruskal-Wallis Test
     │    └─ Post-hoc → Dunn's Test
     └─ Repeated measures (same subjects) → Friedman Test

Categorical data (frequency tables) → Chi-Square Test
Association between two variables → Spearman's Rank Correlation

These notes cover all major non-parametric tests with step-by-step worked examples. The key to mastering these is practicing the ranking step - once you get the ranks right, the rest follows from plugging into formulas.
This is a shared conversation. Sign in to Orris to start your own chat.