The hardest part of inference is usually choosing the procedure, not running
it. This guide walks you from a description of your data to the exact test — and
to the mosaic/BSDA function that performs it. It uses the same formula
interface, goal(y ~ x, data = D), as the rest of the course, so once the guide
names your test you already know how to call it.
11. The master decision table¶
| Response | # groups | Paired? | Procedure | R function (mosaic / BSDA) |
|---|---|---|---|---|
| Categorical (binary) | 1 | — | One proportion (z) | prop.test(x, n, p = ) (or binom.test) |
| Categorical (3+ categories) | 1 | — | Chi-square goodness of fit | chisq.test(tally(~ var, data = D), p = ...) |
| Categorical (binary) | 2 | — | Two proportions (z) | prop.test(c(x1, x2), c(n1, n2)) |
| Categorical × categorical | 2 vars | — | Chi-square independence | xchisq.test(tally(~ y + x, data = D)) |
| Numerical | 1 | — | One-sample t | t.test(~ y, data = D, mu = ) — or tsum.test() from summary stats |
| Numerical | 2 | No | Two-sample (independent) t | t.test(y ~ group, data = D) |
| Numerical | 2 | Yes | Paired t | t.test(after, before, paired = TRUE) |
| Numerical | 3+ | — | One-way ANOVA (F) | anova(aov(y ~ group, data = D)) |
| Two numerical (association) | — | — | Correlation / linear regression | cor(y ~ x, data = D) / lm(y ~ x, data = D) |
Reading the whole table top to bottom is itself the decision procedure: find the row that matches your response type, number of groups, and pairing, and the last column is the call to make.
22. Decision flow, in words¶
Follow the branches in order.
Step 1 — Response type?
Numerical (e.g. PM2.5 level, yield per acre) go to Step 2A.
Categorical (e.g. yes/no, crop type, region) go to Step 2B.
Relating two numerical variables (does move with ?) correlation / regression,
lm(y ~ x, data = D). Done.
Step 2A — Numerical: how many groups?
One group, comparing its mean to a fixed value one-sample t,
t.test(~ y, data = D, mu = )(ortsum.test()from summary statistics).Two groups are they paired (same subjects twice / matched)?
Paired paired t,
t.test(after, before, paired = TRUE).Not paired two-sample t,
t.test(y ~ group, data = D).
Three or more groups one-way ANOVA,
anova(aov(y ~ group, data = D)).
Step 2B — Categorical: how many variables/groups?
One categorical variable, binary (two outcomes), one group one proportion,
prop.test(x, n, p = ).One categorical variable, 3+ categories, checking against claimed proportions goodness of fit,
chisq.test(tally(~ var, data = D), p = ...).A binary outcome compared across two groups two proportions,
prop.test(c(x1, x2), c(n1, n2)).Two categorical variables, testing if they are related chi-square independence,
xchisq.test(tally(~ y + x, data = D)).
33. Confidence interval, test, or both?¶
The table picks the procedure; you still decide what you want from it:
A confidence interval estimates the parameter (“how big is the difference?”). Use it when the goal is a range of plausible values.
A hypothesis test weighs evidence against a specific claim (“is there any difference at all?”). Use it when the goal is a yes/no decision with a p-value.
The t.test, prop.test, and BSDA *sum.test functions report both by
default — the printout gives you the test decision and the matching interval.
For a regression or ANOVA model, read the interval with confint(model).
44. Worked routing examples¶
55. Before you trust any result — check the conditions¶
Every procedure assumes something. Here is the short version; the chapter that introduces each test lists the exact conditions for your case.
| Procedure | Key conditions |
|---|---|
| One / two proportions | Independence; success–failure (≥ 10 successes and ≥ 10 failures, in each group) |
| Goodness of fit / independence | Independence; every expected count ≥ 5 |
| One / two / paired means (t) | Independence; population roughly Normal or (for paired, the differences are Normal) |
| ANOVA (F) | Independence; roughly Normal within groups; comparable spreads (largest SD < ~2× smallest) |
| Correlation / regression | Linearity; independent, roughly Normal residuals with constant spread |
If a condition fails, the result may be misleading. The chapter that introduces each test explains what to do (for example, a randomization or bootstrap approach when Normality is doubtful — see Ch. 7 and Ch. 8).