1 | // $Id: utility.cc 1271 2008-04-09 16:11:07Z 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 |
---|
7 | Copyright (C) 2007 Jari Häkkinen |
---|
8 | |
---|
9 | This file is part of the yat library, http://trac.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 "utility.h" |
---|
28 | |
---|
29 | #include <gsl/gsl_cdf.h> |
---|
30 | #include <gsl/gsl_randist.h> |
---|
31 | #include <gsl/gsl_statistics_double.h> |
---|
32 | |
---|
33 | #include <cassert> |
---|
34 | |
---|
35 | namespace theplu { |
---|
36 | namespace yat { |
---|
37 | namespace statistics { |
---|
38 | |
---|
39 | double cdf_hypergeometric_P(unsigned int k, unsigned int n1, |
---|
40 | unsigned int n2, unsigned int t) |
---|
41 | { |
---|
42 | double p=0; |
---|
43 | for (size_t i=0; i<=k; i++) |
---|
44 | p+= gsl_ran_hypergeometric_pdf(i, n1, n2, t); |
---|
45 | return p; |
---|
46 | } |
---|
47 | |
---|
48 | |
---|
49 | double pearson_p_value(double r, unsigned int n) |
---|
50 | { |
---|
51 | assert(n>=2); |
---|
52 | if (n<=2) |
---|
53 | return std::numeric_limits<double>::quiet_NaN(); |
---|
54 | return gsl_cdf_tdist_Q(r*sqrt((n-2)/(1-r*r)), n-2); |
---|
55 | } |
---|
56 | |
---|
57 | |
---|
58 | double kurtosis(const utility::VectorBase& v) |
---|
59 | { |
---|
60 | const gsl_vector* gvp=v.gsl_vector_p(); |
---|
61 | return gsl_stats_kurtosis(gvp->data,gvp->stride,gvp->size); |
---|
62 | } |
---|
63 | |
---|
64 | |
---|
65 | double skewness(const utility::VectorBase& v) |
---|
66 | { |
---|
67 | const gsl_vector* gvp=v.gsl_vector_p(); |
---|
68 | return gsl_stats_skew(gvp->data,gvp->stride,gvp->size); |
---|
69 | } |
---|
70 | |
---|
71 | }}} // of namespace statistics, yat, and theplu |
---|