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} {} fcdf (@var{x}, @var{m}, @var{n}) |
5410
|
22 ## For each element of @var{x}, compute the CDF at @var{x} of the F |
|
23 ## distribution with @var{m} and @var{n} degrees of freedom, i.e., |
|
24 ## PROB (F (@var{m}, @var{n}) <= @var{x}). |
|
25 ## @end deftypefn |
|
26 |
5428
|
27 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
5410
|
28 ## Description: CDF of the F distribution |
|
29 |
5411
|
30 function cdf = fcdf (x, m, n) |
5410
|
31 |
|
32 if (nargin != 3) |
6046
|
33 print_usage (); |
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 ("fcdf: x, m and n must be of common size or scalar"); |
5410
|
40 endif |
|
41 endif |
|
42 |
|
43 sz = size (x); |
|
44 cdf = zeros (sz); |
|
45 |
|
46 k = find (!(m > 0) | !(n > 0) | isnan (x)); |
|
47 if (any (k)) |
|
48 cdf(k) = NaN; |
|
49 endif |
|
50 |
|
51 k = find ((x == Inf) & (m > 0) & (n > 0)); |
|
52 if (any (k)) |
|
53 cdf(k) = 1; |
|
54 endif |
|
55 |
|
56 k = find ((x > 0) & (x < Inf) & (m > 0) & (n > 0)); |
|
57 if (any (k)) |
|
58 if (isscalar (m) && isscalar (n)) |
|
59 cdf(k) = 1 - betainc (1 ./ (1 + m .* x(k) ./ n), n / 2, m / 2); |
|
60 else |
|
61 cdf(k) = 1 - betainc (1 ./ (1 + m(k) .* x(k) ./ n(k)), n(k) / 2, |
|
62 m(k) / 2); |
|
63 endif |
|
64 endif |
|
65 |
|
66 endfunction |