Statistic Class Reference

Implements a class for summary statistics. More...

List of all members.

Public Member Functions

 Statistic (void)
void Add (double)
void Add (ratio)
long N (void)
double Sum (void)
double SumSq (void)
double Mean (void)
double Variance (void)
double StdDev (void)
double CV (void)
Statisticoperator+= (double v)
Statisticoperator+= (ratio r)

Friends

std::ostream & operator<< (std::ostream &, Statistic &)


Detailed Description

Implements a class for summary statistics.

The Statistic class allows easy calculation of summary statistics. When applied to ratio data the mean is the ratio of the means, and the variance is calculated from the ratio of the sums of squares. Specifically, let

\[ s = \frac{\sum_i x_{i,top}}{\sum_i x_{i,bottom}} \]

\[ ss = \frac{\sum_i x_{i,top}^2}{\sum_i x_{i,bottom}^2} \]

then Mean() returns

\[ s/n \]

and Variance() returns

\[ (ss - (s*s)/n)/(n-1) \]

Example:

 Statistic stat;
 stat.Add(1.0);
 stat.Add(2.0);
 stat.Add(3.0);
 stat.Add(4.0);
 stat.Add(5.0);
 long  n    = stat.N();    // n = 5
 double mean   = stat.Mean();   // mean = 3.000
 double variance  = stat.Variance(); // variance = 2.500
 double stddev  = stat.StdDev();  // stddev = 1.581
 double cv    = stat.CV();   // cv = 0.527

Definition at line 129 of file statistics.h.


Constructor & Destructor Documentation

Statistic::Statistic ( void   ) 

Constructor

The constructor for statistic simply initializes all internal values in preparation for calculating statistics. After initializtion, data is added with Add().

Definition at line 74 of file statistics.cpp.


Member Function Documentation

void Statistic::Add ( double  v  ) 

Add a double value to the statistic.

Parameters:
v The value to add

Definition at line 152 of file statistics.cpp.

Referenced by operator+=().

void Statistic::Add ( ratio  r  ) 

Add a ratio to the statistic.

Parameters:
r The ratio to add

Definition at line 164 of file statistics.cpp.

References ratio::Bottom(), and ratio::Top().

long Statistic::N ( void   )  [inline]

returns sample size

Definition at line 156 of file statistics.h.

Referenced by operator<<().

double Statistic::Sum ( void   )  [inline]

returns sum of sample values

Definition at line 161 of file statistics.h.

double Statistic::SumSq ( void   )  [inline]

returns sum of squared sample values

Definition at line 166 of file statistics.h.

double Statistic::Mean ( void   ) 

Returns arithmetic mean of the data.

Definition at line 118 of file statistics.cpp.

Referenced by operator<<().

double Statistic::Variance ( void   ) 

Returns variance of the data.

Definition at line 126 of file statistics.cpp.

Referenced by operator<<().

double Statistic::StdDev ( void   ) 

Returns standard deviation of the data.

Definition at line 134 of file statistics.cpp.

Referenced by operator<<().

double Statistic::CV ( void   ) 

Returns coefficient of variation of the data.

Definition at line 142 of file statistics.cpp.

Referenced by operator<<().

Statistic & Statistic::operator+= ( double  v  ) 

Add a double value to the statistic

Parameters:
v The value to add

Definition at line 177 of file statistics.cpp.

References Add().

Statistic & Statistic::operator+= ( ratio  r  ) 

Add a ratio to the statistic.

Parameters:
r The ratio to add

Definition at line 187 of file statistics.cpp.

References Add().


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  out,
Statistic st 
) [friend]

Stream output for Statistic.

Reports sample size, mean, variance, standard deviation, and coefficient of variation, each preceded by a tab and appearing on a new line.

Parameters:
out The output stream
st The statistics

Definition at line 202 of file statistics.cpp.


The documentation for this class was generated from the following files:
Generated on Tue Mar 27 16:03:51 2007 for mcmc by  doxygen 1.5.1