#include <yat/statistics/AveragerWeighted.h>
Public Member Functions | |
AveragerWeighted (void) | |
The default constructor. | |
AveragerWeighted (const AveragerWeighted &) | |
The copy constructor. | |
void | add (const double d, const double w=1) |
double | mean (void) const |
Calculate the weighted mean. | |
double | n (void) const |
Weighted version of number of data points. | |
void | rescale (double a) |
Rescale object. | |
void | reset (void) |
Reset everything to zero. | |
double | std (void) const |
The standard deviation is defined as the square root of the variance(). | |
double | standard_error (void) const |
Calculates standard deviation of the mean(). | |
double | sum_w (void) const |
double | sum_ww (void) const |
double | sum_wx (void) const |
double | sum_wxx (void) const |
double | sum_xx_centered (void) const |
double | variance (const double m) const |
double | variance (void) const |
const AveragerWeighted & | operator+= (const AveragerWeighted &) |
Related Functions | |
(Note that these are not member functions.) | |
template<typename InputIterator > | |
void | add (AveragerWeighted &a, InputIterator first, InputIterator last) |
adding a range of values to AveragerWeighted a | |
template<typename InputIterator1 , typename InputIterator2 > | |
void | add (AveragerWeighted &a, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2) |
add values from two ranges to AveragerWeighted a |
There are several different reasons why a statistical analysis needs to adjust for weighting. In the litterature reasons are mainly divided into two kinds of weights - probablity weights and analytical weights. 1) Analytical weights are appropriate for scientific experiments where some measurements are known to be more precise than others. The larger weight a measurement has the more precise is is assumed to be, or more formally the weight is proportional to the reciprocal variance . 2) Probability weights are used for the situation when calculating averages over a distribution , but sampling from a distribution . Compensating for this discrepancy averages of observables are taken to be For further discussion: see Weighted Statistics
If nothing else stated, each function fulfills the following:
void theplu::yat::statistics::AveragerWeighted::add | ( | const double | d, | |
const double | w = 1 | |||
) |
Adding a data point d, with weight w (default is 1)
double theplu::yat::statistics::AveragerWeighted::mean | ( | void | ) | const |
Calculate the weighted mean.
double theplu::yat::statistics::AveragerWeighted::n | ( | void | ) | const |
Weighted version of number of data points.
If all weights are equal, the unweighted version is identical to the non-weighted version. Adding a data point with zero weight does not change n(). The calculated value is always smaller than the actual number of data points added to object.
const AveragerWeighted& theplu::yat::statistics::AveragerWeighted::operator+= | ( | const AveragerWeighted & | ) |
void theplu::yat::statistics::AveragerWeighted::rescale | ( | double | a | ) |
Rescale object.
Each data point is rescaled as
double theplu::yat::statistics::AveragerWeighted::standard_error | ( | void | ) | const |
double theplu::yat::statistics::AveragerWeighted::std | ( | void | ) | const |
The standard deviation is defined as the square root of the variance().
double theplu::yat::statistics::AveragerWeighted::sum_w | ( | void | ) | const |
Calculating the sum of weights
double theplu::yat::statistics::AveragerWeighted::sum_ww | ( | void | ) | const |
double theplu::yat::statistics::AveragerWeighted::sum_wx | ( | void | ) | const |
double theplu::yat::statistics::AveragerWeighted::sum_wxx | ( | void | ) | const |
double theplu::yat::statistics::AveragerWeighted::sum_xx_centered | ( | void | ) | const |
double theplu::yat::statistics::AveragerWeighted::variance | ( | void | ) | const |
The variance is calculated as , where m is the mean(). Here the weight are interpreted as probability weights. For analytical weights the variance has no meaning as each data point has its own variance.
double theplu::yat::statistics::AveragerWeighted::variance | ( | const double | m | ) | const |
The variance is calculated as , where m is the known mean.
void add | ( | AveragerWeighted & | a, | |
InputIterator1 | first1, | |||
InputIterator1 | last1, | |||
InputIterator2 | first2 | |||
) | [related] |
add values from two ranges to AveragerWeighted a
Add data from range [first1, last1) with their corresponding weight in range [first2, first2 + distance(first, last) ).
Requirement: InputIterator1 and InputIterator2 are unweighted input iterators.
void add | ( | AveragerWeighted & | a, | |
InputIterator | first, | |||
InputIterator | last | |||
) | [related] |
adding a range of values to AveragerWeighted a
If InputIterator is non-weighted unitary weights are used.