Chi-squared test 2026-10-14
A chi-squared test rejects a null hypothesis for a statistic whose null distribution is a chi-squared law, exactly or asymptotically. Pearson tests compare observed and expected counts; both goodness-of-fit and chi-squared tests of independence are instances.
Equality criterion for paired and unpaired allele tests Created 2026-10-14 Updated 2026-11-05
Let a paired binary table have cells and . The uncorrected McNemar test is , while the ordinary independent-sample chi-squared test on the two marginal allele columns is . For nonzero difference and positive denominators, they coincide exactly when . Such numerical coincidence does not justify discarding pairing; altering concordant counts can change the unpaired statistic while leaving McNemar's statistic unchanged.
// Target: biology.bigb
Let denote the two ordered alleles at the genetic locus. Under Hardy-Weinberg equilibrium they are independent with probabilities . Write the multiplicative penetrance as , with parameters chosen so these are valid probabilities, and set . Then
The Bayes' theorem gives
Thus multiplicative penetrance preserves Hardy-Weinberg equilibrium: the affected subjects still have two independent allele draws, with tilted allele frequencies. The displayed product uses ordered allele slots. For the usual unordered genotypes, the corresponding probabilities are
The factor of two is required for heterozygotes and must not be dropped when translating the ordered notation into genotype counts.
For genetic association analysis, the case genotype probabilities factor into allele frequencies, so under this model an allelic comparison with representative population controls is appropriate; separate dominance departures are not required by the penetrance model. The ratio of case allele frequency to population allele frequency is proportional to , and relative risk multipliers satisfy . Population controls are important to this exact statement. Among specifically unaffected controls,
which generally does not factor. For a rare disease it is close to the population genotype law, but no rare-disease assumption was needed for the case factorization itself. Population stratification and sampling dependence must also be addressed before using an ordinary allelic chi-squared test.
A case chromosome is transmitted and a pseudo-control chromosome is untransmitted. Summing the paired table by columns for cases and by rows for controls gives
For the ordinary unpaired chi-squared test of independence, the expected cells are 30,30,70,70. Its uncorrected Pearson statistic is
For the paired McNemar's test, only the discordant transmissions matter, with counts 24 and 18. Thus
Both uncorrected statistics happen to coincide and have the same approximate one-degree-of-freedom chi-squared distribution reference, giving . The data do not show persuasive transmission imbalance at the conventional 5% level.
The equality is a numerical coincidence, not a justification for ignoring pairing. To see the equality criterion for paired and unpaired allele tests, write the original matched cells as and . The unpaired marginal-table statistic is
whereas McNemar's is . Here , , and , giving equality. Changing concordant counts can change the unpaired statistic without changing McNemar's. The transmission disequilibrium test should retain its conditional paired interpretation.
If a continuity correction is used, state it explicitly: McNemar's corrected statistic is ; the corresponding Yates-corrected marginal statistic also coincides here. An exact conditional test uses and gives the two-sided probability .
For independent Gaussian measurements with correctly specified standard deviations, model residuals give the chi-squared test statistic
For a linear fit of identifiable parameters under the null model, it has a chi-squared distribution with degrees of freedom. The upper-tail p-value tests unusually large residuals; a nonlinear fit generally uses this distribution only approximately. Correlated Gaussian errors instead require .
For counts, Pearson's chi-squared test uses , with calculated under the null hypothesis. For multinomial categories and fitted parameters the usual asymptotic degrees of freedom are ; the subtraction of one reflects the fixed total count. Sparse expected counts can invalidate this approximation, requiring a suitable exact or simulation-based test. Contingency-table independence gives degrees of freedom.
A small p-value indicates tension with the specified model and error assumptions; it is not the probability that the null is true. Excessive may reflect a wrong model, underestimated errors, correlations or outliers. An implausibly small value may suggest overestimated errors or hidden constraints. For an adequate fitted model is typically near one, with fluctuations, rather than required to equal one.
A chi-squared test compares discrepancies with their expected random size. For independent Gaussian observations with known standard deviations, a fitted model gives
Under a correct regular model with fitted parameters, its reference statistical degrees of freedom are usually . Correlated errors instead require with the correct covariance matrix. The reduced statistic has mean about one and standard deviation , so it should not be forced to equal exactly one.
For binned counts, Pearson's statistic is . With a fixed total and populated categories, fitting distribution parameters generally gives . The approximation needs adequately populated expected bins and the appropriate dependence assumptions. Sparse data may require a Poisson likelihood, exact calculation or simulated reference distribution rather than a casual chi-squared approximation.
The upper-tail probability measures how unusual the discrepancy would be under the null model; it is not the probability that the model is true. A large statistic can indicate a wrong model, underestimated noise or unmodelled systematic effects; an unusually small one can indicate overestimated errors or correlations. Residual plots and checks of the noise model are needed alongside the numerical test.
A chi-squared test compares residuals with the random scatter predicted by a model. For independent measurements with known Gaussian standard deviations and predictions , form
If the mean model and error assumptions are correct, a full-rank linear fit of parameters gives a chi-squared distribution with statistical degrees of freedom. With a fully specified prediction and no fitted parameters, . Nonlinear fits usually make this an approximation. Independent external calibration is not the same as fitting a parameter to these test data.
Under the reference distribution, the mean statistic is and its variance is . The upper-tail p-value quantifies how unusual a discrepancy at least this large would be under the assumed model. A small value suggests model failure or incorrect uncertainties; it is not the probability that the model is true. An unusually small statistic can also reveal inflated uncertainties or correlations. A rejection threshold should be specified in advance.
For independent Poisson distribution counts, the model variance is its expected count . The Pearson chi-squared statistic is . The estimated-error alternative is common for large counts but can differ substantially when counts are small. In that regime the Poisson deviance or a direct likelihood calculation is preferable, with simulation if an accurately calibrated goodness-of-fit probability is required.
A chi-squared test compares squared deviations with the size expected from the assumed random errors. For independent observations with a normal distribution with known standard deviations and predictions , use
For a correct fixed model, the standardized independent residuals are unit-variance normal distributions, so has a chi-squared distribution with . Fitting independent linear parameters removes residual directions, giving . This distribution is exact for a full-rank linear model with known errors with a normal distribution; it is an approximation for many nonlinear fits. With known correlated errors with a multivariate normal distribution, replace the sum by , where is the covariance matrix and its rank and fitted constraints determine the available statistical degrees of freedom.
Under the null hypothesis, and . The reduced statistic should therefore be near one, with standard deviation , rather than equal to one exactly. An upper-tail p-value is
Compare it with a significance threshold chosen in advance. A small value indicates tension with the model together with its error assumptions; it can arise from a wrong mean model, underestimated uncertainties or neglected correlations. An unusually small statistic can suggest overestimated uncertainties, correlations or overfitting. A p-value is not the probability that the model is true, and failure to reject is not proof of the model.
For counts in categories, the Pearson form is . Its chi-squared distribution is an asymptotic approximation requiring adequate expected counts. For a fixed-total multinomial sample there is one normalization constraint, so the usual statistical degrees of freedom are after fitting other parameters. Independent Poisson bins instead start with statistical degrees of freedom before parameters are fitted. Sparse counts require an appropriate count likelihood or a calibrated exact or simulation-based test; plugging tiny expected counts into the asymptotic formula is unreliable. The error model, binning, fitted parameters and chosen test must therefore be reported with the result.
A chi-squared test compares the sum of squared standardized regression residuals with the appropriate chi-squared distribution. With both line parameters fitted, the data give on degrees of freedom, with upper-tail P-value about : the fitted exponential decay model describes the data adequately.
First consider fixing the alternative lifetime at its central value . Its slope is . One must refit the normalization rather than retain the earlier intercept. Minimization over the intercept gives , and
on degrees of freedom, with upper-tail P-value about . Thus that fixed central lifetime gives a substantially worse fit than . Equivalently, the increase after profiling over the intercept is
This fixed-value comparison does not yet include the uncertainty of the alternative measurement.
For the compatibility of independent lifetime measurements, include both errors. Under the approximately Gaussian lifetime-error model, equality of the two true lifetimes is tested by
This has one degree of freedom and P-value approximately , equivalent to a -standard deviation discrepancy. The two measurements are therefore in mild tension: equality is rejected at a significance threshold, but not at . There is no unique yes-or-no compatibility verdict without choosing such a threshold. Treating the alternative central value as exact would overstate the disagreement between the experiments.
The lifetime that provides the best fit to these six rates remains , not . The compatibility calculation above assumes the two experiments have independent uncertainties; a shared systematic error would require its covariance.
Assume independent normally distributed angle errors with known standard deviation . The relevant chi-squared test uses the sum of squared standardized residuals,
For the model through the origin, the predictions and residuals, expressed in milliradians, are
Consequently . There are statistical degrees of freedom. The upper-tail P-value is approximately ; equivalently the value greatly exceeds the critical value . The zero-intercept model is strongly rejected under the stated errors.
For the alternative linear regression, minimize . Setting both partial derivatives to zero gives the normal equations, whose solution is
For these data , , and . This yields
The new predictions are , with residuals . Therefore
The affine model is compatible with the data. Allowing for its additional fitted parameter, the decrease has a chi-squared distribution with one statistical degree of freedom under the nested zero-intercept hypothesis, corresponding to . Thus the model with a fitted intercept provides the better description, rather than merely lowering the residual by adding a parameter.
With the measurement variance treated as known, the coefficient uncertainties are
Hence , about standard deviations above zero. A positive constant systematic error in the angular zero, or an additional nearly constant torque, could account for it. Its presence is evidence against the ideal zero-intercept model; four points alone do not identify the physical cause uniquely. A calibration error in only rescales the inferred gravitational constant and cannot remove this residual pattern.
Using the fitted slope after allowing for this offset would give , with the period and slope errors combined in quadrature. This is conditional on the constant-offset model.
For observed counts in an by contingency table, Pearson's chi-squared test statistic for independence is
Under the null model and the usual large-expected-count conditions, its reference distribution is with degrees of freedom.