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 |
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 -*- |
5411
|
20 ## @deftypefn {Function File} {} finv (@var{x}, @var{m}, @var{n}) |
5410
|
21 ## For each component of @var{x}, compute the quantile (the inverse of |
|
22 ## the CDF) at @var{x} of the F distribution with parameters @var{m} and |
|
23 ## @var{n}. |
|
24 ## @end deftypefn |
|
25 |
5428
|
26 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
5410
|
27 ## Description: Quantile function of the F distribution |
|
28 |
5411
|
29 function inv = finv (x, m, n) |
5410
|
30 |
|
31 if (nargin != 3) |
6046
|
32 print_usage (); |
5410
|
33 endif |
|
34 |
|
35 if (!isscalar (m) || !isscalar (n)) |
|
36 [retval, x, m, n] = common_size (x, m, n); |
|
37 if (retval > 0) |
5411
|
38 error ("finv: x, m and n must be of common size or scalar"); |
5410
|
39 endif |
|
40 endif |
|
41 |
|
42 sz = size (x); |
|
43 inv = zeros (sz); |
|
44 |
|
45 k = find ((x < 0) | (x > 1) | isnan (x) | !(m > 0) | !(n > 0)); |
|
46 if (any (k)) |
|
47 inv(k) = NaN; |
|
48 endif |
|
49 |
|
50 k = find ((x == 1) & (m > 0) & (n > 0)); |
|
51 if (any (k)) |
|
52 inv(k) = Inf; |
|
53 endif |
|
54 |
|
55 k = find ((x > 0) & (x < 1) & (m > 0) & (n > 0)); |
|
56 if (any (k)) |
|
57 if (isscalar (m) && isscalar (n)) |
5411
|
58 inv(k) = ((1 ./ betainv (1 - x(k), n / 2, m / 2) - 1) .* n ./ m); |
5410
|
59 else |
5411
|
60 inv(k) = ((1 ./ betainv (1 - x(k), n(k) / 2, m(k) / 2) - 1) |
5410
|
61 .* n(k) ./ m(k)); |
|
62 endif |
|
63 endif |
|
64 |
|
65 endfunction |