solve_mean_fit

sofia_redux.toolkit.resampling.solve_mean_fit(data, error, weight, weightsum=None, calculate_variance=True, calculate_rchi2=True)[source]

Return the weighted mean of data, variance, and reduced chi-squared.

For data (\(y\)), error (\(\sigma\)), and weights (\(w\)), the weighted mean is given as:

\[\bar{y} = \frac{\sum_{i=1}^{N}{w_i y_i}} {\sum_{i=1}^{N}{w_i}}\]

The returned variance (\(V\)) will depend on use_error. If use_error is True:

\[V = \frac{\sum_{i=1}^{N}{(w_i\sigma_i)^2}}{(\sum_{i=1}^{N}{w_i})^2}\]

If use_error is False:

\[V = \frac{1}{N - 1} \frac{\sum_{i=1}^{N}{w_i (y_i - \bar{y})^2}} {\sum_{i=1}^{N}{w_i}}\]

Finally, the reduced chi-squared statistic is given as:

\[\chi_r^2 = \frac{N}{N - 1} \frac{\sum_{i=1}^{N}{w_i (y_i - \bar{y})^2 / \sigma_i^2}} {\sum_{i=1}^{N}{w_i}}\]

Note that \(\chi_r^2 = 1\) is use_error is False.

Parameters:
datanumpy.ndarray (N,)

The data array consisting of N samples.

errornumpy.ndarray (N,)

The associated 1-sigma error values for each of the N data samples.

weightnumpy.ndarray (N,)

The weighting applied to each of the N data samples.

weightsumint or float, optional

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

calculate_variancebool, optional

If True, calculate the variance. Otherwise, variance will be returned as a float value of zero.

calculate_rchi2bool, optional

If True, calculate the reduced chi-squared statistic. Otherwise, it will be returned as a float value of zero.

Returns:
mean, variance, rchi2float, float, float

The weighted mean, variance and reduced chi-squared statistic.