23 : mStatistics( stats )
54 foreach (
double value, values )
58 mMin = qMin( mMin, value );
59 mMax = qMax( mMax, value );
62 mValueCount.
insert( value, mValueCount.
value( value, 0 ) + 1 );
68 mMean = mSum / mCount;
72 double sumSquared = 0;
73 foreach (
double value, values )
75 double diff = value - mMean;
76 sumSquared += diff * diff;
78 mStdev = qPow( sumSquared / values.
count(), 0.5 );
79 mSampleStdev = qPow( sumSquared / ( values.
count() - 1 ), 0.5 );
89 qSort( sorted.
begin(), sorted.
end() );
90 bool even = ( mCount % 2 ) < 1;
93 mMedian = ( sorted[mCount / 2 - 1] + sorted[mCount / 2] ) / 2.0;
97 mMedian = sorted[( mCount + 1 ) / 2 - 1];
102 || mStatistics & QgsStatisticalSummary::InterQuartileRange )
104 if (( mCount % 2 ) < 1 )
106 int halfCount = mCount / 2;
107 bool even = ( halfCount % 2 ) < 1;
110 mFirstQuartile = ( sorted[halfCount / 2 - 1] + sorted[halfCount / 2] ) / 2.0;
114 mFirstQuartile = sorted[( halfCount + 1 ) / 2 - 1];
119 int halfCount = mCount / 2 + 1;
120 bool even = ( halfCount % 2 ) < 1;
123 mFirstQuartile = ( sorted[halfCount / 2 - 1] + sorted[halfCount / 2] ) / 2.0;
127 mFirstQuartile = sorted[( halfCount + 1 ) / 2 - 1];
133 || mStatistics & QgsStatisticalSummary::InterQuartileRange )
135 if (( mCount % 2 ) < 1 )
137 int halfCount = mCount / 2;
138 bool even = ( halfCount % 2 ) < 1;
141 mThirdQuartile = ( sorted[ halfCount + halfCount / 2 - 1] + sorted[ halfCount + halfCount / 2] ) / 2.0;
145 mThirdQuartile = sorted[( halfCount + 1 ) / 2 - 1 + halfCount ];
150 int halfCount = mCount / 2 + 1;
151 bool even = ( halfCount % 2 ) < 1;
154 mThirdQuartile = ( sorted[ halfCount + halfCount / 2 - 2 ] + sorted[ halfCount + halfCount / 2 - 1 ] ) / 2.0;
158 mThirdQuartile = sorted[( halfCount + 1 ) / 2 - 2 + halfCount ];
166 qSort( valueCounts.
begin(), valueCounts.
end() );
169 mMinority = mValueCount.
key( valueCounts.
first() );
171 if ( mStatistics & QgsStatisticalSummary::Majority )
173 mMajority = mValueCount.
key( valueCounts.
last() );
206 return mValueCount.
count();
208 return mFirstQuartile;
210 return mThirdQuartile;
212 return mThirdQuartile - mFirstQuartile;
void reset()
Resets the calculated values.
virtual ~QgsStatisticalSummary()
QList< T > values() const
Statistic
Enumeration of flags that specify statistics to be calculated.
Variety (count of distinct) values.
Sample standard deviation of values.
QString tr(const char *sourceText, const char *disambiguation, int n)
int count(const T &value) const
double statistic(Statistic stat) const
Returns the value of a specified statistic.
Inter quartile range (IQR)
static QString displayName(Statistic statistic)
Returns the friendly display name for a statistic.
const Key key(const T &value) const
QgsStatisticalSummary(Statistics stats=Statistics(0))
Constructor for QgsStatisticalSummary.
void calculate(const QList< double > &values)
Calculates summary statistics for a list of values.
iterator insert(const Key &key, const T &value)
Standard deviation of values.
int count(const Key &key) const
Range of values (max - min)
const T value(const Key &key) const