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) |
| Statistic & | operator+= (double v) |
| Statistic & | operator+= (ratio r) |
Friends | |
| std::ostream & | operator<< (std::ostream &, Statistic &) |
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
then Mean() returns
and Variance() returns
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.
| 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.
| void Statistic::Add | ( | double | v | ) |
Add a double value to the statistic.
| 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.
| r | The ratio to add |
Definition at line 164 of file statistics.cpp.
References ratio::Bottom(), and ratio::Top().
| long Statistic::N | ( | void | ) | [inline] |
| 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
| v | The value to add |
Definition at line 177 of file statistics.cpp.
References Add().
Add a ratio to the statistic.
| r | The ratio to add |
Definition at line 187 of file statistics.cpp.
References Add().
| 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.
| out | The output stream | |
| st | The statistics |
Definition at line 202 of file statistics.cpp.
1.5.1