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

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

fixes #755

  • 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.0 KB
Line 
1// $Id: tTest.cc 3024 2013-04-06 06:38:51Z 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) const
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 = score();
87    if (!dof_)
88      return 1.0;
89    return gsl_cdf_tdist_Q(t, dof_);
90  }
91
92
93  double tTest::p_value(void) const
94  {
95    double p=2*p_right();
96    return std::min(p,2-p);
97  }
98
99
100  double tTest::p_value_one_sided(void) const
101  {
102    return p_right();
103  }
104
105}}} // of namespace statistics, yat, and theplu
Note: See TracBrowser for help on using the repository browser.