QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
Public Types | Public Member Functions | Static Public Member Functions | List of all members
QgsStatisticalSummary Class Reference

Calculator for summary statistics for a list of doubles. More...

#include <qgsstatisticalsummary.h>

Public Types

enum  Statistic {
  Count = 1, CountMissing = 32770, Sum = 2, Mean = 4,
  Median = 8, StDev = 16, StDevSample = 32, Min = 64,
  Max = 128, Range = 256, Minority = 512, Majority = 1024,
  Variety = 2048, FirstQuartile = 4096, ThirdQuartile = 8192, InterQuartileRange = 16384,
  All = Count | CountMissing | Sum | Mean | Median | StDev | Max | Min | Range | Minority | Majority | Variety | FirstQuartile | ThirdQuartile | InterQuartileRange
}
 Enumeration of flags that specify statistics to be calculated. More...
 

Public Member Functions

 QgsStatisticalSummary (const QgsStatisticalSummary::Statistics &stats=All)
 Constructor for QgsStatisticalSummary. More...
 
virtual ~QgsStatisticalSummary ()
 
void addValue (double value)
 Adds a single value to the statistics calculation. More...
 
void addVariant (const QVariant &value)
 Adds a single value to the statistics calculation. More...
 
void calculate (const QList< double > &values)
 Calculates summary statistics for a list of values. More...
 
int count () const
 Returns calculated count of values. More...
 
int countMissing () const
 Returns the number of missing (null) values. More...
 
void finalize ()
 Must be called after adding all values with addValues() and before retrieving any calculated statistics. More...
 
double firstQuartile () const
 Returns the first quartile of the values. More...
 
double interQuartileRange () const
 Returns the inter quartile range of the values. More...
 
double majority () const
 Returns majority of values. More...
 
double max () const
 Returns calculated maximum from values. More...
 
double mean () const
 Returns calculated mean of values. More...
 
double median () const
 Returns calculated median of values. More...
 
double min () const
 Returns calculated minimum from values. More...
 
double minority () const
 Returns minority of values. More...
 
double range () const
 Returns calculated range (difference between maximum and minimum values). More...
 
void reset ()
 Resets the calculated values. More...
 
double sampleStDev () const
 Returns sample standard deviation. More...
 
void setStatistics (const Statistics &stats)
 Sets flags which specify which statistics will be calculated. More...
 
double statistic (Statistic stat) const
 Returns the value of a specified statistic. More...
 
Statistics statistics () const
 Returns flags which specify which statistics will be calculated. More...
 
double stDev () const
 Returns population standard deviation. More...
 
double sum () const
 Returns calculated sum of values. More...
 
double thirdQuartile () const
 Returns the third quartile of the values. More...
 
int variety () const
 Returns variety of values. More...
 

Static Public Member Functions

static QString displayName (Statistic statistic)
 Returns the friendly display name for a statistic. More...
 

Detailed Description

Calculator for summary statistics for a list of doubles.

Statistics are calculated by calling calculate and passing a list of doubles. The individual statistics can then be retrieved using the associated methods. Note that not all statistics are calculated by default. Statistics which require slower computations are only calculated by specifying the statistic in the constructor or via setStatistics.

Note
Added in version 2.9

Definition at line 41 of file qgsstatisticalsummary.h.

Member Enumeration Documentation

◆ Statistic

Enumeration of flags that specify statistics to be calculated.

Enumerator
Count 

Count.

CountMissing 

Number of missing (null) values.

Sum 

Sum of values.

Mean 

Mean of values.

Median 

Median of values.

StDev 

Standard deviation of values.

StDevSample 

Sample standard deviation of values.

Min 

Min of values.

Max 

Max of values.

Range 

Range of values (max - min)

Minority 

Minority of values.

Majority 

Majority of values.

Variety 

Variety (count of distinct) values.

FirstQuartile 

First quartile.

ThirdQuartile 

Third quartile.

InterQuartileRange 

Inter quartile range (IQR)

All 

Definition at line 46 of file qgsstatisticalsummary.h.

Constructor & Destructor Documentation

◆ QgsStatisticalSummary()

QgsStatisticalSummary::QgsStatisticalSummary ( const QgsStatisticalSummary::Statistics &  stats = All)

Constructor for QgsStatisticalSummary.

Parameters
statsflags for statistics to calculate

Definition at line 28 of file qgsstatisticalsummary.cpp.

◆ ~QgsStatisticalSummary()

QgsStatisticalSummary::~QgsStatisticalSummary ( )
virtual

Definition at line 34 of file qgsstatisticalsummary.cpp.

Member Function Documentation

◆ addValue()

void QgsStatisticalSummary::addValue ( double  value)

Adds a single value to the statistics calculation.

Calling this method allows values to be added to the calculation one at a time. For large quantities of values this may be more efficient then first adding all the values to a list and calling calculate().

Parameters
valuevalue to add
Note
call reset() before adding the first value using this method to clear the results from any previous calculations
finalize() must be called after adding the final value and before retrieving calculated statistics.
See also
calculate()
addVariant()
finalize()
Note
added in QGIS 2.16

Definition at line 76 of file qgsstatisticalsummary.cpp.

◆ addVariant()

void QgsStatisticalSummary::addVariant ( const QVariant value)

Adds a single value to the statistics calculation.

Calling this method allows values to be added to the calculation one at a time. For large quantities of values this may be more efficient then first adding all the values to a list and calling calculate().

Parameters
valuevariant containing to add. Non-numeric values are treated as null.
Note
call reset() before adding the first value using this method to clear the results from any previous calculations
finalize() must be called after adding the final value and before retrieving calculated statistics.
See also
addValue()
calculate()
finalize()
Note
added in QGIS 2.16

Definition at line 92 of file qgsstatisticalsummary.cpp.

◆ calculate()

void QgsStatisticalSummary::calculate ( const QList< double > &  values)

Calculates summary statistics for a list of values.

Parameters
valueslist of doubles

Definition at line 64 of file qgsstatisticalsummary.cpp.

◆ count()

int QgsStatisticalSummary::count ( ) const
inline

Returns calculated count of values.

Definition at line 146 of file qgsstatisticalsummary.h.

◆ countMissing()

int QgsStatisticalSummary::countMissing ( ) const
inline

Returns the number of missing (null) values.

Note
added in QGIS 2.16

Definition at line 151 of file qgsstatisticalsummary.h.

◆ displayName()

QString QgsStatisticalSummary::displayName ( QgsStatisticalSummary::Statistic  statistic)
static

Returns the friendly display name for a statistic.

Parameters
statisticstatistic to return name for

Definition at line 281 of file qgsstatisticalsummary.cpp.

◆ finalize()

void QgsStatisticalSummary::finalize ( )

Must be called after adding all values with addValues() and before retrieving any calculated statistics.

See also
addValue()
addVariant()
Note
added in QGIS 2.16

Definition at line 107 of file qgsstatisticalsummary.cpp.

◆ firstQuartile()

double QgsStatisticalSummary::firstQuartile ( ) const
inline

Returns the first quartile of the values.

The quartile is calculated using the "Tukey's hinges" method. A NaN value may be returned if the first quartile cannot be calculated.

See also
thirdQuartile
interQuartileRange

Definition at line 225 of file qgsstatisticalsummary.h.

◆ interQuartileRange()

double QgsStatisticalSummary::interQuartileRange ( ) const
inline

Returns the inter quartile range of the values.

The quartiles are calculated using the "Tukey's hinges" method. A NaN value may be returned if the IQR cannot be calculated.

See also
firstQuartile
thirdQuartile

Definition at line 241 of file qgsstatisticalsummary.h.

◆ majority()

double QgsStatisticalSummary::majority ( ) const
inline

Returns majority of values.

The majority is the value with most occurances in the list This is only calculated if Statistic::Majority has been specified in the constructor or via setStatistics. A NaN value may be returned if the majority cannot be calculated.

See also
minority

Definition at line 217 of file qgsstatisticalsummary.h.

◆ max()

double QgsStatisticalSummary::max ( ) const
inline

Returns calculated maximum from values.

A NaN value may be returned if the maximum cannot be calculated.

Definition at line 176 of file qgsstatisticalsummary.h.

◆ mean()

double QgsStatisticalSummary::mean ( ) const
inline

Returns calculated mean of values.

A NaN value may be returned if the mean cannot be calculated.

Definition at line 160 of file qgsstatisticalsummary.h.

◆ median()

double QgsStatisticalSummary::median ( ) const
inline

Returns calculated median of values.

This is only calculated if Statistic::Median has been specified in the constructor or via setStatistics. A NaN value may be returned if the median cannot be calculated.

Definition at line 166 of file qgsstatisticalsummary.h.

◆ min()

double QgsStatisticalSummary::min ( ) const
inline

Returns calculated minimum from values.

A NaN value may be returned if the minimum cannot be calculated.

Definition at line 171 of file qgsstatisticalsummary.h.

◆ minority()

double QgsStatisticalSummary::minority ( ) const
inline

Returns minority of values.

The minority is the value with least occurances in the list This is only calculated if Statistic::Minority has been specified in the constructor or via setStatistics. A NaN value may be returned if the minority cannot be calculated.

See also
majority

Definition at line 209 of file qgsstatisticalsummary.h.

◆ range()

double QgsStatisticalSummary::range ( ) const
inline

Returns calculated range (difference between maximum and minimum values).

A NaN value may be returned if the range cannot be calculated.

Definition at line 181 of file qgsstatisticalsummary.h.

◆ reset()

void QgsStatisticalSummary::reset ( )

Resets the calculated values.

Definition at line 39 of file qgsstatisticalsummary.cpp.

◆ sampleStDev()

double QgsStatisticalSummary::sampleStDev ( ) const
inline

Returns sample standard deviation.

This is only calculated if Statistic::StDev has been specified in the constructor or via setStatistics. A NaN value may be returned if the standard deviation cannot be calculated.

See also
stDev

Definition at line 195 of file qgsstatisticalsummary.h.

◆ setStatistics()

void QgsStatisticalSummary::setStatistics ( const Statistics &  stats)
inline

Sets flags which specify which statistics will be calculated.

Some statistics are always calculated (eg sum, min and max).

Parameters
statsflags for statistics to calculate
See also
statistics

Definition at line 86 of file qgsstatisticalsummary.h.

◆ statistic()

double QgsStatisticalSummary::statistic ( QgsStatisticalSummary::Statistic  stat) const

Returns the value of a specified statistic.

Parameters
statstatistic to return
Returns
calculated value of statistic. A NaN value may be returned for invalid statistics.

Definition at line 239 of file qgsstatisticalsummary.cpp.

◆ statistics()

Statistics QgsStatisticalSummary::statistics ( ) const
inline

Returns flags which specify which statistics will be calculated.

Some statistics are always calculated (eg sum, min and max).

See also
setStatistics

Definition at line 79 of file qgsstatisticalsummary.h.

◆ stDev()

double QgsStatisticalSummary::stDev ( ) const
inline

Returns population standard deviation.

This is only calculated if Statistic::StDev has been specified in the constructor or via setStatistics. A NaN value may be returned if the standard deviation cannot be calculated.

See also
sampleStDev

Definition at line 188 of file qgsstatisticalsummary.h.

◆ sum()

double QgsStatisticalSummary::sum ( ) const
inline

Returns calculated sum of values.

Definition at line 155 of file qgsstatisticalsummary.h.

◆ thirdQuartile()

double QgsStatisticalSummary::thirdQuartile ( ) const
inline

Returns the third quartile of the values.

The quartile is calculated using the "Tukey's hinges" method. A NaN value may be returned if the third quartile cannot be calculated.

See also
firstQuartile
interQuartileRange

Definition at line 233 of file qgsstatisticalsummary.h.

◆ variety()

int QgsStatisticalSummary::variety ( ) const
inline

Returns variety of values.

The variety is the count of unique values from the list. This is only calculated if Statistic::Variety has been specified in the constructor or via setStatistics.

Definition at line 201 of file qgsstatisticalsummary.h.


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