]> Creatis software - CreaPhase.git/blob - octave_packages/m/statistics/tests/run_test.m
update packages
[CreaPhase.git] / octave_packages / m / statistics / tests / run_test.m
1 ## Copyright (C) 1995-2012 Friedrich Leisch
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} {[@var{pval}, @var{chisq}] =} run_test (@var{x})
21 ## Perform a chi-square test with 6 degrees of freedom based on the
22 ## upward runs in the columns of @var{x}.  Can be used to test whether
23 ## @var{x} contains independent data.
24 ##
25 ## The p-value of the test is returned in @var{pval}.
26 ##
27 ## If no output argument is given, the p-value is displayed.
28 ## @end deftypefn
29
30 ## Author: FL <Friedrich.Leisch@ci.tuwien.ac.at>
31 ## Description: Run test for independence
32
33 function [pval, chisq] = run_test (x)
34
35   if (nargin != 1)
36     print_usage ();
37   endif
38
39   A = [4529.4,  9044.9, 13568,  18091,  22615,  27892;
40        9044.4, 18097,   27139,  36187,  45234,  55789;
41       13568,   27139,   40721,  54281,  67852,  83685;
42       18091,   36187,   54281,  72414,  90470, 111580;
43       22615,   45234,   67852,  90470, 113262, 139476;
44       27892,   55789,   83685, 111580, 139476, 172860];
45
46   b = [1/6; 5/24; 11/120; 19/720; 29/5040; 1/840];
47
48   n = rows (x);
49   r = run_count (x, 6) - n * b * ones (1, columns(x));
50
51   chisq = diag (r' * A * r)' / n;
52   pval  = chi2cdf (chisq, 6);
53
54   if (nargout == 0)
55     printf("pval: %g\n", pval);
56   endif
57
58 endfunction