changelog shortlog tags changeset files revisions annotate raw

scripts/statistics/distributions/fcdf.m

changeset 10289: 4b124317dc38
parent:93c65f2a5668
author: John W. Eaton <jwe@octave.org>
date: Tue Feb 09 20:58:55 2010 -0500 (53 minutes ago)
permissions: -rw-r--r--
description: base_properties::set_children: account for hidden children
1## Copyright (C) 1995, 1996, 1997, 2005, 2006, 2007 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 3 of the License, or (at
8## your option) 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, see
17## <http://www.gnu.org/licenses/>.
18
19## -*- texinfo -*-
20## @deftypefn {Function File} {} fcdf (@var{x}, @var{m}, @var{n})
21## For each element of @var{x}, compute the CDF at @var{x} of the F
22## distribution with @var{m} and @var{n} degrees of freedom, i.e.,
23## PROB (F (@var{m}, @var{n}) <= @var{x}).
24## @end deftypefn
25
26## Author: KH <Kurt.Hornik@wu-wien.ac.at>
27## Description: CDF of the F distribution
28
29function cdf = fcdf (x, m, n)
30
31 if (nargin != 3)
32 print_usage ();
33 endif
34
35 if (!isscalar (m) || !isscalar (n))
36 [retval, x, m, n] = common_size (x, m, n);
37 if (retval > 0)
38 error ("fcdf: x, m and n must be of common size or scalar");
39 endif
40 endif
41
42 sz = size (x);
43 cdf = zeros (sz);
44
45 k = find (!(m > 0) | !(n > 0) | isnan (x));
46 if (any (k))
47 cdf(k) = NaN;
48 endif
49
50 k = find ((x == Inf) & (m > 0) & (n > 0));
51 if (any (k))
52 cdf(k) = 1;
53 endif
54
55 k = find ((x > 0) & (x < Inf) & (m > 0) & (n > 0));
56 if (any (k))
57 if (isscalar (m) && isscalar (n))
58 cdf(k) = 1 - betainc (1 ./ (1 + m .* x(k) ./ n), n / 2, m / 2);
59 else
60 cdf(k) = 1 - betainc (1 ./ (1 + m(k) .* x(k) ./ n(k)), n(k) / 2,
61 m(k) / 2);
62 endif
63 endif
64
65endfunction