weighted_fit_variance

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

Calculate variance of a fit from the residuals of the fit to data.

For data \(y\), weights \(w\), and fitted function \(f(x) = fit(x, y, w)\), the residual is given as \(r = y - f(x)\). The variance is then given as:

\[V = \frac{1}{N - M} \frac{\sum_{i=1}^{N}{w_i r_i^2}} {\sum_{i=1}^{N}{w_i}}\]

where \(M\) = dof if \(M < N\) and \(M = N - 1\) otherwise.

Parameters:
residualsnumpy.ndarray (ndata,)

The residuals given as data - fit.

weightsnumpy.ndarray (ndata,)

The weights.

weightsumint or float, optional

The sum of weights optionally passed in for speed if pre-calculated.

rankint, optional

The degrees of freedom used in the variance calculation is taken as ndata - rank. The default is 1 and applies the Bessel correction. If ndata < rank, rank is automatically set to ndata - 1.

Returns:
variancefloat

Variance calculated from residuals.