Loading [MathJax]/extensions/ams.js
ALMaSS  1.2 (after EcoStack, March 2024)
The Animal, Landscape and Man Simulation System
All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SimpleStatistics Class Reference

#include <PopulationManager.h>

Public Member Functions

 SimpleStatistics ()=default
 SimpleStatistics constructor. More...
 
void add_variable (double x)
 Add a value. More...
 
void remove_variable (double x)
 Remove a value. More...
 
double get_N () const
 Returns the number of values. More...
 
double get_Total () const
 Returns the mean. More...
 
double get_meanvalue () const
 Returns the mean. More...
 
double get_varianceP ()
 Returns the population variance. More...
 
double get_varianceS ()
 Returns the sample variance. More...
 
double get_SD ()
 Returns the sample standard deviation. More...
 
double get_SE ()
 Returns the sample standard error. More...
 
void ClearData ()
 Clears the data. More...
 

Protected Attributes

double m_K {0}
 
double m_n {0}
 
double m_Sum {0}
 
double m_SumX {0}
 
double m_SumX2 {0}
 

Constructor & Destructor Documentation

◆ SimpleStatistics()

SimpleStatistics::SimpleStatistics ( )
default

SimpleStatistics constructor.

Member Function Documentation

◆ add_variable()

void SimpleStatistics::add_variable ( double  x)
inline

Add a value.

480  {
481  // This uses the computing shifted data equation.
482  if (m_n < 1) m_K = x;
483  m_n++;
484  m_Sum += x;
485  m_SumX += x - m_K;
486  m_SumX2 += (x - m_K) * (x - m_K);
487  }

References m_K, m_n, m_Sum, m_SumX, and m_SumX2.

◆ ClearData()

void SimpleStatistics::ClearData ( )
inline

Clears the data.

537  {
538  m_K = 0;
539  m_n = 0;
540  m_Sum = 0;
541  m_SumX = 0;
542  m_SumX2 = 0;
543  }

References m_K, m_n, m_Sum, m_SumX, and m_SumX2.

Referenced by Osmia_Population_Manager::DoLast().

◆ get_meanvalue()

double SimpleStatistics::get_meanvalue ( ) const
inline

Returns the mean.

500  {
501  if (m_n < 1) return -1;
502  return m_K + m_SumX / m_n;
503  }

References m_K, m_n, and m_SumX.

Referenced by Osmia_Population_Manager::DoLast().

◆ get_N()

double SimpleStatistics::get_N ( ) const
inline

Returns the number of values.

496 { return m_n; }

References m_n.

Referenced by get_SE().

◆ get_SD()

double SimpleStatistics::get_SD ( )
inline

Returns the sample standard deviation.

521  {
522  if (m_n < 2)
523  {
524  return -1; // Ilegal n value, but don't want to exit
525  }
526  return sqrt(get_varianceS());
527  }

References get_varianceS(), and m_n.

◆ get_SE()

double SimpleStatistics::get_SE ( )
inline

Returns the sample standard error.

529  {
530  if (m_n < 2)
531  {
532  return -1; // Ilegal n value, but don't want to exit
533  }
534  return sqrt(get_varianceS() / get_N());
535  }

References get_N(), get_varianceS(), and m_n.

◆ get_Total()

double SimpleStatistics::get_Total ( ) const
inline

Returns the mean.

498 { return m_Sum; }

References m_Sum.

◆ get_varianceP()

double SimpleStatistics::get_varianceP ( )
inline

Returns the population variance.

505  {
506  if (m_n < 2)
507  {
508  return -1; // Ilegal n value, but don't want to exit
509  }
510  return (m_SumX2 - m_SumX * m_SumX / m_n) / m_n;
511  }

References m_n, m_SumX, and m_SumX2.

◆ get_varianceS()

double SimpleStatistics::get_varianceS ( )
inline

Returns the sample variance.

513  {
514  if (m_n < 2)
515  {
516  return -1; // Ilegal n value, but don't want to exit
517  }
518  return (m_SumX2 - m_SumX * m_SumX / m_n) / (m_n - 1);
519  }

References m_n, m_SumX, and m_SumX2.

Referenced by get_SD(), and get_SE().

◆ remove_variable()

void SimpleStatistics::remove_variable ( double  x)
inline

Remove a value.

489  {
490  m_n--;
491  m_Sum -= x;
492  m_SumX -= x - m_K;
493  m_SumX2 -= (x - m_K) * (x - m_K);
494  }

References m_K, m_n, m_Sum, m_SumX, and m_SumX2.

Member Data Documentation

◆ m_K

double SimpleStatistics::m_K {0}
protected

This class is designed to provide the facility to create simple stats from data that comes in incrementally. It can provide the mean, variance of the data set at any point in time

Referenced by add_variable(), ClearData(), get_meanvalue(), and remove_variable().

◆ m_n

double SimpleStatistics::m_n {0}
protected

◆ m_Sum

double SimpleStatistics::m_Sum {0}
protected

◆ m_SumX

double SimpleStatistics::m_SumX {0}
protected

◆ m_SumX2

double SimpleStatistics::m_SumX2 {0}
protected

The documentation for this class was generated from the following file:
SimpleStatistics::m_Sum
double m_Sum
Definition: PopulationManager.h:472
SimpleStatistics::m_K
double m_K
Definition: PopulationManager.h:470
SimpleStatistics::m_SumX2
double m_SumX2
Definition: PopulationManager.h:474
SimpleStatistics::get_varianceS
double get_varianceS()
Returns the sample variance.
Definition: PopulationManager.h:513
SimpleStatistics::m_n
double m_n
Definition: PopulationManager.h:471
SimpleStatistics::get_N
double get_N() const
Returns the number of values.
Definition: PopulationManager.h:496
SimpleStatistics::m_SumX
double m_SumX
Definition: PopulationManager.h:473