source: trunk/yat/statistics/tTest.cc @ 3023

Last change on this file since 3023 was 3023, checked in by Peter, 9 years ago

closes #754. ROC::area() is now const

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
  • Property svndigest:ignore set to 776
File size: 2.1 KB
Line 
1// $Id: tTest.cc 3023 2013-04-06 02:35:36Z 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, 2008 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2012 Peter Johansson
9
10  This file is part of the yat library, http://dev.thep.lu.se/yat
11
12  The yat library is free software; you can redistribute it and/or
13  modify it under the terms of the GNU General Public License as
14  published by the Free Software Foundation; either version 3 of the
15  License, or (at your option) any later version.
16
17  The yat library is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  General Public License for more details.
21
22  You should have received a copy of the GNU General Public License
23  along with yat. If not, see <http://www.gnu.org/licenses/>.
24*/
25
26#include <config.h>
27
28#include "tTest.h"
29#include "AveragerWeighted.h"
30#include "tScore.h"
31
32#include <algorithm>
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
57  void tTest::reset(void)
58  {
59    pos_.reset();
60    neg_.reset();
61    dof_=0;
62    t_=0;
63    updated_=false;
64  }
65
66
67  double tTest::score(void)
68  {
69    if (!updated_){
70      tScore score(false);
71      t_ = score.score(pos_, neg_, &dof_);
72      updated_=true;
73    }
74    return t_;
75  }
76
77
78  double tTest::p_left(void) const
79  {
80    assert(0 && "not implemented yet");
81  }
82
83
84  double tTest::p_right(void) const
85  {
86    double t=t_;
87    double dof=dof_;
88    if (!updated_){
89      tScore score(false);
90      t = score.score(pos_, neg_, &dof);
91    }
92    if (!dof)
93      return 1.0;
94    return gsl_cdf_tdist_Q(t, dof);
95  }
96
97
98  double tTest::p_value(void) const
99  {
100    double p=2*p_right();
101    return std::min(p,2-p);
102  }
103
104
105  double tTest::p_value_one_sided(void) const
106  {
107    return p_right();
108  }
109
110}}} // of namespace statistics, yat, and theplu
Note: See TracBrowser for help on using the repository browser.