3200
|
1 ## Copyright (C) 1995, 1996, 1997 Friedrich Leisch |
3426
|
2 ## |
3922
|
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 |
3200
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
3426
|
9 ## |
3922
|
10 ## Octave is distributed in the hope that it will be useful, but |
3200
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3426
|
13 ## General Public License for more details. |
|
14 ## |
3200
|
15 ## You should have received a copy of the GNU General Public License |
3922
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
3200
|
19 |
3454
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {[@var{pval}, @var{chisq}] =} run_test (@var{x}) |
|
22 ## Perform a chi-square test with 6 degrees of freedom based on the |
|
23 ## upward runs in the columns of @var{x}. Can be used to test whether |
|
24 ## @var{x} contains independent data. |
3200
|
25 ## |
3454
|
26 ## The p-value of the test is returned in @var{pval}. |
3200
|
27 ## |
3454
|
28 ## If no output argument is given, the p-value is displayed. |
|
29 ## @end deftypefn |
3426
|
30 |
3456
|
31 ## Author: FL <Friedrich.Leisch@ci.tuwien.ac.at> |
|
32 ## Description: Run test for independence |
3426
|
33 |
3200
|
34 function [pval, chisq] = run_test (x) |
|
35 |
|
36 if (nargin != 1) |
|
37 usage ("run_test (x)"); |
|
38 endif |
|
39 |
3238
|
40 A = [4529.4, 9044.9, 13568, 18091, 22615, 27892; |
|
41 9044.4, 18097, 27139, 36187, 45234, 55789; |
|
42 13568, 27139, 40721, 54281, 67852, 83685; |
|
43 18091, 36187, 54281, 72414, 90470, 111580; |
|
44 22615, 45234, 67852, 90470, 113262, 139476; |
|
45 27892, 55789, 83685, 111580, 139476, 172860]; |
3200
|
46 |
|
47 b = [1/6; 5/24; 11/120; 19/720; 29/5040; 1/840]; |
3426
|
48 |
3200
|
49 n = rows (x); |
|
50 r = run_count (x, 6) - n * b * ones (1, columns(x)); |
|
51 |
|
52 chisq = diag (r' * A * r)' / n; |
|
53 pval = chisquare_cdf (chisq, 6); |
3426
|
54 |
3200
|
55 if (nargout == 0) |
3456
|
56 printf("pval: %g\n", pval); |
3200
|
57 endif |
3426
|
58 |
3200
|
59 endfunction |