imap_processing.idex.idex_l2a.chi_square#
- imap_processing.idex.idex_l2a.chi_square(observed: ndarray, expected: ndarray, num_params: int) tuple[float, float]#
Calculate the chi-square and reduced chi-square statistics.
This implementation follows the approach used in lmfit.minimize()’s _calculate_statistics() method, which calculates chi-square as the sum of squared residuals:
chisqr = (residual**2).sum()
And reduced chi-square as the chi-square divided by degrees of freedom:
ndata = len(residual) nfree = ndata - number_of_parameters redchi = chisqr / max(1, nfree)
- Parameters:
observed (numpy.ndarray) – The observed signal.
expected (numpy.ndarray) – The expected signal calculated with the fit parameters.
num_params (int) – The number of parameters used in the fit.
- Returns:
chisqr (float) – The chi-square value.
redchi (float) – The reduced chi-square value.