= Solution
A <chi-squared test> compares squared deviations with the size expected from the assumed random errors. For independent observations with a <normal distribution> $y_i$ with known <standard deviations> $\sigma_i$ and predictions $\mu_i(\theta)$, use
$$
Q=\sum_{i=1}^{N}\frac{[y_i-\mu_i(\widehat\theta)]^2}{\sigma_i^2}.
$$
For a correct fixed model, the standardized independent residuals are unit-variance <normal distributions>, so $Q$ has a <chi-squared distribution> with $\nu=N$. Fitting $p$ independent linear parameters removes $p$ residual directions, giving $\nu=N-p$. 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 $Q=\mathbf r^{\mathsf T}\Sigma^{-1}\mathbf r$, where $\Sigma$ is the <covariance matrix> and its rank and fitted constraints determine the available <statistical degrees of freedom>.
Under the <null hypothesis>, $\mathbb E Q=\nu$ and $\operatorname{Var}Q=2\nu$. The reduced statistic $Q/\nu$ should therefore be near one, with <standard deviation> $\sqrt{2/\nu}$, rather than equal to one exactly. An upper-tail <p-value> is
$$
\boxed{p=\Pr(\chi_\nu^2\geq Q_{\mathrm{obs}}).}
$$
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 $Q=\sum_{j=1}^k(O_j-E_j)^2/E_j$. 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 $k-1-p$ after fitting $p$ other parameters. Independent Poisson bins instead start with $k$ <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.
Back to article page