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

t-test compares means (continuous); chi-square tests association between categorical variables.

How to answer it

It comes down to the type of the outcome.

So "did the new page raise average order value?" is a t-test (Welch's, which does not assume equal variances). "Did the new page change the conversion rate?" is a chi-square test on a 2x2 table of converted/not by variant, which is equivalent to a two-proportion z-test.

from scipy import stats
# means: Welch's t-test
t, p = stats.ttest_ind(aov_a, aov_b, equal_var=False)
# rates: chi-square on the contingency table
table = [[1600, 48_400], [1500, 48_500]]   # [converted, not] per variant
chi2, p, dof, _ = stats.chi2_contingency(table)

Conditions to mention: the t-test wants independent observations and, for small n, roughly normal means (the CLT covers large n); chi-square wants expected counts of at least about 5 per cell, otherwise use Fisher's exact test. If the numeric metric is heavily skewed and n is small, a Mann-Whitney test or a bootstrap is safer than either.

Related questions

Practice this for real