Solution (source code)

= Solution

The fitted <grouped-binomial logistic regression> <generalized linear model> treats seasonal hits $H_i$ as independent $\operatorname{Bin}(n_i,p_i)$ variables, with $n_i=\mathrm{AB}_i$ and
$$
\log\frac{p_i}{1-p_i}=\beta_0+\beta_1a_i+\beta_2a_i^2.
$$
Thus the response supplied to `glm` is a proportion, and `weights=AB` supplies its binomial denominator; it is not a regression with equally precise seasonal averages. `I(Age^2)` forms the numerical square rather than using a formula operator. The estimates maximize $\ell(\beta)=\sum_i[H_i\eta_i-n_i\log(1+e^{\eta_i})]$ up to a constant, where $\eta_i=x_i^T\beta$, $x_i=(1,a_i,a_i^2)^T$.

The observed negative <Hessian> is $X^TWX$, $W_{ii}=n_i\widehat p_i(1-\widehat p_i)$. Expanding the score around the true parameter and applying a central-limit approximation gives $\widehat\beta\approx N(\beta,(X^TWX)^{-1})$. The reported <standard errors> are square roots of the diagonal entries of this inverse; the binomial dispersion is fixed at one. Each `z value` divides the coefficient estimate by its <standard error>, and the reported two-sided <Wald test> uses a standard normal approximation under the corresponding zero-coefficient hypothesis.

The last line reports the <deviance> against the saturated model,
$$
D=2\sum_i\left[H_i\log\frac{H_i}{n_i\widehat p_i}+(n_i-H_i)\log\frac{n_i-H_i}{n_i(1-\widehat p_i)}\right],
$$
with $0\log0=0$. There are 22 seasonal observations and three fitted parameters, so 19 <degrees of freedom>. Under the quadratic-logit model, independent binomial sampling and sufficiently large expected counts, $D\approx\chi^2_{19}$. The value 23.345 gives an upper-tail <probability> about 0.22, \b[no evidence of lack of fit at conventional levels]. This approximation and the independence assumption should not be confused with an exact test of a player's ability.

The final commands recover the coefficients, apply the inverse logit $p=(1+e^{-\eta})^{-1}$, plot the observed averages against age, and join the fitted <probabilities> at the observed ages. The fitted curve is smooth, rises towards its peak at $a=-\widehat\beta_1/(2\widehat\beta_2)\approx29.95$, then falls. Its maximum is about 0.373; the early and late observed points include markedly lower averages. The plot uses equally sized points even though their binomial precisions differ.

\Image[/past-exam-of-the-mathematics-course-of-the-university-of-cambridge/2006/ii/paper-1-batting-fit.png]
{title=Observed seasonal batting averages and the fitted quadratic logistic curve}