822 |
18 Mar 07 |
peter |
// $Id$ |
822 |
18 Mar 07 |
peter |
2 |
|
822 |
18 Mar 07 |
peter |
3 |
/* |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2007 Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
3114 |
10 Nov 13 |
peter |
Copyright (C) 2012, 2013 Peter Johansson |
822 |
18 Mar 07 |
peter |
7 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
822 |
18 Mar 07 |
peter |
9 |
|
822 |
18 Mar 07 |
peter |
The yat library is free software; you can redistribute it and/or |
822 |
18 Mar 07 |
peter |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
822 |
18 Mar 07 |
peter |
License, or (at your option) any later version. |
822 |
18 Mar 07 |
peter |
14 |
|
822 |
18 Mar 07 |
peter |
The yat library is distributed in the hope that it will be useful, |
822 |
18 Mar 07 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
822 |
18 Mar 07 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
822 |
18 Mar 07 |
peter |
General Public License for more details. |
822 |
18 Mar 07 |
peter |
19 |
|
822 |
18 Mar 07 |
peter |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
822 |
18 Mar 07 |
peter |
22 |
*/ |
822 |
18 Mar 07 |
peter |
23 |
|
2881 |
18 Nov 12 |
peter |
24 |
#include <config.h> |
2881 |
18 Nov 12 |
peter |
25 |
|
1248 |
19 Mar 08 |
peter |
26 |
#include "Suite.h" |
1248 |
19 Mar 08 |
peter |
27 |
|
822 |
18 Mar 07 |
peter |
28 |
#include "yat/classifier/Target.h" |
822 |
18 Mar 07 |
peter |
29 |
#include "yat/statistics/tTest.h" |
822 |
18 Mar 07 |
peter |
30 |
#include "yat/statistics/utility.h" |
1120 |
21 Feb 08 |
peter |
31 |
#include "yat/utility/Vector.h" |
822 |
18 Mar 07 |
peter |
32 |
|
822 |
18 Mar 07 |
peter |
33 |
#include <cmath> |
822 |
18 Mar 07 |
peter |
34 |
#include <fstream> |
822 |
18 Mar 07 |
peter |
35 |
#include <iostream> |
822 |
18 Mar 07 |
peter |
36 |
|
822 |
18 Mar 07 |
peter |
37 |
|
822 |
18 Mar 07 |
peter |
38 |
using namespace theplu::yat; |
822 |
18 Mar 07 |
peter |
39 |
|
1248 |
19 Mar 08 |
peter |
40 |
int main(int argc, char* argv[]) |
3043 |
08 Jun 13 |
peter |
41 |
{ |
1248 |
19 Mar 08 |
peter |
42 |
test::Suite suite(argc, argv); |
822 |
18 Mar 07 |
peter |
43 |
|
1248 |
19 Mar 08 |
peter |
44 |
suite.err() << "testing ttest" << std::endl; |
1120 |
21 Feb 08 |
peter |
45 |
utility::Vector value(31); |
822 |
18 Mar 07 |
peter |
46 |
std::vector<std::string> label(31,"positive"); |
3043 |
08 Jun 13 |
peter |
47 |
for (size_t i=0; i<16; i++) |
822 |
18 Mar 07 |
peter |
48 |
label[i] = "negative"; |
822 |
18 Mar 07 |
peter |
49 |
classifier::Target target(label); |
822 |
18 Mar 07 |
peter |
50 |
target.set_binary(0,false); |
822 |
18 Mar 07 |
peter |
51 |
target.set_binary(1,true); |
3043 |
08 Jun 13 |
peter |
52 |
for (size_t i=0; i<value.size(); i++) |
822 |
18 Mar 07 |
peter |
53 |
value(i)=i; |
822 |
18 Mar 07 |
peter |
54 |
statistics::tTest test; |
1145 |
25 Feb 08 |
peter |
55 |
statistics::add(test, value.begin(), value.end(), target); |
3043 |
08 Jun 13 |
peter |
56 |
double p = test.p_right(); |
822 |
18 Mar 07 |
peter |
57 |
double p2 = test.p_value(); |
1248 |
19 Mar 08 |
peter |
58 |
if (!suite.equal(p2, 2*p) ){ |
1248 |
19 Mar 08 |
peter |
59 |
suite.add(false); |
1248 |
19 Mar 08 |
peter |
60 |
suite.err() << "Two-sided P-value should equal 2 * one-sided P-value.\n"; |
822 |
18 Mar 07 |
peter |
61 |
} |
822 |
18 Mar 07 |
peter |
62 |
|
1248 |
19 Mar 08 |
peter |
63 |
return suite.return_value(); |
822 |
18 Mar 07 |
peter |
64 |
} |