Mercurial > octave-nkf
annotate scripts/statistics/tests/wilcoxon_test.m @ 20266:83792dd9bcc1
Use in-place operators in m-files where possible.
* scripts/audio/@audioplayer/set.m, scripts/audio/@audiorecorder/set.m,
scripts/audio/mu2lin.m, scripts/elfun/cosd.m, scripts/general/del2.m,
scripts/general/profexplore.m, scripts/general/quadl.m, scripts/general/rat.m,
scripts/general/rotdim.m, scripts/help/get_first_help_sentence.m,
scripts/help/private/__strip_html_tags__.m, scripts/image/cubehelix.m,
scripts/io/textread.m, scripts/linear-algebra/duplication_matrix.m,
scripts/linear-algebra/housh.m, scripts/linear-algebra/krylov.m,
scripts/linear-algebra/logm.m, scripts/linear-algebra/normest.m,
scripts/linear-algebra/onenormest.m, scripts/optimization/fminsearch.m,
scripts/optimization/lsqnonneg.m, scripts/optimization/qp.m,
scripts/plot/appearance/annotation.m, scripts/plot/appearance/axis.m,
scripts/plot/appearance/legend.m, scripts/plot/appearance/specular.m,
scripts/plot/draw/colorbar.m, scripts/plot/draw/hist.m,
scripts/plot/draw/plotmatrix.m, scripts/plot/draw/private/__stem__.m,
scripts/plot/util/__actual_axis_position__.m,
scripts/plot/util/__gnuplot_drawnow__.m, scripts/plot/util/findobj.m,
scripts/plot/util/print.m, scripts/plot/util/private/__go_draw_axes__.m,
scripts/plot/util/private/__print_parse_opts__.m, scripts/plot/util/rotate.m,
scripts/polynomial/pchip.m, scripts/polynomial/polyaffine.m,
scripts/polynomial/polyder.m, scripts/polynomial/private/__splinefit__.m,
scripts/polynomial/residue.m, scripts/signal/arch_fit.m,
scripts/signal/arch_rnd.m, scripts/signal/bartlett.m,
scripts/signal/blackman.m, scripts/signal/freqz.m, scripts/signal/hamming.m,
scripts/signal/hanning.m, scripts/signal/spectral_adf.m,
scripts/signal/spectral_xdf.m, scripts/signal/stft.m,
scripts/sparse/bicgstab.m, scripts/sparse/cgs.m,
scripts/sparse/private/__sprand_impl__.m, scripts/sparse/qmr.m,
scripts/sparse/sprandsym.m, scripts/sparse/svds.m, scripts/specfun/legendre.m,
scripts/special-matrix/gallery.m, scripts/statistics/base/gls.m,
scripts/statistics/models/logistic_regression.m,
scripts/statistics/tests/kruskal_wallis_test.m,
scripts/statistics/tests/manova.m, scripts/statistics/tests/wilcoxon_test.m,
scripts/time/datevec.m:
Use in-place operators in m-files where possible.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 26 May 2015 21:07:42 -0700 |
parents | d9341b422488 |
children |
rev | line source |
---|---|
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1 ## Copyright (C) 1995-2015 Kurt Hornik |
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{z}] =} wilcoxon_test (@var{x}, @var{y}, @var{alt}) | |
21 ## For two matched-pair sample vectors @var{x} and @var{y}, perform a | |
20209
d9341b422488
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
22 ## Wilcoxon signed-rank test of the null hypothesis |
d9341b422488
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
23 ## PROB (@var{x} > @var{y}) == 1/2. |
d9341b422488
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
24 ## |
d9341b422488
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
25 ## Under the null, the test statistic @var{z} approximately follows a |
d9341b422488
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
26 ## standard normal distribution when @var{n} > 25. |
6701 | 27 ## |
12973
b80b18f537ca
doc: Correct various Texinfo warnings about incorrect use of macros.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
28 ## @strong{Caution:} This function assumes a normal distribution for @var{z} |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
29 ## and thus is invalid for @var{n} @leq{} 25. |
3200 | 30 ## |
20209
d9341b422488
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
31 ## With the optional argument string @var{alt}, the alternative of interest |
d9341b422488
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
32 ## can be selected. If @var{alt} is @qcode{"!="} or @qcode{"<>"}, the null |
d9341b422488
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
33 ## is tested against the two-sided alternative |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
34 ## PROB (@var{x} > @var{y}) != 1/2. If alt is @qcode{">"}, the one-sided |
20209
d9341b422488
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
35 ## alternative PROB (@var{x} > @var{y}) > 1/2 is considered. Similarly for |
d9341b422488
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
36 ## @qcode{"<"}, the one-sided alternative PROB (@var{x} > @var{y}) < 1/2 is |
d9341b422488
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
37 ## considered. The default is the two-sided case. |
3200 | 38 ## |
3454 | 39 ## The p-value of the test is returned in @var{pval}. |
3426 | 40 ## |
3200 | 41 ## If no output argument is given, the p-value of the test is displayed. |
3454 | 42 ## @end deftypefn |
3200 | 43 |
5428 | 44 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
3456 | 45 ## Description: Wilcoxon signed-rank test |
3426 | 46 |
3200 | 47 function [pval, z] = wilcoxon_test (x, y, alt) |
3426 | 48 |
6701 | 49 if (nargin < 2 || nargin > 3) |
6046 | 50 print_usage (); |
3200 | 51 endif |
3426 | 52 |
4030 | 53 if (! (isvector (x) && isvector (y) && (length (x) == length (y)))) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
54 error ("wilcoxon_test: X and Y must be vectors of the same length"); |
3200 | 55 endif |
56 | |
57 n = length (x); | |
58 x = reshape (x, 1, n); | |
59 y = reshape (y, 1, n); | |
60 d = x - y; | |
20266
83792dd9bcc1
Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents:
20209
diff
changeset
|
61 d = d(find (d != 0)); |
3200 | 62 n = length (d); |
6701 | 63 if (n > 25) |
3200 | 64 r = ranks (abs (d)); |
20266
83792dd9bcc1
Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents:
20209
diff
changeset
|
65 z = sum (r(find (d > 0))); |
3200 | 66 z = ((z - n * (n + 1) / 4) / sqrt (n * (n + 1) * (2 * n + 1) / 24)); |
67 else | |
6701 | 68 error ("wilcoxon_test: implementation requires more than 25 different pairs"); |
3200 | 69 endif |
70 | |
71 cdf = stdnormal_cdf (z); | |
3426 | 72 |
3200 | 73 if (nargin == 2) |
74 alt = "!="; | |
75 endif | |
76 | |
5443 | 77 if (! ischar (alt)) |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
78 error ("wilcoxon_test: ALT must be a string"); |
3200 | 79 elseif (strcmp (alt, "!=") || strcmp (alt, "<>")) |
80 pval = 2 * min (cdf, 1 - cdf); | |
81 elseif (strcmp (alt, ">")) | |
82 pval = 1 - cdf; | |
83 elseif (strcmp (alt, "<")) | |
84 pval = cdf; | |
85 else | |
3456 | 86 error ("wilcoxon_test: option %s not recognized", alt); |
3200 | 87 endif |
88 | |
89 if (nargout == 0) | |
3456 | 90 printf (" pval: %g\n", pval); |
3200 | 91 endif |
3426 | 92 |
3200 | 93 endfunction |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
94 |