29 : mStatistics( stats )
68 Q_FOREACH (
double value, values )
80 mMin = qMin( mMin, value );
81 mMax = qMax( mMax, value );
84 mValueCount.
insert( value, mValueCount.
value( value, 0 ) + 1 );
94 bool convertOk =
false;
99 double val = value.
toDouble( &convertOk );
111 mMin = std::numeric_limits<double>::quiet_NaN();
112 mMax = std::numeric_limits<double>::quiet_NaN();
113 mMean = std::numeric_limits<double>::quiet_NaN();
114 mMedian = std::numeric_limits<double>::quiet_NaN();
115 mStdev = std::numeric_limits<double>::quiet_NaN();
116 mSampleStdev = std::numeric_limits<double>::quiet_NaN();
117 mMinority = std::numeric_limits<double>::quiet_NaN();
118 mMajority = std::numeric_limits<double>::quiet_NaN();
119 mFirstQuartile = std::numeric_limits<double>::quiet_NaN();
120 mThirdQuartile = std::numeric_limits<double>::quiet_NaN();
124 mMean = mSum / mCount;
128 double sumSquared = 0;
129 Q_FOREACH (
double value, mValues )
131 double diff = value - mMean;
132 sumSquared += diff * diff;
134 mStdev = qPow( sumSquared / mValues.
count(), 0.5 );
135 mSampleStdev = qPow( sumSquared / ( mValues.
count() - 1 ), 0.5 );
143 qSort( mValues.
begin(), mValues.
end() );
144 bool even = ( mCount % 2 ) < 1;
147 mMedian = ( mValues[mCount / 2 - 1] + mValues[mCount / 2] ) / 2.0;
151 mMedian = mValues[( mCount + 1 ) / 2 - 1];
156 || mStatistics & QgsStatisticalSummary::InterQuartileRange )
158 if (( mCount % 2 ) < 1 )
160 int halfCount = mCount / 2;
161 bool even = ( halfCount % 2 ) < 1;
164 mFirstQuartile = ( mValues[halfCount / 2 - 1] + mValues[halfCount / 2] ) / 2.0;
168 mFirstQuartile = mValues[( halfCount + 1 ) / 2 - 1];
173 int halfCount = mCount / 2 + 1;
174 bool even = ( halfCount % 2 ) < 1;
177 mFirstQuartile = ( mValues[halfCount / 2 - 1] + mValues[halfCount / 2] ) / 2.0;
181 mFirstQuartile = mValues[( halfCount + 1 ) / 2 - 1];
187 || mStatistics & QgsStatisticalSummary::InterQuartileRange )
189 if (( mCount % 2 ) < 1 )
191 int halfCount = mCount / 2;
192 bool even = ( halfCount % 2 ) < 1;
195 mThirdQuartile = ( mValues[ halfCount + halfCount / 2 - 1] + mValues[ halfCount + halfCount / 2] ) / 2.0;
199 mThirdQuartile = mValues[( halfCount + 1 ) / 2 - 1 + halfCount ];
204 int halfCount = mCount / 2 + 1;
205 bool even = ( halfCount % 2 ) < 1;
208 mThirdQuartile = ( mValues[ halfCount + halfCount / 2 - 2 ] + mValues[ halfCount + halfCount / 2 - 1 ] ) / 2.0;
212 mThirdQuartile = mValues[( halfCount + 1 ) / 2 - 2 + halfCount ];
220 qSort( valueCounts.
begin(), valueCounts.
end() );
223 mMinority = mValueCount.
key( valueCounts.
first() );
225 if ( mStatistics & QgsStatisticalSummary::Majority )
227 mMajority = mValueCount.
key( valueCounts.
last() );
268 return mValueCount.
count();
270 return mFirstQuartile;
272 return mThirdQuartile;
274 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.
void finalize()
Must be called after adding all values with addValues() and before retrieving any calculated statisti...
void addVariant(const QVariant &value)
Adds a single value to the statistics calculation.
Sample standard deviation of values.
QgsStatisticalSummary(const QgsStatisticalSummary::Statistics &stats=All)
Constructor for QgsStatisticalSummary.
double statistic(Statistic stat) const
Returns the value of a specified statistic.
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.
Number of missing (null) values.
int count(const T &value) const
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.
double toDouble(bool *ok) const
iterator insert(const Key &key, const T &value)
Standard deviation of values.
int count(const Key &key) const
Range of values (max - min)
void addValue(double value)
Adds a single value to the statistics calculation.
const T value(const Key &key) const