source: trunk/yat/statistics/tTest.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 Author Date Id Revision
File size: 1.9 KB
Line 
1// $Id: tTest.cc 1437 2008-08-25 17:55:00Z peter $
2
3/*
4  Copyright (C) 2004 Jari Häkkinen, Peter Johansson
5  Copyright (C) 2005 Peter Johansson
6  Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér
7  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
8
9  This file is part of the yat library, http://dev.thep.lu.se/yat
10
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 2 of the
14  License, or (at your option) any later version.
15
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20
21  You should have received a copy of the GNU General Public License
22  along with this program; if not, write to the Free Software
23  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24  02111-1307, USA.
25*/
26
27#include "tTest.h"
28#include "AveragerWeighted.h"
29#include "tScore.h"
30
31#include <algorithm>
32#include <cassert>
33#include <cmath>
34
35namespace theplu {
36namespace yat {
37namespace statistics { 
38
39  tTest::tTest(void) 
40    : updated_(false)
41  {
42  }
43
44 
45  void tTest::add(double x, bool target, double w)
46  {
47    if (!w)
48      return;
49    if (target)
50      pos_.add(x,w);
51    else
52      neg_.add(x,w);
53    updated_=false;
54  }
55
56  double tTest::score(void)
57  {
58    if (!updated_){
59      tScore score(false);
60      t_ = score.score(pos_, neg_, &dof_);
61      updated_=true;
62    }
63    return t_;
64  }
65
66
67  double tTest::p_value(void) const
68  {
69    double p=2*p_value_one_sided();
70    return std::min(p,2-p); 
71  }
72
73
74  double tTest::p_value_one_sided(void) const
75  {
76    double t=t_;
77    double dof=dof_;
78    if (!updated_){
79      tScore score(false);
80      t = score.score(pos_, neg_, &dof);
81    }
82    if (!dof)
83      return 1.0;
84    return gsl_cdf_tdist_Q(t, dof);
85  }
86
87}}} // of namespace statistics, yat, and theplu
Note: See TracBrowser for help on using the repository browser.