1 | // $Id: utility.cc 1553 2008-10-07 16:06:50Z peter $ |
---|

2 | |
---|

3 | /* |
---|

4 | Copyright (C) 2004 Jari Häkkinen, Peter Johansson |
---|

5 | Copyright (C) 2005 Peter Johansson |
---|

6 | Copyright (C) 2006, 2007 Jari Häkkinen, Peter Johansson |
---|

7 | Copyright (C) 2008 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 3 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 yat. If not, see <http://www.gnu.org/licenses/>. |
---|

23 | */ |
---|

24 | |
---|

25 | #include "utility.h" |
---|

26 | |
---|

27 | #include <gsl/gsl_cdf.h> |
---|

28 | #include <gsl/gsl_randist.h> |
---|

29 | #include <gsl/gsl_statistics_double.h> |
---|

30 | |
---|

31 | #include <cassert> |
---|

32 | |
---|

33 | namespace theplu { |
---|

34 | namespace yat { |
---|

35 | namespace statistics { |
---|

36 | |
---|

37 | double cdf_hypergeometric_P(unsigned int k, unsigned int n1, |
---|

38 | unsigned int n2, unsigned int t) |
---|

39 | { |
---|

40 | return gsl_cdf_hypergeometric_P(k, n1, n2, t); |
---|

41 | } |
---|

42 | |
---|

43 | |
---|

44 | double pearson_p_value(double r, unsigned int n) |
---|

45 | { |
---|

46 | assert(n>=2); |
---|

47 | if (n<=2) |
---|

48 | return std::numeric_limits<double>::quiet_NaN(); |
---|

49 | if (r>=1.0) |
---|

50 | return 0.0; |
---|

51 | if (r<=-1.0) |
---|

52 | return 1.0; |
---|

53 | return gsl_cdf_tdist_Q(r*sqrt((n-2)/(1-r*r)), n-2); |
---|

54 | } |
---|

55 | |
---|

56 | |
---|

57 | double kurtosis(const utility::VectorBase& v) |
---|

58 | { |
---|

59 | const gsl_vector* gvp=v.gsl_vector_p(); |
---|

60 | return gsl_stats_kurtosis(gvp->data,gvp->stride,gvp->size); |
---|

61 | } |
---|

62 | |
---|

63 | |
---|

64 | double skewness(const utility::VectorBase& v) |
---|

65 | { |
---|

66 | const gsl_vector* gvp=v.gsl_vector_p(); |
---|

67 | return gsl_stats_skew(gvp->data,gvp->stride,gvp->size); |
---|

68 | } |
---|

69 | |
---|

70 | }}} // of namespace statistics, yat, and theplu |
---|