1 ## Copyright (C) 2006, 2007 Arno Onken <asnelt@asnelt.org>
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function File} {[@var{mn}, @var{v}] =} fstat (@var{m}, @var{n})
18 ## Compute mean and variance of the F distribution.
20 ## @subheading Arguments
24 ## @var{m} is the first parameter of the F distribution. The elements
25 ## of @var{m} must be positive
28 ## @var{n} is the second parameter of the F distribution. The
29 ## elements of @var{n} must be positive
31 ## @var{m} and @var{n} must be of common size or one of them must be scalar
33 ## @subheading Return values
37 ## @var{mn} is the mean of the F distribution. The mean is undefined for
38 ## @var{n} not greater than 2
41 ## @var{v} is the variance of the F distribution. The variance is undefined
42 ## for @var{n} not greater than 4
45 ## @subheading Examples
51 ## [mn, v] = fstat (m, n)
55 ## [mn, v] = fstat (m, 5)
59 ## @subheading References
63 ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics
64 ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC,
68 ## Athanasios Papoulis. @cite{Probability, Random Variables, and Stochastic
69 ## Processes}. McGraw-Hill, New York, second edition, 1984.
73 ## Author: Arno Onken <asnelt@asnelt.org>
74 ## Description: Moments of the F distribution
76 function [mn, v] = fstat (m, n)
83 if (! isempty (m) && ! ismatrix (m))
84 error ("fstat: m must be a numeric matrix");
86 if (! isempty (n) && ! ismatrix (n))
87 error ("fstat: n must be a numeric matrix");
90 if (! isscalar (m) || ! isscalar (n))
91 [retval, m, n] = common_size (m, n);
93 error ("fstat: m and n must be of common size or scalar");
99 v = (2 .* (n .^ 2) .* (m + n - 2)) ./ (m .* ((n - 2) .^ 2) .* (n - 4));
101 # Continue argument check
102 k = find (! (m > 0) | ! (m < Inf) | ! (n > 2) | ! (n < Inf));
108 k = find (! (n > 4));
118 %! [mn, v] = fstat (m, n);
119 %! expected_mn = [1.6667, 1.5000, 1.4000, 1.3333, 1.2857, 1.2500];
120 %! expected_v = [22.2222, 6.7500, 3.4844, 2.2222, 1.5869, 1.2153];
121 %! assert (mn, expected_mn, 0.001);
122 %! assert (v, expected_v, 0.001);
126 %! [mn, v] = fstat (m, 5);
127 %! expected_mn = [1.6667, 1.6667, 1.6667, 1.6667, 1.6667, 1.6667];
128 %! expected_v = [22.2222, 13.8889, 11.1111, 9.7222, 8.8889, 8.3333];
129 %! assert (mn, expected_mn, 0.001);
130 %! assert (v, expected_v, 0.001);