1 | // $Id: ttest_test.cc 1275 2008-04-11 06:10:12Z 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://trac.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 2 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 this program; if not, write to the Free Software |
---|

21 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|

22 | 02111-1307, USA. |
---|

23 | */ |
---|

24 | |
---|

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

26 | |
---|

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

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

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

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

31 | |
---|

32 | #include <cmath> |
---|

33 | #include <fstream> |
---|

34 | #include <iostream> |
---|

35 | |
---|

36 | |
---|

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

38 | |
---|

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

40 | { |
---|

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

42 | |
---|

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

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

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

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

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

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

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

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

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

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

53 | statistics::tTest test; |
---|

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

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

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

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

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

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

60 | } |
---|

61 | |
---|

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

63 | } |
---|