solve_rchi2_from_error¶
- sofia_redux.toolkit.resampling.solve_rchi2_from_error(residuals, weights, errors, weightsum=None, rank=1)[source]¶
Return the reduced chi-squared given residuals and sample errors.
For
weights
\(w\),errors
\(\sigma\), and residuals \(r\) where \(r = y - f(x)\), the reduced chi-squared is given as:\[\chi_r^2 = \frac{N}{N - M} \frac{\sum_{i=1}^{N}{w_i r_i^2 / \sigma_i^2}} {\sum_{i=1}^{N}{w_i}}\]where \(M\) is given by
rank
.- Parameters:
- residualsnumpy.ndarray (N,)
The residuals to the fit, or y - f(x).
- weightsnumpy.ndarray (N,)
The weights to each sample in the fit.
- errorsnumpy.ndarray (N,)
The 1-sigma measurement errors for each sample in the fit.
- weightsumint or float, optional
The sum of the sample weights, optionally passed in for speed.
- rankint or float, optional
The degrees of freedom used in the reduced chi-squared value is taken as N - rank. The default is 1 and applies the Bessel correction. If N < rank, rank is automatically set to N - 1.
- Returns:
- rchi2float
The reduced chi-squared value for the fit.