Statistics
Calculates the statistics for a set of data that may change size frequently.
You're viewing an older version of this page (#108). View the current version.
Interface
#include <codecogs/statistics/moments/statistics.h>
using namespace Statistics::Moments;
Statistics() : m_n(size), m_calc(false), m_total(0), m_total1(0), m_total2(0), m_total3(0), m_total4(0), m_prod(1)Statistics(int size, T *data)void add(T x)void calcStats()void print()inline double getTotal()inline double getMean()inline double getGeometricMean()inline double getHarmonicMean()inline double getVariance()inline double getStdev()inline double getSkewness()inline double getKurtosis()inline double getCV()inline int getSize()Statistics& operator+(const Statistics &B)
Overview
This class allows the calculation of key statistics for a set of data that may change its size frequently. The main advantage of this class is the ability of updating the key statistics while storing minimum information about previous data into a set of main variables given below, rather than storing the actual data. Based on the next main variables, that are recalculated with each new value that is added to the population,
it calculates the statistics using the following formulas
where mean is the arithmetic mean, geomean is the geometric mean, harmean is the harmonic mean,var </em> is the variance and stdev is the standard deviation. The skewness and kurtosis are calculated using similar formulas.
References
Example 1
#include <codecogs/statistics/moments/statistics.h>
#include <iostream>
int main()
{
double a[15];
for (int i = 0; i < 15; i++)
a[i]=i+1;
a[1]=5;
Stats::Moments::Statistics<double> stats(15, a);
stats.print();
return 0;
}Output:
Total = 123.0000000000
Arithmetic Mean = 8.2000000000
Geometric Mean = 6.8280387111
Harmonic Mean = 4.9698018386
Variance = 18.0285714286
Standard Deviation = 4.2460065271
Skewness = 0.0403100873
Kurtosis = -1.0487842858Members of Statistics
CLASS METHOD
Statistics
Default constructor which resets all variables
CLASS METHOD
Statistics
This constructor takes an array as input, which is analyzes to compute the various statistical parameters
Parameters
CLASS METHOD
add
This function adds a new value to the statistical collection. Additional values are appended in constant time very quickly, enabling you to call this function thousands of times in quick succession with no penalty.
Parameters
CLASS METHOD
calcStats
One this class is loaded with the values that you want analysed, this function must be run to compute the final values such as mean, variance etc. This function need only be run once before all statistics can be retrieved.
CLASS METHOD
Calculates and prints the key statistics of the current population.
CLASS METHOD
getTotal
CLASS METHOD
getMean
CLASS METHOD
getGeometricMean
CLASS METHOD
getHarmonicMean
CLASS METHOD
getVariance
CLASS METHOD
getStdev
CLASS METHOD
getSkewness
CLASS METHOD
getKurtosis
CLASS METHOD
getCV
CLASS METHOD
getSize
Calculates the size of the set of data.
CLASS METHOD
operator+
Combines the statistics from two independent Statistics objects. This is equivalent to having added all the data to just one container, with all the statistical measures maintained accurately. i.e
Stats::Moments::Statistics<double> A(15, somearray_a);
Stats::Moments::Statistics<double> B(51, somearray_b);
//This contains the combined statistics
Stats::Moments::Statistics<double> C = A+B;