Statistics · medium

When would you use a t-test vs a chi-square test?

Asked in Data Analyst interviews, in the Statistics round.

Short answer

A t-test compares means of a continuous variable, a chi-square test checks association between categorical variables.

T-testChi-square
Outcome isA number, like revenue or timeA count in categories, like converted or not
ComparesTwo meansObserved against expected counts
Typical A/B useAverage order value per groupConversion rate per group
AssumesRoughly normal means, similar varianceExpected count of at least 5 per cell
The outcome you measured decides the test, not the question.

How to answer it

Definition

The outcome you measured decides the test. A number per unit points to a t-test; a category per unit points to a chi-square. The table above compares them directly.

Example

Question: did the new checkout page help?

Metric: conversion rate      -> each user converted or not
                             -> counts in categories
                             -> chi-square on the 2x2 table

Metric: average order value  -> each user has a number
                             -> comparing means
                             -> t-test, Welch's version

The 2x2 table

              converted   not converted
control            800          19,200
variant            880          19,120

Chi-square asks whether the split of converted against not converted depends on which group you were in.

Always Welch's

For two means, use Welch's t-test rather than Student's. It does not assume equal variances, it costs nothing when the variances happen to be equal, and the equal-variance assumption is rarely true in product data. Most libraries default to it; scipy.stats.ttest_ind needs equal_var=False.

Key points

FAQ

The 30-second answer

It comes down to the type of the outcome, not the question. If each unit gives me a number and I am comparing means, that is a t-test, and I would use Welch's version because it does not assume equal variances and costs nothing when they happen to be equal.
If each unit gives me a category and I am comparing counts, that is a chi-square on the contingency table. So for a conversion rate I would use chi-square, and for average order value on the same experiment a t-test.
The check I would mention for chi-square is the expected count per cell, around five or more; below that I would use Fisher's exact test instead.

In the interview

Practice this for real