1 | // $Id: ttest_test.cc 1487 2008-09-10 08:41:36Z jari $ |
---|

2 | |
---|

3 | /* |
---|

4 | Copyright (C) 2007 Jari Häkkinen, Peter Johansson |
---|

5 | Copyright (C) 2008 Peter Johansson |
---|

6 | |
---|

7 | This file is part of the yat library, http://dev.thep.lu.se/yat |
---|

8 | |
---|

9 | The yat library is free software; you can redistribute it and/or |
---|

10 | modify it under the terms of the GNU General Public License as |
---|

11 | published by the Free Software Foundation; either version 3 of the |
---|

12 | License, or (at your option) any later version. |
---|

13 | |
---|

14 | The yat library is distributed in the hope that it will be useful, |
---|

15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|

16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|

17 | General Public License for more details. |
---|

18 | |
---|

19 | You should have received a copy of the GNU General Public License |
---|

20 | along with yat. If not, see <http://www.gnu.org/licenses/>. |
---|

21 | */ |
---|

22 | |
---|

23 | #include "Suite.h" |
---|

24 | |
---|

25 | #include "yat/classifier/Target.h" |
---|

26 | #include "yat/statistics/tTest.h" |
---|

27 | #include "yat/statistics/utility.h" |
---|

28 | #include "yat/utility/Vector.h" |
---|

29 | |
---|

30 | #include <cmath> |
---|

31 | #include <fstream> |
---|

32 | #include <iostream> |
---|

33 | |
---|

34 | |
---|

35 | using namespace theplu::yat; |
---|

36 | |
---|

37 | int main(int argc, char* argv[]) |
---|

38 | { |
---|

39 | test::Suite suite(argc, argv); |
---|

40 | |
---|

41 | suite.err() << "testing ttest" << std::endl; |
---|

42 | utility::Vector value(31); |
---|

43 | std::vector<std::string> label(31,"positive"); |
---|

44 | for (size_t i=0; i<16; i++) |
---|

45 | label[i] = "negative"; |
---|

46 | classifier::Target target(label); |
---|

47 | target.set_binary(0,false); |
---|

48 | target.set_binary(1,true); |
---|

49 | for (size_t i=0; i<value.size(); i++) |
---|

50 | value(i)=i; |
---|

51 | statistics::tTest test; |
---|

52 | statistics::add(test, value.begin(), value.end(), target); |
---|

53 | double p = test.p_value_one_sided(); |
---|

54 | double p2 = test.p_value(); |
---|

55 | if (!suite.equal(p2, 2*p) ){ |
---|

56 | suite.add(false); |
---|

57 | suite.err() << "Two-sided P-value should equal 2 * one-sided P-value.\n"; |
---|

58 | } |
---|

59 | |
---|

60 | return suite.return_value(); |
---|

61 | } |
---|