Statistics Lab · step 03

Compare groups.

Use cross-tabs, chi-square, Welch’s t-test and Mann–Whitney for distinct questions—and interpret more than significance.

Outcome: three unadjusted comparisons with assumptions, effect estimates and clinical context kept visible.

Seven-step investigationNow: 03 · Compare groups

Analysis checkpoint

Match one comparison method to one question.

Work through these six prompts in order. Each one supplies what the next one needs.

1 · Before you start

Have the overall cohort description from Step 02 and know which variable is the exposure group and which variable is the outcome for each comparison.

Words used on this page

Cross-tabulation
a table of counts for two categorical variables.
Independent observations
each participant contributes a separate observation, not a paired or repeated one.
Confidence interval
a range showing the estimate's statistical uncertainty.
p-value
how incompatible the data are with a specified null model; it is not the size or importance of an effect.
Welch's t-test
a comparison of two means that does not assume equal variances.
Mann–Whitney test
a comparison based on the ranks, and therefore distributions, of two groups.
2 · Why this comes now

Simple, unadjusted comparisons show the observed group patterns before effect measures and regression add more structure. The outcome scale determines the method.

3 · Do this now
  1. Cross-tabulate medication review with six-month disability and inspect row percentages.
  2. Compare mean quality of life with Welch's t-test and ranked medicine counts with Mann–Whitney.
  3. For each comparison, record the group values, estimate or test result, confidence interval where available and p-value.
Same step in Stata and SPSS

Run Section 03 in Stata or SPSS. The command names differ, but both routes should produce the same 2 × 2 counts, group summaries and three unadjusted conclusions.

4 · Read this

Read the group values before the p-value. For the t-test use the unequal-variance result; for Mann–Whitney interpret a difference in ranked distributions unless the distribution shapes support a median interpretation.

5 · Ready to continue when

You can state what each method compares, report the observed values and uncertainty, and explain why statistical significance alone is not the finding.

6 · Next step 04 · Measure association Turn the disability table into absolute and relative measures.

Test selector

Ask what is being compared.

QuestionMethodRead before the p-value
Are two categorical variables associated?Cross-tabulation + Pearson chi-squareCounts, row/column percentages and expected counts.
Do two independent groups differ in mean outcome?Welch’s independent t-testGroup means, mean difference, 95% CI and outliers.
Do two independent groups differ in rank distribution?Mann–Whitney / Wilcoxon rank-sumGroup distributions and the estimand; it is not automatically a test of medians.

Independence matters. These procedures do not cover paired before-and-after data, repeated measurements or clustered samples.

Worked comparisons

Read the estimate, interval and context.

Chi-square

Disability risk is 22.5% with a review and 21.9% without. Pearson χ² = 0.033, p = 0.857.

Welch’s t-test

Mean EQ-5D-style scores are 0.750 and 0.751; mean difference −0.001, 95% CI −0.020 to 0.018.

Mann–Whitney

Medication count is higher in the review group: median 5 versus 3; p < 0.001.

Interpretation

The groups differ at baseline but not in the crude outcomes. That is a reason to examine confounding, not to hunt for another test.

Representative output · same teaching data in all three routes

Three unadjusted group comparisons

Outcome / method              Estimate or test             95% CI                 p
Disability / chi-square       22.5% vs 21.9%; χ²=0.033      —                       0.857
EQ-5D / Welch t-test          reviewed − unreviewed=-0.001 -0.020 to 0.018         0.921
Medicines / Mann–Whitney      medians 5 vs 3; W=37,897      —                      <0.001

What the output means

The disability proportions and mean quality-of-life scores are very similar before adjustment, and their tests provide no evidence of a crude group difference. Medication counts tend to be higher in the reviewed group. The Mann–Whitney result concerns the rank distributions; it is not automatically a confidence interval for a difference in medians.

Write the interpretation like this

At baseline, participants who received medication review took more medicines (median 5 versus 3; Mann–Whitney p<0.001). Crude six-month disability (22.5% versus 21.9%; χ²=0.033, p=0.857) and mean quality of life (difference −0.001, 95% CI −0.020 to 0.018) were similar between groups.
Stata

The three commands mirror the three questions: association between categories, difference in means, and difference in rank distributions.

tabulate med_review disability_6m, ///
    row column expected chi2

ttest eq5d_6m, by(med_review) unequal

ranksum medication_count, by(med_review)
Download the complete commented Stata do-file
IBM SPSS Statistics

Use Crosstabs, the unequal-variances t-test row, and an independent-samples Mann–Whitney test.

CROSSTABS
  /TABLES=med_review BY disability_6m
  /STATISTICS=CHISQ
  /CELLS=COUNT ROW COLUMN EXPECTED.

T-TEST GROUPS=med_review(0 1)
  /VARIABLES=eq5d_6m
  /ES DISPLAY(TRUE)
  /CRITERIA=CI(.95).

NPAR TESTS
  /M-W=medication_count BY med_review(0 1).
Download the complete commented SPSS syntax file
R and RStudio

table(), t.test() and wilcox.test() keep each comparison readable and return confidence intervals where available.

disability_table <- with(
  cohort,
  table(med_review_f, disability_6m)
)
prop.table(disability_table, margin = 1)
chisq.test(disability_table, correct = FALSE)

t.test(eq5d_6m ~ med_review_f, data = cohort)

wilcox.test(
  medication_count ~ med_review_f,
  data = cohort,
  exact = FALSE,
  conf.int = TRUE
)
Download the complete commented R script

Official references

Check the procedure details.

Stata t-test manual

Syntax, assumptions and worked examples for one- and two-sample tests.

Open PDF

Stata rank-sum manual

Official details for the equality-of-populations rank test.

Open PDF

IBM independent t-test

Group definition, output, assumptions and unequal-variance results.

Open IBM documentation