Subversion Repositories public iLand

Rev

Rev 1221 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1211 werner 1
/********************************************************************************************
2
**    iLand - an individual based forest landscape and disturbance model
3
**    http://iland.boku.ac.at
4
**    Copyright (C) 2009-  Werner Rammer, Rupert Seidl
5
**
6
**    This program is free software: you can redistribute it and/or modify
7
**    it under the terms of the GNU General Public License as published by
8
**    the Free Software Foundation, either version 3 of the License, or
9
**    (at your option) any later version.
10
**
11
**    This program is distributed in the hope that it will be useful,
12
**    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
**    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
**    GNU General Public License for more details.
15
**
16
**    You should have received a copy of the GNU General Public License
17
**    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
********************************************************************************************/
808 werner 19
#ifndef STATDATA_H
20
#define STATDATA_H
21
 
22
/** StatData.
23
* Helper class for statistics. This class calculates
24
* from a double-vector relevant information used
25
* for BoxPlots. */
26
class StatData
27
{
28
public:
29
    StatData() { calculate(); }
30
    StatData(QVector<double> &data);
31
    void setData(QVector<double> &data) { mData=data; calculate(); }
32
    void calculate();
33
    // getters
34
    double sum() const { return mSum; } ///< sum of values
35
    double mean() const { return mMean; } ///< arithmetic mean
36
    double min() const { return mMin; } ///< minimum value
37
    double max() const { return mMax; } ///< maximum value
38
    double median() const { if (mP25==std::numeric_limits<double>::max()) calculatePercentiles(); return mMedian; } ///< 2nd quartil = median
39
    double percentile25() const { if (mP25==std::numeric_limits<double>::max()) calculatePercentiles(); return mP25; } ///< 1st quartil
40
    double percentile75() const { if (mP25==std::numeric_limits<double>::max()) calculatePercentiles(); return mP75; } ///< 3rd quartil
1059 werner 41
    double percentile(const int percent) const; ///< get value of a given percentile (0..100)
808 werner 42
    double standardDev() const { if (mSD==std::numeric_limits<double>::max()) calculateSD(); return mSD; } ///< get the standard deviation (of the population)
43
    // additional functions
44
    static QVector<int> calculateRanks(const QVector<double> &data, bool descending=false); ///< rank data.
45
    static void normalize(QVector<double> &data, double targetSum); ///< normalize, i.e. the sum of all items after processing is targetSum
46
private:
47
    double calculateSD() const;
48
    mutable QVector<double> mData; // mutable to allow late calculation of percentiles (e.g. a call to "median()".)
49
    double mSum;
50
    double mMean;
51
    double mMin;
52
    double mMax;
53
    mutable double mP25;
54
    mutable double mP75;
55
    mutable double mMedian;
56
    mutable double mSD; // standard deviation
57
    void calculatePercentiles() const;
58
};
59
 
60
 
61
#endif // STATDATA_H