1 ## Copyright (C) 1995-2012 Friedrich Leisch
3 ## This file is part of Octave.
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.
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.
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/>.
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.
25 ## The p-value of the test is returned in @var{pval}.
27 ## If no output argument is given, the p-value is displayed.
30 ## Author: FL <Friedrich.Leisch@ci.tuwien.ac.at>
31 ## Description: Run test for independence
33 function [pval, chisq] = run_test (x)
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];
46 b = [1/6; 5/24; 11/120; 19/720; 29/5040; 1/840];
49 r = run_count (x, 6) - n * b * ones (1, columns(x));
51 chisq = diag (r' * A * r)' / n;
52 pval = chi2cdf (chisq, 6);
55 printf("pval: %g\n", pval);