macro_rules! assert_residuals_normal {
($fit:expr $(, strict = $strict:expr)?) => { ... };
($fit:expr, $tolerance:expr $(, strict = $strict:expr)? $(, $msg:literal $(, $($args:tt),*)?)?) => { ... };
}Expand description
Asserts that the residuals (the differences between the observed and predicted values) of a fit are normally distributed.
This means the errors are likely random, not based on some undiscovered pattern.
See crate::statistics::residual_normality for more details.
- Results will be between 0.0 and 1.0, with values closer to 1.0 indicating a better fit.
§Parameters
$fit: A reference to theCurveFitobject whose residuals will be tested.$tolerance: Minimum p-value for normality. Defaults to0.1if omitted.strict: (optional) If true, uses unfiltered residuals. Defaults to false. Use strict mode if you want to include all residuals, even those close to zero. Normally, small residuals are due to floating-point noise and are filtered out.
§Behavior
- Computes mean, standard deviation, skewness, and excess kurtosis of residuals.
- If p-value <
$tolerance, the macro will:- Optionally generate a failure plot (if the
plottingfeature is enabled). - Panic with a clear error message indicating skew/kurtosis values.
- Optionally generate a failure plot (if the
§Example
function!(test(x) = 20.0 + 3.0 x^1 + 2.0 x^2 + 4.0 x^3 );
let data = test.solve_range(0.0..=1000.0, 1.0);
let fit = ChebyshevFit::new_auto(&data, DegreeBound::Relaxed, &Aic).expect("Failed to create model");
// Uses default tolerance 0.1
assert_residuals_normal!(fit);
// Strict mode uses unfiltered residuals - even floating point noise can cause failure
assert_residuals_normal!(fit, 0.00, strict = true);