# Chapter 9 — complete draft exercise solutions

Constructed teaching cases only. These answers await independent statistical and author review.

1. Example estimand: the mean residual concentration in eligible production batches next month under the new protocol minus that under the old protocol, in mg/L. A prespecified useful improvement might be at least 0.5 mg/L lower. Randomly assign eligible batches (or a feasible cluster unit), conceal assignments where possible, use the same calibrated assay and time window, and retain all assigned batches in an intention-to-treat analysis. Record temperature and missingness.
2. For a specified null model and two-sided statistic, the p-value is the null probability of a statistic at least as far from its null centre as the observed one under the stated tail rule. It conditions on the null; it is not the posterior probability of that null given the data.
3. Sum 6, so mean 1. Squared deviations from 1 sum to 8; sample variance $8/5=1.6$. $SE=\sqrt{1.6/6}=.516398$, hence $t=1/.516398=1.936492$ with 5 degrees of freedom. The six weekly checks are the intended independent units, if their selection supports that interpretation.
4. Mean difference $-10/5=-2$ kWh. Squared deviations from -2 sum to 2, so $s_d^2=2/4=.5$ and $SE=\sqrt{.5/5}=.316228$. Treating before and after as independent drops their within-machine covariance and ignores the fact that each pair refers to one machine. It also does not fix time trends.
5. Means are 5 and 7, so B minus A is 2. Sample variances are $2/3$ and $8/3$; $SE=\sqrt{(2/3)/4+(8/3)/4}=\sqrt{5/6}=.912871$. Welch avoids imposing equal population variances, while still requiring a defensible independent-unit sampling/design model.
6. Group means 4,6,8; grand mean 6. $SS_B=3[(4-6)^2+(6-6)^2+(8-6)^2]=24$. Each group has within sum 2, hence $SS_W=6$. The cross term in $\sum(y_{ij}-\bar y)^2$ vanishes because deviations around each group's mean sum to zero. $F=(24/2)/(6/6)=12$ under the stated one-way model.
7. The two row totals and two column totals are each 20 of 40, so each expected count is 10. Four squared deviations of 4/10 yield $\chi^2=1.6$. A's correct rate .6 minus B's .4 is .20; the signed rate difference carries the direction, whereas chi-square does not.
8. $1-(1-.05)^{20}=.641514$. This special calculation assumes twenty independent tests and twenty true nulls, each with false-rejection probability .05. It is not a false-discovery-rate estimate for an arbitrary study.
9. No. Failure to reject zero does not show equivalence. Define a scientifically meaningful equivalence margin before examining the result, use a suitable equivalence procedure, and show enough precision to place the effect inside the entire permitted band under a credible design. The reported wide interval argues against a sameness claim.
10. The original rule counted only tail values in a prespecified direction. After seeing the statistic, choosing whichever one-sided direction looks favourable effectively searches two directions. The advertised one-sided type I error no longer describes that adaptive procedure.
11. Ten readings from one machine may be correlated and share calibration, workload and ambient conditions. Four machines may be the independently sampled or assigned units. One defensible first analysis is a per-machine mean or protocol contrast, followed by a model that respects repeated measurements; the scientific target determines the unit.
12. Example structure: “Among the defined eligible batches, the new-minus-old mean residual was -0.7 mg/L. Its 95% interval was [insert the actual calculated interval], including both smaller and larger improvements. The prespecified adoption threshold was a reduction of 0.5 mg/L. Two missing assays and a temperature imbalance limit the strength of the comparison.” Do not fabricate an interval when the raw data are absent.

## Verification notes

`testing_lab.py` reproduces the five numerical cases, their intermediate estimates, p-values and intervals with SciPy. The chi-square and ANOVA calculations in the chapter were separately checked against direct arithmetic. Numerical outputs are model-conditional; they do not independently establish assignment validity, representative sampling or causal effect.


## Added contingency practice

For [[20,15,15],[10,20,20]], expected rows are [15,17.5,17.5], chi-square=100/21=4.76190476, df=2 and p=0.09246248.

## Excel statistical laboratory

For waits [2,3,3,4,5,19], mean=6, median=3.5, mode=3, sample variance=41.6, sample SD=6.4498062. The normal-model t interval has margin 6.7686565, with endpoints -0.7686565 and 12.7686565. For x=[1,2,3,4,5], y=[2,1,4,3,5], Pearson r=.8, fitted intercept=.6, slope=.8 and SSE=3.6. The independent Welch comparison of [3,4,5] and [5,6,7] gives t=-2.44948974, df=4 and p=.070483997.
