| 1 | ;; Fdist distribution |
|---|
| 2 | ;; Liam Healy, Sat Sep 30 2006 |
|---|
| 3 | ;; Time-stamp: <2008-02-17 13:14:44EST fdist.lisp> |
|---|
| 4 | ;; $Id$ |
|---|
| 5 | |
|---|
| 6 | (in-package :gsl) |
|---|
| 7 | |
|---|
| 8 | (defmfun fdist (generator nu1 nu2) |
|---|
| 9 | "gsl_ran_fdist" |
|---|
| 10 | (((generator generator) :pointer) (nu1 :double) (nu2 :double)) |
|---|
| 11 | :c-return :double |
|---|
| 12 | :documentation ; FDL |
|---|
| 13 | "A random variate from the F-distribution with degrees of freedom nu1 |
|---|
| 14 | and nu2. The distribution function is |
|---|
| 15 | p(x) dx = |
|---|
| 16 | { \Gamma((\nu_1 + \nu_2)/2) |
|---|
| 17 | \over \Gamma(\nu_1/2) \Gamma(\nu_2/2) } |
|---|
| 18 | \nu_1^{\nu_1/2} \nu_2^{\nu_2/2} |
|---|
| 19 | x^{\nu_1/2 - 1} (\nu_2 + \nu_1 x)^{-\nu_1/2 -\nu_2/2} |
|---|
| 20 | for x >= 0.") |
|---|
| 21 | |
|---|
| 22 | (defmfun fdist-pdf (x nu1 nu2) |
|---|
| 23 | "gsl_ran_fdist_pdf" ((x :double) (nu1 :double) (nu2 :double)) |
|---|
| 24 | :c-return :double |
|---|
| 25 | :documentation ; FDL |
|---|
| 26 | "The probability density p(x) at x |
|---|
| 27 | for an F-distribution with nu1 and nu2 degrees of freedom, |
|---|
| 28 | using the formula given #'fdist.") |
|---|
| 29 | |
|---|
| 30 | (defmfun fdist-P (x nu1 nu2) |
|---|
| 31 | "gsl_cdf_fdist_P" ((x :double) (nu1 :double) (nu2 :double)) |
|---|
| 32 | :c-return :double |
|---|
| 33 | :documentation ; FDL |
|---|
| 34 | "The cumulative distribution functions |
|---|
| 35 | P(x) for the fdist distribution with |
|---|
| 36 | nu1 and nu2 degrees of freedom.") |
|---|
| 37 | |
|---|
| 38 | (defmfun fdist-Q (x nu1 nu2) |
|---|
| 39 | "gsl_cdf_fdist_Q" ((x :double) (nu1 :double) (nu2 :double)) |
|---|
| 40 | :c-return :double |
|---|
| 41 | :documentation ; FDL |
|---|
| 42 | "The cumulative distribution functions |
|---|
| 43 | Q(x) for the fdist distribution with |
|---|
| 44 | nu1 and nu2 degrees of freedom.") |
|---|
| 45 | |
|---|
| 46 | (defmfun fdist-Pinv (P nu1 nu2) |
|---|
| 47 | "gsl_cdf_fdist_Pinv" ((P :double) (nu1 :double) (nu2 :double)) |
|---|
| 48 | :c-return :double |
|---|
| 49 | :documentation ; FDL |
|---|
| 50 | "The inverse cumulative distribution functions |
|---|
| 51 | P(x) for the fdist distribution with |
|---|
| 52 | nu1 and nu2 degrees of freedom.") |
|---|
| 53 | |
|---|
| 54 | (defmfun fdist-Qinv (Q nu1 nu2) |
|---|
| 55 | "gsl_cdf_fdist_Qinv" ((Q :double) (nu1 :double) (nu2 :double)) |
|---|
| 56 | :c-return :double |
|---|
| 57 | :documentation ; FDL |
|---|
| 58 | "The inverse cumulative distribution functions |
|---|
| 59 | Q(x) for the fdist distribution with |
|---|
| 60 | nu1 and nu2 degrees of freedom.") |
|---|
| 61 | |
|---|
| 62 | ;;; Examples and unit test |
|---|
| 63 | #| |
|---|
| 64 | (make-tests fdist |
|---|
| 65 | (letm ((rng (random-number-generator *mt19937* 0))) |
|---|
| 66 | (loop for i from 0 to 10 |
|---|
| 67 | collect |
|---|
| 68 | (fdist rng 1.0d0 2.0d0))) |
|---|
| 69 | (fdist-pdf 1.2d0 1.0d0 2.0d0) |
|---|
| 70 | (fdist-P 1.2d0 1.0d0 2.0d0) |
|---|
| 71 | (fdist-Q 1.2d0 1.0d0 2.0d0) |
|---|
| 72 | (fdist-Pinv 0.612372435695795d0 1.0d0 2.0d0) |
|---|
| 73 | (fdist-Qinv 0.38762756430420503d0 1.0d0 2.0d0)) |
|---|
| 74 | |# |
|---|
| 75 | |
|---|
| 76 | (LISP-UNIT:DEFINE-TEST FDIST |
|---|
| 77 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 78 | (LIST |
|---|
| 79 | (LIST 103.77423336538772d0 2.124850132212401d0 |
|---|
| 80 | 0.3044106947086728d0 0.30018868738752463d0 |
|---|
| 81 | 0.0011228206844788875d0 0.29210940078495257d0 |
|---|
| 82 | 0.0635729092565007d0 0.4779663652167387d0 |
|---|
| 83 | 0.03472116760794376d0 0.4869748230412714d0 |
|---|
| 84 | 2.531794516961295d0)) |
|---|
| 85 | (MULTIPLE-VALUE-LIST |
|---|
| 86 | (LETM ((RNG (RANDOM-NUMBER-GENERATOR *MT19937* 0))) |
|---|
| 87 | (LOOP FOR I FROM 0 TO 10 COLLECT |
|---|
| 88 | (FDIST RNG 1.0d0 2.0d0))))) |
|---|
| 89 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 90 | (LIST 0.1594719884624466d0) |
|---|
| 91 | (MULTIPLE-VALUE-LIST (FDIST-PDF 1.2d0 1.0d0 2.0d0))) |
|---|
| 92 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 93 | (LIST 0.6123724356957948d0) |
|---|
| 94 | (MULTIPLE-VALUE-LIST (FDIST-P 1.2d0 1.0d0 2.0d0))) |
|---|
| 95 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 96 | (LIST 0.3876275643042052d0) |
|---|
| 97 | (MULTIPLE-VALUE-LIST (FDIST-Q 1.2d0 1.0d0 2.0d0))) |
|---|
| 98 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 99 | (LIST 1.200000000000001d0) |
|---|
| 100 | (MULTIPLE-VALUE-LIST |
|---|
| 101 | (FDIST-PINV 0.612372435695795d0 1.0d0 2.0d0))) |
|---|
| 102 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 103 | (LIST 1.2000000000000006d0) |
|---|
| 104 | (MULTIPLE-VALUE-LIST |
|---|
| 105 | (FDIST-QINV 0.38762756430420503d0 1.0d0 2.0d0)))) |
|---|
| 106 | |
|---|