4114 |
13 Oct 21 |
peter |
// $Id$ |
4114 |
13 Oct 21 |
peter |
2 |
|
4114 |
13 Oct 21 |
peter |
3 |
/* |
4114 |
13 Oct 21 |
peter |
Copyright (C) 2021 Peter Johansson |
4114 |
13 Oct 21 |
peter |
5 |
|
4114 |
13 Oct 21 |
peter |
This file is part of the yat library, https://dev.thep.lu.se/yat |
4114 |
13 Oct 21 |
peter |
7 |
|
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 |
12 |
|
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 |
17 |
|
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 |
20 |
*/ |
4114 |
13 Oct 21 |
peter |
21 |
|
4114 |
13 Oct 21 |
peter |
22 |
#include <config.h> |
4114 |
13 Oct 21 |
peter |
23 |
|
4114 |
13 Oct 21 |
peter |
24 |
#include "Suite.h" |
4114 |
13 Oct 21 |
peter |
25 |
|
4114 |
13 Oct 21 |
peter |
26 |
#include "yat/utility/getvector.h" |
4114 |
13 Oct 21 |
peter |
27 |
#include "yat/statistics/Anova.h" |
4114 |
13 Oct 21 |
peter |
28 |
|
4114 |
13 Oct 21 |
peter |
29 |
#include <fstream> |
4114 |
13 Oct 21 |
peter |
30 |
|
4114 |
13 Oct 21 |
peter |
31 |
using namespace theplu::yat; |
4114 |
13 Oct 21 |
peter |
32 |
|
4114 |
13 Oct 21 |
peter |
33 |
int main(int argc, char* argv[]) |
4114 |
13 Oct 21 |
peter |
34 |
{ |
4114 |
13 Oct 21 |
peter |
35 |
using namespace theplu::yat; |
4114 |
13 Oct 21 |
peter |
36 |
theplu::yat::test::Suite suite(argc, argv); |
4114 |
13 Oct 21 |
peter |
37 |
|
4114 |
13 Oct 21 |
peter |
38 |
statistics::Anova anova(6); |
4114 |
13 Oct 21 |
peter |
39 |
|
4114 |
13 Oct 21 |
peter |
40 |
std::ifstream is(test::filename("data/anova.txt")); |
4114 |
13 Oct 21 |
peter |
41 |
std::vector<double> vec; |
4114 |
13 Oct 21 |
peter |
42 |
int group = 0; |
4114 |
13 Oct 21 |
peter |
43 |
while (utility::getvector(is, vec, ',')) { |
4114 |
13 Oct 21 |
peter |
44 |
for (auto x : vec) |
4114 |
13 Oct 21 |
peter |
45 |
anova.add(x, group); |
4114 |
13 Oct 21 |
peter |
46 |
++group; |
4114 |
13 Oct 21 |
peter |
47 |
} |
4114 |
13 Oct 21 |
peter |
48 |
|
4114 |
13 Oct 21 |
peter |
49 |
suite.out() << "F: " << anova.F() << "\n"; |
4114 |
13 Oct 21 |
peter |
50 |
suite.out() << "p: " << anova.p_value() << "\n"; |
4114 |
13 Oct 21 |
peter |
51 |
suite.out() << "inter DF: " << anova.inter_df() << "\n"; |
4114 |
13 Oct 21 |
peter |
52 |
suite.out() << "intra DF: " << anova.intra_df() << "\n"; |
4114 |
13 Oct 21 |
peter |
53 |
|
4114 |
13 Oct 21 |
peter |
54 |
if (!suite.add(suite.equal_fix(anova.F(), 1.860, 0.0005))) |
4114 |
13 Oct 21 |
peter |
55 |
suite.err() << "error: incorrect F\n"; |
4114 |
13 Oct 21 |
peter |
56 |
if (!suite.add(suite.equal_fix(anova.p_value(), 0.1013, 0.00005))) |
4114 |
13 Oct 21 |
peter |
57 |
suite.err() << "error: incorrect p\n"; |
4114 |
13 Oct 21 |
peter |
58 |
if (!suite.add(anova.inter_df() == 5)) |
4114 |
13 Oct 21 |
peter |
59 |
suite.err() << "error: incorrect inter df\n"; |
4114 |
13 Oct 21 |
peter |
60 |
if (!suite.add(anova.intra_df() == 296)) |
4114 |
13 Oct 21 |
peter |
61 |
suite.err() << "error: incorrect intra df\n"; |
4114 |
13 Oct 21 |
peter |
62 |
|
4114 |
13 Oct 21 |
peter |
63 |
return suite.return_value(); |
4114 |
13 Oct 21 |
peter |
64 |
} |