source: trunk/test/ttest_test.cc @ 1437

Last change on this file since 1437 was 1437, checked in by Peter, 13 years ago

merge patch release 0.4.2 to trunk. Delta 0.4.2-0.4.1

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.8 KB
RevLine 
[822]1// $Id: ttest_test.cc 1437 2008-08-25 17:55:00Z peter $
2
3/*
[1275]4  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
5  Copyright (C) 2008 Peter Johansson
[822]6
[1437]7  This file is part of the yat library, http://dev.thep.lu.se/yat
[822]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
[1248]25#include "Suite.h"
26
[822]27#include "yat/classifier/Target.h"
28#include "yat/statistics/tTest.h"
29#include "yat/statistics/utility.h"
[1120]30#include "yat/utility/Vector.h"
[822]31
32#include <cmath>
33#include <fstream>
34#include <iostream>
35
36
37using namespace theplu::yat;
38
[1248]39int main(int argc, char* argv[])
[822]40{ 
[1248]41  test::Suite suite(argc, argv);
[822]42
[1248]43  suite.err() << "testing ttest" << std::endl;
[1120]44  utility::Vector value(31);
[822]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;
[1145]54  statistics::add(test, value.begin(), value.end(), target);
[822]55  double p = test.p_value_one_sided();
56  double p2 = test.p_value();
[1248]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";
[822]60  }
61
[1248]62  return suite.return_value();
[822]63}
Note: See TracBrowser for help on using the repository browser.