Independence log-linear model for a two-way contingency table Created 2026-09-29 Updated 2026-10-14
Linear-by-linear association test Created 2026-09-29 Updated 2026-10-14
For a two-way contingency table whose row and column variables are ordinal categorical variables, assign row scores and column scores . The linear-by-linear association statistic measures the weighted covarianceAfter normalization, its square is asymptotically under independence. A signed, one-sided version tests a specified direction of ordinal association and can have greater statistical power than an omnibus independence test against a monotone alternative.
Mating assortment contrast 2026-10-14
For observed pairings between two labels , let and , where the first label denotes the female's group and the second the male's. A mating assortment contrast isIt lies between and . Positive describes an excess of same-label pairings over cross-label pairings; whether that is evidence of assortative mating depends on the null mathematical model and the assay. The four counts form a contingency table.
Here is an original scope check. Suppose independently paired females and males have probabilities of carrying label . ThenWith , the expected value is zero. With , it is , despite pairing being independent of label. This counterexample concerns unequal pool composition; it does not replace the group introductions and contingency table tests in the dietary divergence and mating isolation in Drosophila pseudoobscura experiment. Even with balanced pools, finite observed samples fluctuate: a positive alone is not a hypothesis test, much less a universal species boundary.
Past exam of the mathematics course of the University of Cambridge 2001 iii Paper 28 2 i Solution Created 2026-10-03 Updated 2026-10-14
The missing output is needed to identify the actual regression formula, response column, transformations and coefficient estimates. A useful possible analysis regresses the maintained-school percentage among acceptances on the corresponding percentage among applications, allowing for year; it must be described as a model of college-level composition, not a direct estimate of individual acceptance probabilities.
For instance, if and are these two percentages, a normal linear model might specify , with a slope-by-year interaction term if needed. The intercept is the expected response at zero predictor, often an extrapolation; the slope is a percentage-point change in acceptance composition per percentage-point change in application composition. A slope of one is not by itself evidence of equal acceptance chances: equal chances within every college would give the entire relation , including zero intercept and no year shift. A fit with positive slope mainly confirms that applicant composition helps predict acceptance composition.
Regression diagnostics should include residuals versus fitted values and predictors, a residual normal Q-Q plot, checks of heteroscedasticity, regression leverage, studentized residuals and Cook's distance. The aggregate mature-college category merits an influence check and a sensitivity analysis: combining several colleges can conceal different within-college patterns. Repeated observations from the same college across years may have correlated errors, so treating them as independent needs justification. Check nonlinearity, the year interaction and the effects of excluding no observation except with a substantive reason.
Percentages are bounded, and their precision depends on their denominators. A simple weighted least squares or binomial analysis requires the underlying numbers accepted, not merely percentages. For a proportion based on people, the working variance is under independent sampling, rather than constant across colleges. If the predictor percentage is itself estimated, an ordinary regression also ignores its uncertainty. The supplied summaries cannot recover all four cells of each college contingency table or the actual fitted numerical output.
The published Cambridge percentage table nevertheless allows a descriptive comparison of acceptance rates. Write for the maintained-school proportion among applicants and for its proportion among acceptances. The relative risk from group compositions givesThe overall acceptance probability cancels by Bayes' theorem. This risk ratio compares acceptance probabilities; it is not the acceptance odds ratio, which also needs the overall acceptance probability.
For Christ's, the two published application/acceptance pairs give risk ratios and . If the displayed percentages were rounded to the nearest whole percentage point, the relative risk bounds from rounded group compositions give ranges approximately and . Thus both comparisons remain below one under that rounding assumption. These are descriptive comparisons of observed groups, without adjustment for applicant qualifications or a causal effect interpretation. The published compositions determine approximate relative acceptance rates, but not their standard errors or the original regression results.
Past exam of the mathematics course of the University of Cambridge 2003 iii Paper 40 5 iii Solution Created 2026-10-03 Updated 2026-10-14
Arrange rows by marker genotype, with cases and controls as the two columns. Both column totals are 100, and the three row totals are 100, 60 and 40. Under the null of no genetic association, estimate each common row probability from its pooled proportion. The expected count is row total times column total divided by the grand total. Thus the expected contingency table isThe Pearson chi-squared test of independence usesUnder independent sampled individuals and the no-association null, its reference chi-squared distribution has degrees of freedom. All expected cells are well above five. The null is overwhelmingly rejected: the approximate p-value is . This establishes association in the sampling model, not by itself a causal role for the marker.
Past exam of the mathematics course of the University of Cambridge 2003 iii Paper 40 5 iv Solution Created 2026-10-03 Updated 2026-10-14
Each diploid individual contributes two marker alleles. Count copies as twice the count plus the count, and count copies analogously. The observed chromosome-level contingency table, followed by its null expected table, isThere are 200 chromosomes in each group; pooled totals are 140 and 260 . The usual allelic Pearson chi-squared test of independence givesWith the ordinary independent-chromosome null model, use one degree of freedom; its p-value is about , providing very strong evidence of genetic association.
The two alleles from the same person are not automatically two independent observations. The usual one-degree-of-freedom calibration is justified, for example, for unrelated individuals with Hardy-Weinberg equilibrium under the null. If that assumption is not suitable, retain individuals as the sampling units and test their allele dosages using an appropriate variance or permutation of case-control labels, or use the genotype-level test from part (iii). No Hardy-Weinberg equilibrium assumption was needed for that genotype-level test.
Past exam of the mathematics course of the University of Cambridge 2004 iii Paper 37 2 i Solution Created 2026-10-03 Updated 2026-10-14
Treat the counts as independent binomial distributions, , conditional on the known numbers of operations. The null hypothesis is that the probabilities are all equal, with no assumed numerical value. Centre 4 has no operations in this period and hence contributes likelihood one, supplying no information about its mortality probability. The empty groups in a binomial homogeneity test principle leaves 11 contributing centres and 10 test degrees of freedom.
Under the common-probability model the maximum-likelihood estimator isUse the two-column contingency table of deaths and survivors, deleting its all-zero row. The Pearson chi-squared test of homogeneity has statisticUnder the null, the large-sample reference distribution is . The expected counts are adequate for this approximation here, including at the smallest nonempty centre. Calculating givesAn alternative is the likelihood-ratio test against separate centre probabilities, with binomial devianceThe unrestricted probabilities are ; subtracting one fitted common probability leaves the same 10 degrees of freedom. Here and . Thus there is strong evidence against a common mortality probability. This omnibus test does not identify Centre 1 as the sole source of the heterogeneity. If its comparison with the remaining centres is the primary scientific question, specify a separate planned one-versus-rest comparison; inspection of many pairwise comparisons calls for consideration of multiple testing.
Past exam of the mathematics course of the University of Cambridge 2005 iii Paper 41 4 Solution Created 2026-10-03 Updated 2026-10-14
read.table(...,header=T) reads four grouped rows with column names. The displayed outcome counts give the observed risks in the indicated factor order. rbind in the first test pools over predisposition: the two rows represent no cannabis use and some use, with event/non-event counts and . Thus the pooled risks are and . This test concerns the marginal statistical association between use and outcome, not an association adjusted for predisposition.Under independence, expected counts in the two-by-two contingency table are . The ordinary Pearson chi-squared statistic is . The printed is reproduced by the default two-by-two Yates continuity correction:All absolute differences here exceed one half. Comparison with a chi-squared distribution on one statistical degree of freedom gives . There is strong evidence of marginal association. The simplified output omits the usual continuity-correction wording, but its numerical value shows which statistic was used.
attach makes the data columns available by name, and tot=with+without obtains group sizes . The grouped binomial regression fits , with response and prior weights . These weights tell R the binomial denominator; treating the four proportions as four equally precise individual observations would be wrong. The default logit link isLet indicate some use and indicate predisposition. The additive logistic regression specifies . Its log-likelihood, including the binomial constants, isDifferentiation gives score equations and Fisher information matrix , where . Fisher scoring solves these equations, and the inverse fitted Fisher information matrix gives the reported approximate coefficient variances. The number of scoring iterations records numerical convergence, not degrees of freedom or statistical evidence.The intercept corresponds to no use and no predisposition and gives baseline fitted risk . The additive coefficients imply common adjusted odds ratios:They multiply the odds, not the risks. The Wald tests divide the estimates by their standard errors and use a standard normal distribution; both predictors have small two-sided p-values. Approximate confidence intervals for these odds ratios are and , obtained by exponentiating the log-scale intervals. The intercept test against zero asks whether the reference risk equals one half, and is not a test of either exposure association. The binomial dispersion is assumed to be one because ; the output does not demonstrate independence or rule out extra-binomial variation.
There are four grouped probabilities and three fitted coefficients, leaving one residual degree of freedom. The fitted risks are approximately . The binomial deviance compares this fit with the four unrestricted observed proportions:The deviance goodness-of-fit test against has p-value . The common-odds-ratio fit is not rejected at , although the doubly exposed group's observed risk exceeds its fitted risk appreciably and suggests possible interaction.
The second formula adds . Its four coefficients fit all four probabilities, making a saturated statistical model with zero grouped residual degrees of freedom. The near-zero deviance is roundoff from exact interpolation; it supplies no remaining grouped lack-of-fit test. Unlike Q1's unreplicated Gaussian fit, however, these grouped responses represent many independent Bernoulli trials, and their binomial variances are specified by their sizes and probabilities. Coefficient standard errors remain available from binomial information without estimating dispersion from the zero residual degrees of freedom.
Indeed, let be the fitted cell logit link value. The saturated coefficients areThese calculations yield the printed estimates. The delta method gives , and independent groups make the variance of the sum of all eight reciprocal counts. Its square root is , reproducing the printed standard error.
The saturated logistic regression describes the conditional odds ratios as follows:Thus the main coefficients now concern effects at the other factor's reference level. Logistic interaction as a ratio of odds ratios gives , with approximate confidence interval . The interaction Wald test has , while the nested likelihood-ratio test uses deviance difference on one statistical degree of freedom and has . The data suggest a larger odds association in predisposed subjects, but do not establish this interaction at the conventional level. This conclusion is specific to the odds scale; absolute-risk differences can vary even with no logit-scale interaction.
The Akaike information criterion is . The additive fit has and AIC ; the interaction fit has and AIC . The extra coefficient improves twice the log-likelihood by but incurs penalty , so AIC falls by only . It weakly favors the larger fit rather than decisively establishing an interaction, and AIC is not a p-value.
The marginal odds ratio and the fitted conditional odds ratios are different quantities. Predisposition is associated with both use frequency and outcome, so confounding is a substantive possibility; noncollapsibility of the odds ratio also means marginal and conditional odds ratios need not agree. This is an observational association analysis with only one adjustment factor. It does not by itself establish a causal effect, exclude other confounding, or validate the assumed independent binomial sampling.
Past exam of the mathematics course of the University of Cambridge 2017 ii Paper 4 5J a Solution Created 2026-09-24 Updated 2026-10-05
This is the appropriate command for the full contingency table. It fits a log-linear model to the nine cell counts, with logarithmic link function and no interaction:With baseline constraints on , there are five parameters. The factorized means express independence of treatment group and damage category. The maximum-likelihood estimates areAlthough the experiment fixes each row total at 30, conditioning these independent Poisson random variables on those totals produces the appropriate row-wise multinomial distribution. The Poisson trick therefore gives the correct likelihood inference for this independence log-linear model for a two-way contingency table; the margins are nuisance parameters. It tests whether treatment changes the distribution of damage, rather than modelling a binary outcome.
Past exam of the mathematics course of the University of Cambridge 2017 ii Paper 4 5J d Solution Created 2026-09-24 Updated 2026-10-05
The count weights correct the loss of frequencies for a deliberately coarsened binary response, but do not supply a third outcome category. Thus this remains inappropriate for the full contingency table. With the base R factor convention, it could fit the chosen first damage level versus the other two combined, using a logistic regression and the frequencies as weights. That is a different scientific question. The supplied log-linear model retains all three categories and their counts without this information loss.
Past exam of the mathematics course of the University of Cambridge 2018 ii Paper 3 5J Solution Created 2026-09-24 Updated 2026-10-03
Treat the cell counts as independent Poisson random variables. Under independence of Month and Hospital, the independence log-linear model for a two-way contingency table iswith no Month–Hospital interaction. Compare its Poisson deviance with the appropriate upper quantile of a chi-squared distribution. This is the likelihood-ratio test of independence in a contingency table.
The approximation assumes independent counts with correctly specified Poisson means, identifiable parameters, and sufficiently large fitted cell means for the asymptotic chi-squared law to be accurate. Equivalently, one may condition on the margins and use the corresponding multinomial sampling formulation.
For the month table there are cells and independent model parameters, so the residual degrees of freedom areSincemodel 1 does not reject Month–Hospital independence at the level.
After combining months into four quarters, the table is , givingdegrees of freedom. Nowso model 2 rejects Quarter–Hospital independence at the level.
There is no contradiction. Relabelling twelve months as four quarters aggregates the contingency table, changes the null hypothesis, and reduces the degrees of freedom. The quarter-level hospital pattern is coherent enough to cross the much lower six-degree-of-freedom threshold even though the more detailed month-level omnibus test does not. This is an instance of how aggregation can change a contingency-table independence test.
Pearson chi-squared statistic for contingency tables Created 2026-10-06 Updated 2026-10-14
For observed counts and positive expected counts in a contingency table, the statistic is . Under common category probabilities or statistical independence, estimate by the product of the row and column totals divided by the grand total. With large expected counts, this gives the test statistic for the Pearson chi-squared test of homogeneity or the Pearson chi-squared test of independence, with asymptotic chi-squared distribution on degrees of freedom.
For independent Poisson cell counts in stratified two-by-two contingency tables, the model allows both margins to vary by stratum but excludes within-stratum association. Its fitted means are the displayed products of margins, because the Poisson regression score equations match those margins. Every stratum's odds ratio is one. With positive nondegenerate margins, strata give parameters and residual degrees of freedom. A common association adds one parameter; stratum-specific associations saturate the tables.
Yates's correction for continuity 2026-10-14
For a two-by-two contingency table, subtracting one half from each absolute observed-minus-expected count difference, with truncation at zero, gives the displayed corrected Pearson chi-squared statistic. Expected counts use the independence model . The subtraction compensates approximately for using a continuous chi-squared distribution for discrete counts. It can make the test conservative. The corrected statistic should be distinguished from the ordinary uncorrected Pearson chi-squared statistic.