QGIS API Documentation
3.10.0-A Coruña (6c816b4204)
|
Calculator for summary statistics for a list of doubles. More...
#include <qgsstatisticalsummary.h>
Public Types | |
enum | Statistic { Count = 1 << 0, CountMissing = 1 << 15, Sum = 1 << 1, Mean = 1 << 2, Median = 1 << 3, StDev = 1 << 4, StDevSample = 1 << 5, Min = 1 << 6, Max = 1 << 7, Range = 1 << 8, Minority = 1 << 9, Majority = 1 << 10, Variety = 1 << 11, FirstQuartile = 1 << 12, ThirdQuartile = 1 << 13, InterQuartileRange = 1 << 14, First = 1 << 16, Last = 1 << 17, All = Count | CountMissing | Sum | Mean | Median | StDev | Max | Min | Range | Minority | Majority | Variety | FirstQuartile | ThirdQuartile | InterQuartileRange | First | Last } |
Enumeration of flags that specify statistics to be calculated. More... | |
Public Member Functions | |
QgsStatisticalSummary (QgsStatisticalSummary::Statistics stats=QgsStatisticalSummary::All) | |
Constructor for QgsStatisticalSummary. More... | |
virtual | ~QgsStatisticalSummary ()=default |
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 | first () const |
Returns the first value obtained. 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 | last () const |
Returns the last value obtained. 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 (QgsStatisticalSummary::Statistics stats) |
Sets flags which specify which statistics will be calculated. More... | |
double | statistic (QgsStatisticalSummary::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 (QgsStatisticalSummary::Statistic statistic) |
Returns the friendly display name for a statistic. More... | |
static QString | shortName (QgsStatisticalSummary::Statistic statistic) |
Returns a short, friendly display name for a statistic, suitable for use in a field name. More... | |
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().
Definition at line 43 of file qgsstatisticalsummary.h.
Enumeration of flags that specify statistics to be calculated.
Definition at line 48 of file qgsstatisticalsummary.h.
QgsStatisticalSummary::QgsStatisticalSummary | ( | QgsStatisticalSummary::Statistics | stats = QgsStatisticalSummary::All | ) |
Constructor for QgsStatisticalSummary.
stats | flags for statistics to calculate |
Definition at line 27 of file qgsstatisticalsummary.cpp.
|
virtualdefault |
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().
value | value to add |
Definition at line 84 of file qgsstatisticalsummary.cpp.
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().
value | variant containing to add. Non-numeric values are treated as null. |
Definition at line 101 of file qgsstatisticalsummary.cpp.
void QgsStatisticalSummary::calculate | ( | const QList< double > & | values | ) |
Calculates summary statistics for a list of values.
values | list of doubles |
Definition at line 72 of file qgsstatisticalsummary.cpp.
|
inline |
Returns calculated count of values.
Definition at line 160 of file qgsstatisticalsummary.h.
|
inline |
Returns the number of missing (null) values.
Definition at line 166 of file qgsstatisticalsummary.h.
|
static |
Returns the friendly display name for a statistic.
Definition at line 297 of file qgsstatisticalsummary.cpp.
void QgsStatisticalSummary::finalize | ( | ) |
Must be called after adding all values with addValues() and before retrieving any calculated statistics.
Definition at line 116 of file qgsstatisticalsummary.cpp.
|
inline |
Returns the first value obtained.
A NaN value may be returned if no values were encountered.
Definition at line 210 of file qgsstatisticalsummary.h.
|
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.
Definition at line 268 of file qgsstatisticalsummary.h.
|
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.
Definition at line 286 of file qgsstatisticalsummary.h.
|
inline |
Returns the last value obtained.
A NaN value may be returned if no values were encountered.
Definition at line 218 of file qgsstatisticalsummary.h.
|
inline |
Returns majority of values.
The majority is the value with most occurrences 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.
Definition at line 259 of file qgsstatisticalsummary.h.
|
inline |
Returns calculated maximum from values.
A NaN value may be returned if the maximum cannot be calculated.
Definition at line 196 of file qgsstatisticalsummary.h.
|
inline |
Returns calculated mean of values.
A NaN value may be returned if the mean cannot be calculated.
Definition at line 177 of file qgsstatisticalsummary.h.
|
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 184 of file qgsstatisticalsummary.h.
|
inline |
Returns calculated minimum from values.
A NaN value may be returned if the minimum cannot be calculated.
Definition at line 190 of file qgsstatisticalsummary.h.
|
inline |
Returns minority of values.
The minority is the value with least occurrences 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.
Definition at line 250 of file qgsstatisticalsummary.h.
|
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 202 of file qgsstatisticalsummary.h.
void QgsStatisticalSummary::reset | ( | ) |
Resets the calculated values.
Definition at line 39 of file qgsstatisticalsummary.cpp.
|
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.
Definition at line 234 of file qgsstatisticalsummary.h.
void QgsStatisticalSummary::setStatistics | ( | QgsStatisticalSummary::Statistics | stats | ) |
Sets flags which specify which statistics will be calculated.
Some statistics are always calculated (e.g., sum, min and max).
stats | flags for statistics to calculate |
Definition at line 33 of file qgsstatisticalsummary.cpp.
|
static |
Returns a short, friendly display name for a statistic, suitable for use in a field name.
Definition at line 343 of file qgsstatisticalsummary.cpp.
double QgsStatisticalSummary::statistic | ( | QgsStatisticalSummary::Statistic | stat | ) | const |
Returns the value of a specified statistic.
stat | statistic to return |
Definition at line 251 of file qgsstatisticalsummary.cpp.
|
inline |
Returns flags which specify which statistics will be calculated.
Some statistics are always calculated (e.g., sum, min and max).
Definition at line 85 of file qgsstatisticalsummary.h.
|
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.
Definition at line 226 of file qgsstatisticalsummary.h.
|
inline |
Returns calculated sum of values.
Definition at line 171 of file qgsstatisticalsummary.h.
|
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.
Definition at line 277 of file qgsstatisticalsummary.h.
|
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 241 of file qgsstatisticalsummary.h.