1 | // $Id: anova.cc 4114 2021-10-13 04:36:16Z peter $ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) 2021 Peter Johansson |
---|
5 | |
---|
6 | This file is part of the yat library, https://dev.thep.lu.se/yat |
---|
7 | |
---|
8 | The yat library is free software; you can redistribute it and/or |
---|
9 | modify it under the terms of the GNU General Public License as |
---|
10 | published by the Free Software Foundation; either version 3 of the |
---|
11 | License, or (at your option) any later version. |
---|
12 | |
---|
13 | The yat library is distributed in the hope that it will be useful, |
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU General Public License |
---|
19 | along with yat. If not, see <https://www.gnu.org/licenses/>. |
---|
20 | */ |
---|
21 | |
---|
22 | #include <config.h> |
---|
23 | |
---|
24 | #include "Suite.h" |
---|
25 | |
---|
26 | #include "yat/utility/getvector.h" |
---|
27 | #include "yat/statistics/Anova.h" |
---|
28 | |
---|
29 | #include <fstream> |
---|
30 | |
---|
31 | using namespace theplu::yat; |
---|
32 | |
---|
33 | int main(int argc, char* argv[]) |
---|
34 | { |
---|
35 | using namespace theplu::yat; |
---|
36 | theplu::yat::test::Suite suite(argc, argv); |
---|
37 | |
---|
38 | statistics::Anova anova(6); |
---|
39 | |
---|
40 | std::ifstream is(test::filename("data/anova.txt")); |
---|
41 | std::vector<double> vec; |
---|
42 | int group = 0; |
---|
43 | while (utility::getvector(is, vec, ',')) { |
---|
44 | for (auto x : vec) |
---|
45 | anova.add(x, group); |
---|
46 | ++group; |
---|
47 | } |
---|
48 | |
---|
49 | suite.out() << "F: " << anova.F() << "\n"; |
---|
50 | suite.out() << "p: " << anova.p_value() << "\n"; |
---|
51 | suite.out() << "inter DF: " << anova.inter_df() << "\n"; |
---|
52 | suite.out() << "intra DF: " << anova.intra_df() << "\n"; |
---|
53 | |
---|
54 | if (!suite.add(suite.equal_fix(anova.F(), 1.860, 0.0005))) |
---|
55 | suite.err() << "error: incorrect F\n"; |
---|
56 | if (!suite.add(suite.equal_fix(anova.p_value(), 0.1013, 0.00005))) |
---|
57 | suite.err() << "error: incorrect p\n"; |
---|
58 | if (!suite.add(anova.inter_df() == 5)) |
---|
59 | suite.err() << "error: incorrect inter df\n"; |
---|
60 | if (!suite.add(anova.intra_df() == 296)) |
---|
61 | suite.err() << "error: incorrect intra df\n"; |
---|
62 | |
---|
63 | return suite.return_value(); |
---|
64 | } |
---|