98 |
10 Jun 04 |
peter |
// $Id$ |
98 |
10 Jun 04 |
peter |
2 |
|
675 |
10 Oct 06 |
jari |
3 |
/* |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2004 Jari Häkkinen, Peter Johansson |
831 |
27 Mar 07 |
peter |
Copyright (C) 2005 Peter Johansson |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2007 Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
3114 |
10 Nov 13 |
peter |
Copyright (C) 2012, 2013 Peter Johansson |
675 |
10 Oct 06 |
jari |
10 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
675 |
10 Oct 06 |
jari |
12 |
|
675 |
10 Oct 06 |
jari |
The yat library is free software; you can redistribute it and/or |
675 |
10 Oct 06 |
jari |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
675 |
10 Oct 06 |
jari |
License, or (at your option) any later version. |
675 |
10 Oct 06 |
jari |
17 |
|
675 |
10 Oct 06 |
jari |
The yat library is distributed in the hope that it will be useful, |
675 |
10 Oct 06 |
jari |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
675 |
10 Oct 06 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
675 |
10 Oct 06 |
jari |
General Public License for more details. |
675 |
10 Oct 06 |
jari |
22 |
|
675 |
10 Oct 06 |
jari |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
675 |
10 Oct 06 |
jari |
25 |
*/ |
675 |
10 Oct 06 |
jari |
26 |
|
2881 |
18 Nov 12 |
peter |
27 |
#include <config.h> |
2881 |
18 Nov 12 |
peter |
28 |
|
779 |
05 Mar 07 |
peter |
29 |
#include "tTest.h" |
822 |
18 Mar 07 |
peter |
30 |
#include "AveragerWeighted.h" |
680 |
11 Oct 06 |
jari |
31 |
#include "tScore.h" |
623 |
05 Sep 06 |
peter |
32 |
|
822 |
18 Mar 07 |
peter |
33 |
#include <algorithm> |
98 |
10 Jun 04 |
peter |
34 |
#include <cmath> |
98 |
10 Jun 04 |
peter |
35 |
|
98 |
10 Jun 04 |
peter |
36 |
namespace theplu { |
680 |
11 Oct 06 |
jari |
37 |
namespace yat { |
3023 |
06 Apr 13 |
peter |
38 |
namespace statistics { |
98 |
10 Jun 04 |
peter |
39 |
|
3023 |
06 Apr 13 |
peter |
40 |
tTest::tTest(void) |
822 |
18 Mar 07 |
peter |
41 |
: updated_(false) |
102 |
15 Jun 04 |
peter |
42 |
{ |
102 |
15 Jun 04 |
peter |
43 |
} |
102 |
15 Jun 04 |
peter |
44 |
|
3023 |
06 Apr 13 |
peter |
45 |
|
822 |
18 Mar 07 |
peter |
46 |
void tTest::add(double x, bool target, double w) |
98 |
10 Jun 04 |
peter |
47 |
{ |
822 |
18 Mar 07 |
peter |
48 |
if (!w) |
822 |
18 Mar 07 |
peter |
49 |
return; |
822 |
18 Mar 07 |
peter |
50 |
if (target) |
822 |
18 Mar 07 |
peter |
51 |
pos_.add(x,w); |
822 |
18 Mar 07 |
peter |
52 |
else |
822 |
18 Mar 07 |
peter |
53 |
neg_.add(x,w); |
822 |
18 Mar 07 |
peter |
54 |
updated_=false; |
98 |
10 Jun 04 |
peter |
55 |
} |
98 |
10 Jun 04 |
peter |
56 |
|
3023 |
06 Apr 13 |
peter |
57 |
|
1451 |
28 Aug 08 |
peter |
58 |
void tTest::reset(void) |
1451 |
28 Aug 08 |
peter |
59 |
{ |
1451 |
28 Aug 08 |
peter |
60 |
pos_.reset(); |
1451 |
28 Aug 08 |
peter |
61 |
neg_.reset(); |
1451 |
28 Aug 08 |
peter |
62 |
dof_=0; |
1451 |
28 Aug 08 |
peter |
63 |
t_=0; |
1451 |
28 Aug 08 |
peter |
64 |
updated_=false; |
1451 |
28 Aug 08 |
peter |
65 |
} |
1451 |
28 Aug 08 |
peter |
66 |
|
1451 |
28 Aug 08 |
peter |
67 |
|
3024 |
06 Apr 13 |
peter |
68 |
double tTest::score(void) const |
623 |
05 Sep 06 |
peter |
69 |
{ |
822 |
18 Mar 07 |
peter |
70 |
if (!updated_){ |
822 |
18 Mar 07 |
peter |
71 |
tScore score(false); |
822 |
18 Mar 07 |
peter |
72 |
t_ = score.score(pos_, neg_, &dof_); |
822 |
18 Mar 07 |
peter |
73 |
updated_=true; |
822 |
18 Mar 07 |
peter |
74 |
} |
623 |
05 Sep 06 |
peter |
75 |
return t_; |
623 |
05 Sep 06 |
peter |
76 |
} |
623 |
05 Sep 06 |
peter |
77 |
|
623 |
05 Sep 06 |
peter |
78 |
|
3023 |
06 Apr 13 |
peter |
79 |
double tTest::p_left(void) const |
112 |
07 Jul 04 |
peter |
80 |
{ |
3025 |
06 Apr 13 |
peter |
81 |
double t = score(); |
3025 |
06 Apr 13 |
peter |
82 |
if (!dof_) |
3025 |
06 Apr 13 |
peter |
83 |
return 1.0; |
3025 |
06 Apr 13 |
peter |
84 |
return gsl_cdf_tdist_P(t, dof_); |
112 |
07 Jul 04 |
peter |
85 |
} |
98 |
10 Jun 04 |
peter |
86 |
|
822 |
18 Mar 07 |
peter |
87 |
|
3023 |
06 Apr 13 |
peter |
88 |
double tTest::p_right(void) const |
98 |
10 Jun 04 |
peter |
89 |
{ |
3024 |
06 Apr 13 |
peter |
90 |
double t = score(); |
3024 |
06 Apr 13 |
peter |
91 |
if (!dof_) |
779 |
05 Mar 07 |
peter |
92 |
return 1.0; |
3024 |
06 Apr 13 |
peter |
93 |
return gsl_cdf_tdist_Q(t, dof_); |
98 |
10 Jun 04 |
peter |
94 |
} |
98 |
10 Jun 04 |
peter |
95 |
|
3023 |
06 Apr 13 |
peter |
96 |
|
3023 |
06 Apr 13 |
peter |
97 |
double tTest::p_value(void) const |
3023 |
06 Apr 13 |
peter |
98 |
{ |
3023 |
06 Apr 13 |
peter |
99 |
double p=2*p_right(); |
3023 |
06 Apr 13 |
peter |
100 |
return std::min(p,2-p); |
3023 |
06 Apr 13 |
peter |
101 |
} |
3023 |
06 Apr 13 |
peter |
102 |
|
3023 |
06 Apr 13 |
peter |
103 |
|
3023 |
06 Apr 13 |
peter |
104 |
double tTest::p_value_one_sided(void) const |
3023 |
06 Apr 13 |
peter |
105 |
{ |
3023 |
06 Apr 13 |
peter |
106 |
return p_right(); |
3023 |
06 Apr 13 |
peter |
107 |
} |
3023 |
06 Apr 13 |
peter |
108 |
|
680 |
11 Oct 06 |
jari |
109 |
}}} // of namespace statistics, yat, and theplu |