mescla.emma.diagnostics.residual_structure_test

mescla.emma.diagnostics.residual_structure_test(observed, fitted, alpha=0.05)[source]

Test each species’ residuals for structure against observed concentration.

A conservative species in a correctly ranked model leaves residuals that are a structureless cloud. Curvature or trend means lack of fit. This fits

\[r_j = a + b\,x_j + c\,x_j^2\]

and reports the p-values of the linear and quadratic terms. Significance on either is evidence against the mixing assumption for that species.

Returns:

DataFrame – Per species: slope, curvature, their p-values, and a structured flag.

Parameters:

Notes

This formalises the plot Hooper (2003) asks you to inspect by eye. It is a screening tool, not a proof: with many samples, trivially small structure becomes statistically significant, so read the effect size alongside the p-value.