satlas.utilities.utilities.weighted_average

satlas.utilities.utilities.weighted_average(x, sigma, axis=None)[source]

Takes the weighted average of an array of values and the associated errors. Calculates the scatter and statistical error, and returns the greater of these two values.

Parameters:
  • x (array_like) – Array-like assortment of measured values, is transformed into a 1D-array.
  • sigma (array_like) – Array-like assortment of errors on the measured values, is transformed into a 1D-array.
Returns:

Returns a tuple (weighted_average, uncertainty), with the uncertainty being the greater of the uncertainty calculated from the statistical uncertainty and the scattering uncertainty.

Return type:

tuple

Note

The formulas used are

\left\langle x\right\rangle_{weighted} &= \frac{\sum_{i=1}^N \frac{x_i}
                                                         {\sigma_i^2}}
                                              {\sum_{i=1}^N \frac{1}
                                                        {\sigma_i^2}}

\sigma_{stat}^2 &= \frac{1}{\sum_{i=1}^N \frac{1}{\sigma_i^2}}

\sigma_{scatter}^2 &= \frac{\sum_{i=1}^N \left(\frac{x_i-\left\langle
                                            x\right\rangle_{weighted}}
                                              {\sigma_i}\right)^2}
       {\left(N-1\right)\sum_{i=1}^N \frac{1}{\sigma_i^2}}