29 : mStatistics( stats )
66 Q_FOREACH (
double value, values )
70 mMin = qMin( mMin, value );
71 mMax = qMax( mMax, value );
74 mValueCount.
insert( value, mValueCount.
value( value, 0 ) + 1 );
80 mMean = mSum / mCount;
84 double sumSquared = 0;
85 Q_FOREACH (
double value, values )
87 double diff = value - mMean;
88 sumSquared += diff * diff;
90 mStdev = qPow( sumSquared / values.
count(), 0.5 );
91 mSampleStdev = qPow( sumSquared / ( values.
count() - 1 ), 0.5 );
101 qSort( sorted.
begin(), sorted.
end() );
102 bool even = ( mCount % 2 ) < 1;
105 mMedian = ( sorted[mCount / 2 - 1] + sorted[mCount / 2] ) / 2.0;
109 mMedian = sorted[( mCount + 1 ) / 2 - 1];
114 || mStatistics & QgsStatisticalSummary::InterQuartileRange )
116 if (( mCount % 2 ) < 1 )
118 int halfCount = mCount / 2;
119 bool even = ( halfCount % 2 ) < 1;
122 mFirstQuartile = ( sorted[halfCount / 2 - 1] + sorted[halfCount / 2] ) / 2.0;
126 mFirstQuartile = sorted[( halfCount + 1 ) / 2 - 1];
131 int halfCount = mCount / 2 + 1;
132 bool even = ( halfCount % 2 ) < 1;
135 mFirstQuartile = ( sorted[halfCount / 2 - 1] + sorted[halfCount / 2] ) / 2.0;
139 mFirstQuartile = sorted[( halfCount + 1 ) / 2 - 1];
145 || mStatistics & QgsStatisticalSummary::InterQuartileRange )
147 if (( mCount % 2 ) < 1 )
149 int halfCount = mCount / 2;
150 bool even = ( halfCount % 2 ) < 1;
153 mThirdQuartile = ( sorted[ halfCount + halfCount / 2 - 1] + sorted[ halfCount + halfCount / 2] ) / 2.0;
157 mThirdQuartile = sorted[( halfCount + 1 ) / 2 - 1 + halfCount ];
162 int halfCount = mCount / 2 + 1;
163 bool even = ( halfCount % 2 ) < 1;
166 mThirdQuartile = ( sorted[ halfCount + halfCount / 2 - 2 ] + sorted[ halfCount + halfCount / 2 - 1 ] ) / 2.0;
170 mThirdQuartile = sorted[( halfCount + 1 ) / 2 - 2 + halfCount ];
178 qSort( valueCounts.
begin(), valueCounts.
end() );
181 mMinority = mValueCount.
key( valueCounts.
first() );
183 if ( mStatistics & QgsStatisticalSummary::Majority )
185 mMajority = mValueCount.
key( valueCounts.
last() );
224 return mValueCount.
count();
226 return mFirstQuartile;
228 return mThirdQuartile;
230 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.
QgsStatisticalSummary(const QgsStatisticalSummary::Statistics &stats=All)
Constructor for QgsStatisticalSummary.
QString tr(const char *sourceText, const char *disambiguation, int n)
double ANALYSIS_EXPORT max(double x, double y)
Returns the maximum of two doubles or the first argument if both are equal.
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
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