Community medicine chapters

Statistical tests: z, t, ANOVA, chi-square, correlation and regression

How to choose the right statistical test from the type of data and number of groups, what the z-test, t-tests, ANOVA and chi-square test do, non-parametric alternatives, and how correlation and simple linear regression differ.

UHS PGET syllabus: Biostatistics (3 MCQs), Z-test; Student's t-test; ANOVA; chi-square test; correlation and regression (simple linear)Updated October 2026
In 30 seconds
  • Compare means: z-test (large samples, over 30), t-test (small samples; unpaired for two separate groups, paired for before-and-after), ANOVA for three or more groups.
  • Compare proportions (categorical data): chi-square test; use Fisher's exact when expected counts are small.
  • Correlation (r) measures the strength and direction of a linear relation (−1 to +1); regression predicts one variable from another (y = a + bx).
On this page

Overview

Choosing the right test depends on three questions:

  1. What type of data? Quantitative (means) or qualitative (proportions)?
  2. How many groups? Two, or three or more?
  3. Are the groups independent or paired? Different people, or the same people measured twice?

Then decide whether the data are normally distributed (parametric tests) or not (non-parametric tests).

Choosing a test

DataQuestionTest
Quantitative, large samplesCompare two meansz-test
Quantitative, small samples, two independent groupsCompare two meansUnpaired (independent) t-test
Quantitative, same subjects twiceCompare before and afterPaired t-test
Quantitative, three or more groupsCompare several meansANOVA
Qualitative (proportions)Compare proportions or test associationChi-square test
Qualitative, small expected numbersSameFisher's exact test
Two quantitative variablesStrength of linear relationshipCorrelation (Pearson's r)
Two quantitative variablesPredict one from the otherLinear regression
High-yield

Means → z or t test (or ANOVA). Proportions → chi-square.

The z-test

Used to compare a mean (or proportion) with a population value, or two means, when samples are large (usually n > 30) and the SD is known or well estimated.

z = difference ÷ standard error. If |z| > 1.96, p < 0.05.

Student's t-test

Used for small samples (n < 30), when the population SD is unknown, and the data are roughly normal.

  • One-sample t-test: compares a sample mean with a known value.
  • Unpaired (independent samples) t-test: compares the means of two separate groups (for example haemoglobin in boys vs girls).
  • Paired t-test: compares two measurements on the same subjects (before and after treatment), or matched pairs.

The t-distribution is like the normal curve but with fatter tails; it approaches the normal curve as sample size increases. Degrees of freedom for one sample = n − 1.

Exam trap

Before-and-after data on the same people need the paired t-test. Using the unpaired test wastes the pairing and loses power.

ANOVA (analysis of variance)

Compares the means of three or more groups at once (for example mean BP in three age groups). It produces an F statistic (ratio of variance between groups to variance within groups).

Using repeated t-tests instead would increase the chance of a type I error. If ANOVA is significant, post-hoc tests show which groups differ.

The chi-square (χ²) test

Used for qualitative (categorical) data, comparing proportions or testing the association between two categorical variables (for example smoking and lung cancer in cases and controls).

  • Data are arranged in a contingency table (for example 2 × 2).
  • It compares the observed counts with the counts expected if there were no association.
  • χ² = Σ (Observed − Expected)² ÷ Expected.
  • Degrees of freedom = (rows − 1) × (columns − 1); a 2 × 2 table has 1 degree of freedom.
Worked example: chi-square (2 × 2 table)

Smokers: 40 of 100 cases, 20 of 100 controls (total smokers 60 of 200)
Expected smokers in each group = (60 × 100) ÷ 200 = 30
Expected non-smokers in each group = (140 × 100) ÷ 200 = 70
χ² = Σ (O − E)² ÷ E
= (40−30)²/30 + (20−30)²/30 + (60−70)²/70 + (80−70)²/70
= 3.33 + 3.33 + 1.43 + 1.43 = 9.52
df = (2 − 1) × (2 − 1) = 1; critical value at p = 0.05 is 3.84
9.52 > 3.84 → significant (p ≈ 0.002): smoking is associated with the disease

Use Fisher's exact test when any expected cell count is less than 5. Use McNemar's test for paired categorical data (before and after in the same people).

High-yield

The chi-square test is used for proportions, not means. Degrees of freedom for a 2 × 2 table = 1.

Non-parametric tests

Used when data are skewed, ordinal, or the sample is small and not normal. They compare medians or ranks.

Parametric testNon-parametric equivalent
Unpaired t-testMann-Whitney U test
Paired t-testWilcoxon signed-rank test
One-way ANOVAKruskal-Wallis test
Pearson correlationSpearman rank correlation

Correlation

Correlation measures the strength and direction of the linear relationship between two quantitative variables (for example height and weight). Always draw a scatter diagram first.

The correlation coefficient (r) ranges from −1 to +1:

rMeaning
+1Perfect positive (both rise together)
0No linear relationship
−1Perfect negative (one rises as the other falls)

Roughly: |r| above 0.7 strong, 0.3–0.7 moderate, below 0.3 weak.

  • Pearson's r: both variables normal and the relation linear.
  • Spearman's rank correlation: ordinal or skewed data.
  • r² (coefficient of determination): the proportion of variation in one variable explained by the other. If r = 0.8, r² = 0.64, so 64% is explained.
High-yield

Correlation does not prove causation. A third factor (confounder) may explain both.

Exam trap

r = 0 means no linear relation; there may still be a curved relationship.

Simple linear regression

Regression describes how one variable (dependent, y) changes with another (independent, x), and is used for prediction.

y = a + bx

  • a: the intercept (value of y when x = 0).
  • b: the regression coefficient (slope): the change in y for each unit increase in x.

Example: predicting weight from height, or the dose-response of a drug.

Worked example: r² and regression

If r = 0.8 → r² = 0.8 × 0.8 = 0.64: 64% of the variation in y is explained by x
Regression: y = a + bx, e.g. weight (kg) = 8 + 2 × age (years) in young children
Age 3 → weight = 8 + (2 × 3) = 14 kg; the slope b = 2 kg per yea

CorrelationRegression
Measures strength of associationPredicts y from x
Both variables treated equallyOne dependent, one independent
Unitless (−1 to +1)Slope in the units of the variables
Exam focus

Most questions give a study scenario and ask which test to use. Identify the data type (means vs proportions), number of groups, and paired vs independent. Also asked: degrees of freedom for chi-square, the range and meaning of r, r², correlation vs causation, and the regression equation.

Quick revision

  • Two means, large samples: z-test. Small samples: t-test (unpaired or paired).
  • Three or more means: ANOVA.
  • Proportions: chi-square (Fisher's exact if expected count < 5).
  • Non-parametric: Mann-Whitney, Wilcoxon, Kruskal-Wallis, Spearman.
  • r from −1 to +1; r² = proportion explained; correlation ≠ causation.
  • Regression: y = a + bx; b is the slope.

Written by The House Job from Excel Community Medicine and Park's Textbook of Preventive and Social Medicine (named in the UHS PGET syllabus).

FAQ

Which test compares the means of two small independent groups?

The unpaired (independent samples) Student's t-test.

When is the chi-square test used?

To compare proportions or test an association between two categorical variables.

Which test compares means of three or more groups?

Analysis of variance (ANOVA).

What is the difference between correlation and regression?

Correlation measures the strength and direction of a linear relationship; regression gives an equation to predict one variable from another.