solve_rchi2_from_variance

sofia_redux.toolkit.resampling.solve_rchi2_from_variance(residuals, weights, variance, weightsum=None, rank=1)[source]

Return the reduced chi-squared given residuals and constant variance.

For weights \(w\), variance \(V\), and residuals \(r\) where \(r = y - f(x)\), the reduced chi-squared is given as:

\[\chi_r^2 = \frac{1}{N - M} \frac{\sum_{i=1}^{N}{w_i r_i^2}} {V \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.

varianceint or float

The constant variance of 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.