Tests for comparing percentages and means
Programme objectives:Tests for comparing percentagesTests for comparing means
Content: Which test? The type of the outcome decides · Contingency tables 2 × 2, 2 × 3, 3 × 4; χ² or Fisher · Comparing two means: Student’s t test · Paired data · Two quantitative variables: correlation, r and ρ · Interpreting beyond p.
Which test? First, the type of the variable to compare
- Qualitative outcome (SBP controlled: yes / no) → comparing percentages → χ² test, or Fisher’s exact test if counts are small.
- Quantitative outcome (SBP in mmHg) → comparing means → Student’s t test, or Mann-Whitney if the distribution is not normal.
- Two independent groups: different patients. The same patients measured twice (before / after) → paired tests.
Data to download
hypertension_trial_2026.csv
120 hypertensive patients randomised between two treatments, A and B. Blood pressure before and after three months. Simulated data for the course. 120 rows, 8 variables.
Variable dictionary
| Variable | Type | Content |
|---|---|---|
| id | identifier | patient number |
| group | qualitative nominal | A / B — treatment allocated at random |
| sex | qualitative nominal | F / M |
| age | quantitative continuous | years |
| sbp_before | quantitative continuous | SBP before treatment, mmHg |
| sbp_after | quantitative continuous | SBP after three months, mmHg |
| controlled | qualitative nominal | Yes if sbp_after < 140 mmHg |
| adverse_events | qualitative nominal | Yes / No |
Format: comma separator, decimal point, UTF-8 encoding — jamovi opens it with no settings. In Excel, use Data → From Text/CSV if the columns are not split.
cohort_efm1_2026.csv
200 outpatients: age, measurements, smoking, physical activity, blood pressure, blood glucose. Simulated data for the course. 200 rows, 11 variables.
Variable dictionary
| Variable | Type | Content |
|---|---|---|
| id | identifier | patient number |
| sex | qualitative nominal | F / M |
| age | quantitative continuous | years |
| height_cm | quantitative continuous | centimetres |
| weight_kg | quantitative continuous | kilograms |
| bmi | quantitative continuous | kg/m², computed |
| smoking | qualitative nominal | Yes / No — current smoker |
| physical_activity | qualitative ordinal | Low < Moderate < High |
| sbp_mmhg | quantitative continuous | systolic blood pressure, mmHg |
| fasting_glucose_g_l | quantitative continuous | fasting blood glucose, g/L |
| hypertension | qualitative nominal | Yes if SBP ≥ 140 mmHg |
Format: comma separator, decimal point, UTF-8 encoding — jamovi opens it with no settings. In Excel, use Data → From Text/CSV if the columns are not split.
Figures of the session (5) — download them for your own notes
Redo the three tests of the session on hypertension_trial_2026.csv: χ², Student’s t, paired t. Each result must match the slides.
- 1
Compare the percentages of controlled patients
- Analyses → Frequencies → Independent Samples — χ² test of association. Rows:
group; Columns:controlled. - Statistics: tick χ² and Fisher’s exact test. Cells: observed and expected counts, row percentages.
Expected result: A: 47 controlled out of 60 (78.3%); B: 34 out of 60 (56.7%). Expected counts A: 40.5 / 19.5, all ≥ 5. χ² = 6.42, p = 0.011; Fisher p = 0.019.
- Analyses → Frequencies → Independent Samples — χ² test of association. Rows:
- 2
Compare the mean SBP after treatment
- Analyses → T-Tests → Independent Samples T-Test. Dependent variable:
sbp_after; grouping variable:group. - Tick Student’s and Welch’s; Additional statistics: mean difference, confidence interval, descriptives; Assumption checks: normality (Shapiro-Wilk), homogeneity of variances (Levene).
Expected result: Student: t = -2.39, df = 118, p = 0.019; difference -5.5 mmHg, 95% CI [-10.1, -0.9]. Welch: t = -2.39, p = 0.019.
- Analyses → T-Tests → Independent Samples T-Test. Dependent variable:
- 3
Before / after: the paired test
- T-Tests → Paired Samples T-Test: drag
sbp_beforethensbp_after. Tick mean difference and confidence interval.
Expected result: Mean difference 20.6 mmHg, 95% CI [18.6, 22.6], t = 20.9, df = 119, p < 0.001.
- T-Tests → Paired Samples T-Test: drag
- 4
Two quantitative variables: correlation
- Open
cohort_efm1_2026.csv. Analyses → Regression → Correlation Matrix: dragageandsbp_mmhg. Tick Pearson and Spearman, and Plots → Correlation matrix for the scatter plot. - Read the sign (direction), the size of r (strength) and p. Then try
bmiagainstsbp_mmhg, andageagainstfasting_glucose_g_l.
Expected result: Age × SBP: Pearson r = 0.46, p < 0.001; Spearman ρ = 0.39, p < 0.001 — positive, moderate.
- Open
- 5
Going further
- Redo the paired test within each group: Data tab → Filters →
group == "A", then"B". - Compare
adverse_eventsbetween A and B with a χ²: do we conclude? What does the size of the counts say?
Expected result: Drop under A: 24.3 mmHg, CI [21.6, 27.0]; under B: 16.9 mmHg, CI [14.4, 19.4].
- Redo the paired test within each group: Data tab → Filters →