yat  0.14.5pre
Public Member Functions | Related Functions | List of all members
theplu::yat::statistics::AveragerWeighted Class Reference

Class to calulate averages with weights. More...

#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. More...
 
double n (void) const
 Weighted version of number of data points. More...
 
void rescale (double a)
 Rescale object. More...
 
void reset (void)
 Reset everything to zero.
 
double std (void) const
 The standard deviation is defined as the square root of the variance(). More...
 
double standard_error (void) const
 Calculates standard deviation of the mean(). More...
 
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 AveragerWeightedoperator+= (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 More...
 
template<typename InputIterator1 , typename InputIterator2 >
void add (AveragerWeighted &a, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2)
 add values from two ranges to AveragerWeighted a More...
 

Detailed Description

Class to calulate averages with weights.

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 $ \sigma_i^2 = \frac{\sigma^2}{w_i} $. 2) Probability weights are used for the situation when calculating averages over a distribution $ f $ , but sampling from a distribution $ f' $. Compensating for this discrepancy averages of observables are taken to be $ \sum \frac{f}{f'}X $ For further discussion: see Weighted Statistics

If nothing else stated, each function fulfills the following:

See Also
Averager AveragerPair AveragerPairWeighted

Member Function Documentation

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.

Returns
$ \frac{\sum w_ix_i}{\sum w_i} $
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.

Returns
$ \frac{\left(\sum w_i\right)^2}{\sum w_i^2} $
const AveragerWeighted& theplu::yat::statistics::AveragerWeighted::operator+= ( const AveragerWeighted )

operator to add an AveragerWeighted

Since
New in yat 0.6
void theplu::yat::statistics::AveragerWeighted::rescale ( double  a)

Rescale object.

Each data point is rescaled as $ x = a * x $

double theplu::yat::statistics::AveragerWeighted::standard_error ( void  ) const

Calculates standard deviation of the mean().

Variance from the weights are here neglected. This is true when the weight is known before the measurement. In case this is not a good approximation, use bootstrapping to estimate the error.

Returns
$ \frac{\sum w^2}{\left(\sum w\right)^3}\sum w(x-m)^2 $ where $ m $ is the mean()
double theplu::yat::statistics::AveragerWeighted::std ( void  ) const

The standard deviation is defined as the square root of the variance().

Returns
The standard deviation, root of the variance().
double theplu::yat::statistics::AveragerWeighted::sum_w ( void  ) const

Calculating the sum of weights

Returns
$ \sum w_i $
double theplu::yat::statistics::AveragerWeighted::sum_ww ( void  ) const
Returns
$ \sum w_i^2 $
double theplu::yat::statistics::AveragerWeighted::sum_wx ( void  ) const

$ \sum w_ix_i $

Returns
weighted sum of x
double theplu::yat::statistics::AveragerWeighted::sum_wxx ( void  ) const
Returns
$ \sum w_i x_i^2 $
double theplu::yat::statistics::AveragerWeighted::sum_xx_centered ( void  ) const
Returns
$ \sum_i w_i (x_i-m)^2$
double theplu::yat::statistics::AveragerWeighted::variance ( const double  m) const

The variance is calculated as $ \frac{\sum w_i (x_i - m)^2 }{\sum w_i} $, where m is the known mean.

Returns
Variance when the mean is known to be m.
double theplu::yat::statistics::AveragerWeighted::variance ( void  ) const

The variance is calculated as $ \frac{\sum w_i (x_i - m)^2 }{\sum w_i} $, 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.

Returns
The variance.

Friends And Related Function Documentation

template<typename InputIterator >
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.

Type Requirement:

template<typename InputIterator1 , typename InputIterator2 >
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) ).

Type Requirement:


The documentation for this class was generated from the following file:

Generated on Tue Sep 26 2017 02:33:30 for yat by  doxygen 1.8.5