4114 |
13 Oct 21 |
peter |
1 |
#ifndef _theplu_yat_statistics_anova_ |
4114 |
13 Oct 21 |
peter |
2 |
#define _theplu_yat_statistics_anova_ |
4114 |
13 Oct 21 |
peter |
3 |
|
4114 |
13 Oct 21 |
peter |
// $Id$ |
4114 |
13 Oct 21 |
peter |
5 |
|
4114 |
13 Oct 21 |
peter |
6 |
/* |
4114 |
13 Oct 21 |
peter |
Copyright (C) 2021 Peter Johansson |
4114 |
13 Oct 21 |
peter |
8 |
|
4114 |
13 Oct 21 |
peter |
This file is part of the yat library, https://dev.thep.lu.se/yat |
4114 |
13 Oct 21 |
peter |
10 |
|
4114 |
13 Oct 21 |
peter |
The yat library is free software; you can redistribute it and/or |
4114 |
13 Oct 21 |
peter |
modify it under the terms of the GNU General Public License as |
4114 |
13 Oct 21 |
peter |
published by the Free Software Foundation; either version 3 of the |
4114 |
13 Oct 21 |
peter |
License, or (at your option) any later version. |
4114 |
13 Oct 21 |
peter |
15 |
|
4114 |
13 Oct 21 |
peter |
The yat library is distributed in the hope that it will be useful, |
4114 |
13 Oct 21 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
4114 |
13 Oct 21 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4114 |
13 Oct 21 |
peter |
General Public License for more details. |
4114 |
13 Oct 21 |
peter |
20 |
|
4114 |
13 Oct 21 |
peter |
You should have received a copy of the GNU General Public License |
4114 |
13 Oct 21 |
peter |
along with yat. If not, see <https://www.gnu.org/licenses/>. |
4114 |
13 Oct 21 |
peter |
23 |
*/ |
4114 |
13 Oct 21 |
peter |
24 |
|
4114 |
13 Oct 21 |
peter |
25 |
#include <yat/statistics/Averager.h> |
4114 |
13 Oct 21 |
peter |
26 |
|
4114 |
13 Oct 21 |
peter |
27 |
#include <cstddef> |
4114 |
13 Oct 21 |
peter |
28 |
#include <vector> |
4114 |
13 Oct 21 |
peter |
29 |
|
4114 |
13 Oct 21 |
peter |
30 |
namespace theplu { |
4114 |
13 Oct 21 |
peter |
31 |
namespace yat { |
4114 |
13 Oct 21 |
peter |
32 |
namespace statistics { |
4114 |
13 Oct 21 |
peter |
33 |
|
4114 |
13 Oct 21 |
peter |
34 |
/** |
4114 |
13 Oct 21 |
peter |
\brief one-way ANOVA |
4114 |
13 Oct 21 |
peter |
36 |
|
4114 |
13 Oct 21 |
peter |
One-way Analysis of Variance is an extension of a t-test to |
4114 |
13 Oct 21 |
peter |
compare also more than two groups. |
4114 |
13 Oct 21 |
peter |
39 |
|
4114 |
13 Oct 21 |
peter |
\since New in yat 0.20 |
4114 |
13 Oct 21 |
peter |
41 |
*/ |
4114 |
13 Oct 21 |
peter |
42 |
class Anova |
4114 |
13 Oct 21 |
peter |
43 |
{ |
4114 |
13 Oct 21 |
peter |
44 |
public: |
4114 |
13 Oct 21 |
peter |
45 |
/** |
4114 |
13 Oct 21 |
peter |
\param n number of groups compared |
4114 |
13 Oct 21 |
peter |
47 |
*/ |
4114 |
13 Oct 21 |
peter |
48 |
Anova(size_t n); |
4114 |
13 Oct 21 |
peter |
49 |
|
4114 |
13 Oct 21 |
peter |
50 |
/** |
4114 |
13 Oct 21 |
peter |
\brief add a data point |
4114 |
13 Oct 21 |
peter |
52 |
|
4114 |
13 Oct 21 |
peter |
\param x value of data point |
4114 |
13 Oct 21 |
peter |
\param g group the data belongs to |
4114 |
13 Oct 21 |
peter |
\param n number of data points |
4114 |
13 Oct 21 |
peter |
56 |
*/ |
4114 |
13 Oct 21 |
peter |
57 |
void add(double x, size_t g, long int n=1); |
4114 |
13 Oct 21 |
peter |
58 |
|
4114 |
13 Oct 21 |
peter |
59 |
/** |
4114 |
13 Oct 21 |
peter |
F is calculated as the ratio between within-group variance and |
4114 |
13 Oct 21 |
peter |
between-group variance. |
4114 |
13 Oct 21 |
peter |
62 |
|
4114 |
13 Oct 21 |
peter |
\f$ \frac |
4114 |
13 Oct 21 |
peter |
{\frac{1}{G-1} \sum_g^G n_g (m_g - m)^2} |
4114 |
13 Oct 21 |
peter |
{\frac{1}{N-G} \sum_{g,i}^{G, n_G} (x_{g,i}-m_g)^2} |
4114 |
13 Oct 21 |
peter |
\f$ |
4114 |
13 Oct 21 |
peter |
67 |
|
4114 |
13 Oct 21 |
peter |
If null hypothesis is true, F follows an F(a,b) distribution |
4114 |
13 Oct 21 |
peter |
where a is inter_df() and b is intra_df. |
4114 |
13 Oct 21 |
peter |
70 |
*/ |
4114 |
13 Oct 21 |
peter |
71 |
double F(void) const; |
4114 |
13 Oct 21 |
peter |
72 |
|
4114 |
13 Oct 21 |
peter |
73 |
/** |
4114 |
13 Oct 21 |
peter |
Number of samples minus one. |
4114 |
13 Oct 21 |
peter |
75 |
*/ |
4114 |
13 Oct 21 |
peter |
76 |
size_t inter_df(void) const; |
4114 |
13 Oct 21 |
peter |
77 |
|
4114 |
13 Oct 21 |
peter |
78 |
/** |
4114 |
13 Oct 21 |
peter |
Number of groups minus one |
4114 |
13 Oct 21 |
peter |
80 |
*/ |
4114 |
13 Oct 21 |
peter |
81 |
size_t intra_df(void) const; |
4114 |
13 Oct 21 |
peter |
82 |
|
4114 |
13 Oct 21 |
peter |
83 |
/** |
4114 |
13 Oct 21 |
peter |
Calculates the probability to get F (or larger) given the null |
4114 |
13 Oct 21 |
peter |
hypothesis that there is no difference between the groups. |
4114 |
13 Oct 21 |
peter |
86 |
|
4114 |
13 Oct 21 |
peter |
\return the one-sided p-value |
4114 |
13 Oct 21 |
peter |
88 |
*/ |
4114 |
13 Oct 21 |
peter |
89 |
double p_value(void) const; |
4114 |
13 Oct 21 |
peter |
90 |
|
4114 |
13 Oct 21 |
peter |
91 |
/** |
4114 |
13 Oct 21 |
peter |
\brief remove all data |
4114 |
13 Oct 21 |
peter |
93 |
*/ |
4114 |
13 Oct 21 |
peter |
94 |
void reset(void); |
4114 |
13 Oct 21 |
peter |
95 |
|
4114 |
13 Oct 21 |
peter |
96 |
private: |
4114 |
13 Oct 21 |
peter |
97 |
std::vector<Averager> aver_; |
4114 |
13 Oct 21 |
peter |
98 |
Averager total_; |
4114 |
13 Oct 21 |
peter |
99 |
}; |
4114 |
13 Oct 21 |
peter |
100 |
|
4114 |
13 Oct 21 |
peter |
101 |
}}} |
4114 |
13 Oct 21 |
peter |
102 |
|
4114 |
13 Oct 21 |
peter |
103 |
#endif |