Mercurial > hg > octave-lyh
annotate scripts/statistics/tests/run_test.m @ 17535:c12c688a35ed default tip lyh
Fix warnings
author | LYH <lyh.kernel@gmail.com> |
---|---|
date | Fri, 27 Sep 2013 17:43:27 +0800 |
parents | 1c89599167a6 |
children |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1 ## Copyright (C) 1995-2012 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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) 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 |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
3200 | 18 |
3454 | 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. | |
3200 | 24 ## |
3454 | 25 ## The p-value of the test is returned in @var{pval}. |
3200 | 26 ## |
3454 | 27 ## If no output argument is given, the p-value is displayed. |
28 ## @end deftypefn | |
3426 | 29 |
3456 | 30 ## Author: FL <Friedrich.Leisch@ci.tuwien.ac.at> |
31 ## Description: Run test for independence | |
3426 | 32 |
3200 | 33 function [pval, chisq] = run_test (x) |
34 | |
35 if (nargin != 1) | |
6046 | 36 print_usage (); |
3200 | 37 endif |
38 | |
3238 | 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]; | |
3200 | 45 |
46 b = [1/6; 5/24; 11/120; 19/720; 29/5040; 1/840]; | |
3426 | 47 |
3200 | 48 n = rows (x); |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
49 r = run_count (x, 6) - n * b * ones (1, columns (x)); |
3200 | 50 |
51 chisq = diag (r' * A * r)' / n; | |
10680
e00de2d5263c
Replace calls to obsolete chisquare_cdf with chi2cdf.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
52 pval = chi2cdf (chisq, 6); |
3426 | 53 |
3200 | 54 if (nargout == 0) |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
55 printf ("pval: %g\n", pval); |
3200 | 56 endif |
3426 | 57 |
3200 | 58 endfunction |
17346
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
59 |