Mercurial > octave-nkf
annotate scripts/statistics/distributions/hygepdf.m @ 11472:1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 09 Jan 2011 21:33:04 -0800 |
parents | 95c3e38098bf |
children | fd0a3ac60b0e |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 1996, 1997, 2005, 2006, 2007, 2009 Kurt Hornik |
5410 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
5410 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
5410 | 18 |
19 ## -*- texinfo -*- | |
7002 | 20 ## @deftypefn {Function File} {} hygepdf (@var{x}, @var{t}, @var{m}, @var{n}) |
5410 | 21 ## Compute the probability density function (PDF) at @var{x} of the |
7002 | 22 ## hypergeometric distribution with parameters @var{t}, @var{m}, and |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
23 ## @var{n}. This is the probability of obtaining @var{x} marked items |
5410 | 24 ## when randomly drawing a sample of size @var{n} without replacement |
25 ## from a population of total size @var{t} containing @var{m} marked items. | |
26 ## | |
27 ## The arguments must be of common size or scalar. | |
28 ## @end deftypefn | |
29 | |
5428 | 30 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
5410 | 31 ## Description: PDF of the hypergeometric distribution |
32 | |
7002 | 33 function pdf = hygepdf (x, t, m, n) |
5410 | 34 |
35 if (nargin != 4) | |
6046 | 36 print_usage (); |
5410 | 37 endif |
38 | |
7002 | 39 if (!isscalar (t) || !isscalar (m) || !isscalar (n)) |
40 [retval, x, t, m, n] = common_size (x, t, m, n); | |
5410 | 41 if (retval > 0) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
42 error ("hygepdf: X, T, M, and N must be of common size or scalar"); |
5410 | 43 endif |
44 endif | |
45 | |
46 pdf = zeros (size (x)); | |
47 | |
48 ## everything in i1 gives NaN | |
7002 | 49 i1 = ((t < 0) | (m < 0) | (n <= 0) | (t != round (t)) | |
50 (m != round (m)) | (n != round (n)) | (m > t) | (n > t)); | |
5410 | 51 ## everything in i2 gives 0 unless in i1 |
52 i2 = ((x != round (x)) | (x < 0) | (x > m) | (n < x) | (n-x > t-m)); | |
53 k = find (i1); | |
54 if (any (k)) | |
7002 | 55 if (isscalar (t) && isscalar (m) && isscalar (n)) |
10525
3306cfcb856e
Replace constructs like "NaN * one()" with "NaN()" and "Inf * ones ()" with "Inf()"
David Bateman <dbateman@free.fr>
parents:
9051
diff
changeset
|
56 pdf = NaN (size (x)); |
5410 | 57 else |
58 pdf (k) = NaN; | |
59 endif | |
60 endif | |
61 k = find (!i1 & !i2); | |
62 if (any (k)) | |
7002 | 63 if (isscalar (t) && isscalar (m) && isscalar (n)) |
5410 | 64 pdf (k) = (bincoeff (m, x(k)) .* bincoeff (t-m, n-x(k)) |
10549 | 65 / bincoeff (t, n)); |
5410 | 66 else |
67 pdf (k) = (bincoeff (m(k), x(k)) .* bincoeff (t(k)-m(k), n(k)-x(k)) | |
10549 | 68 ./ bincoeff (t(k), n(k))); |
5410 | 69 endif |
70 endif | |
71 | |
72 endfunction |