5410
|
1 ## Copyright (C) 1995, 1996, 1997 Kurt Hornik |
|
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 |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
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 |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
|
19 |
|
20 ## -*- texinfo -*- |
5411
|
21 ## @deftypefn {Function File} {} fpdf (@var{x}, @var{m}, @var{n}) |
5410
|
22 ## For each element of @var{x}, compute the probability density function |
|
23 ## (PDF) at @var{x} of the F distribution with @var{m} and @var{n} |
|
24 ## degrees of freedom. |
|
25 ## @end deftypefn |
|
26 |
|
27 ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at> |
|
28 ## Description: PDF of the F distribution |
|
29 |
5411
|
30 function pdf = fpdf (x, m, n) |
5410
|
31 |
|
32 if (nargin != 3) |
5411
|
33 usage ("fpdf (x, m, n)"); |
5410
|
34 endif |
|
35 |
|
36 if (!isscalar (m) || !isscalar (n)) |
|
37 [retval, x, m, n] = common_size (x, m, n); |
|
38 if (retval > 0) |
5411
|
39 error ("fpdf: x, m and n must be of common size or scalar"); |
5410
|
40 endif |
|
41 endif |
|
42 |
|
43 sz = size (x); |
|
44 pdf = zeros (sz); |
|
45 |
|
46 k = find (isnan (x) | !(m > 0) | !(n > 0)); |
|
47 if (any (k)) |
|
48 pdf(k) = NaN; |
|
49 endif |
|
50 |
|
51 k = find ((x > 0) & (x < Inf) & (m > 0) & (n > 0)); |
|
52 if (any (k)) |
|
53 if (isscalar (m) && isscalar (n)) |
|
54 tmp = m / n * x(k); |
|
55 pdf(k) = (exp ((m / 2 - 1) .* log (tmp) |
|
56 - ((m + n) / 2) .* log (1 + tmp)) |
|
57 .* (m / n) ./ beta (m / 2, n / 2)); |
|
58 else |
|
59 tmp = m(k) .* x(k) ./ n(k); |
|
60 pdf(k) = (exp ((m(k) / 2 - 1) .* log (tmp) |
|
61 - ((m(k) + n(k)) / 2) .* log (1 + tmp)) |
|
62 .* (m(k) ./ n(k)) ./ beta (m(k) / 2, n(k) / 2)); |
|
63 endif |
|
64 endif |
|
65 |
|
66 endfunction |