1 /* copyright 2007 by Robert Dodier
2 * I release this file under the terms of the GNU General Public License.
6 file_search_maxima : cons ("./###.mac", file_search_maxima),
7 file_search_lisp : cons ("./###.lisp", file_search_lisp),
10 set_random_state (make_random_state (1234)), 0);
13 /* first some tests of the ranks function */
21 (foo : permutations ({1, 2, 3}),
22 is (equal (foo, map (ranks, foo))));
25 (foo : permutations ({1, 2, 3, 4}),
26 is (equal (foo, map (ranks, foo))));
29 (makelist (i, i, 1, 10),
30 foo : random_permutation (%%), is (equal (foo, ranks (foo))));
33 (makelist (i, i, 1, 20),
34 foo : random_permutation (%%), is (equal (foo, ranks (foo / 20))));
37 (makelist (i, i, 1, 50),
38 foo : random_permutation (%%), is (equal (foo, ranks (foo / 50.0))));
41 (makelist (i, i, 1, 100),
42 foo : random_permutation (%%), is (equal (foo, ranks (foo / 100b0))));
45 (makelist (i, i, 1, 32),
46 foo : random_permutation (%%),
47 makelist (i/32.0, i, 1, 32),
48 bar : permute (%%, foo),
49 is (equal (ranks (bar), inverse_permutation (foo))));
52 ranks ([4, 3, 2, 1, 1, 2, 3, 4]);
53 [15/2, 11/2, 7/2, 3/2, 3/2, 7/2, 11/2, 15/2];
55 ranks ([4, 1, 2, 3, 4]);
58 ranks ([1, 4, 3, 2, 1]);
61 float (ranks ([0.343750, 0.1250, 0.531250, 0.56250, 0.031250, 0.968750, 0.750,
62 0.218750, 0.68750, 0.1250]));
63 [5.0, 2.50, 6.0, 7.0, 1.0, 10.0, 9.0, 4.0, 8.0, 2.50];
65 float (ranks ([0.43750, 0.56250, 0.43750, 0.6250, 0.31250, 0.31250, 0.50,
66 0.31250, 0.50, 0.8750, 0.43750, 0.250, 0.93750, 0.68750, 0.6250, 0.250,
67 0.8750, 0.1250, 0.06250, 0.50]));
68 [9.0, 14.0, 9.0, 15.50, 6.0, 6.0, 12.0, 6.0, 12.0, 18.50, 9.0, 3.50, 20.0,
69 17.0, 15.50, 3.50, 18.50, 2.0, 1.0, 12.0];
71 float (ranks ([0.0, 0.43750, 0.68750, 0.18750, 0.250, 0.56250, 0.6250, 0.18750,
72 0.6250, 0.0, 0.8750, 0.18750, 0.0, 0.43750, 0.50, 0.6250, 0.250, 0.31250,
74 [2.0, 11.50, 18.0, 5.0, 7.50, 14.0, 16.0, 5.0, 16.0, 2.0, 19.0, 5.0, 2.0,
75 11.50, 13.0, 16.0, 7.50, 9.50, 9.50, 20.0];
77 float (ranks ([0.1250, 0.8750, 0.31250, 0.6250, 0.8750, 0.81250, 0.31250,
78 0.3750, 0.06250, 0.31250, 0.06250, 0.31250, 0.250, 0.750, 0.56250, 0.6250,
79 0.750, 0.93750, 0.750, 0.81250]));
80 [3.0, 18.50, 6.50, 11.50, 18.50, 16.50, 6.50, 9.0, 1.50, 6.50, 1.50, 6.50,
81 4.0, 14.0, 10.0, 11.50, 14.0, 20.0, 14.0, 16.50];
83 float (ranks ([0.250, 0.750, 0.93750, 0.250, 0.50, 0.56250, 0.8750, 0.1250,
84 0.0, 0.1250, 0.93750, 0.6250, 0.750, 0.6250, 0.0, 0.31250, 0.750, 0.1250,
86 [7.50, 15.50, 19.50, 7.50, 10.0, 11.0, 18.0, 4.50, 1.50, 4.50, 19.50, 12.50,
87 15.50, 12.50, 1.50, 9.0, 15.50, 4.50, 4.50, 15.50];
89 /* ranks applied to nonnumeric data; dunno if this is practical
90 * but in any case it should work the same.
93 (foo : random_permutation ([-1, 0, 0, 1, 1, 2, 2, 3, 3, 3, 4, 5, 5]),
94 bar : subst ([-1=a, 0=b, 1=c, 2=d, 3=e, 4=f, 5=g], foo),
95 is (equal (ranks (foo), ranks (bar))),
99 /* now for some tests of wilcoxon itself */
101 (set_random_state (make_random_state (1234)),
102 foo : random_matrix (20, 6),
103 foo [all, 4] : amatrixmap (lambda ([x, y], if x + y > 1.0 then 1 else 0), foo [all, 1], foo [all, 2]),
104 foo [all, 5] : amatrixmap (lambda ([x], if x > 0.5 then 1 else 0), foo [all, 3]),
105 foo [all, 6] : amatrixmap (lambda ([x], if x > 0.5 then 1 else 0), foo [all, 6]),
109 wilcoxon (foo [all, 1], foo [all, 4]);
112 wilcoxon (foo [all, 1], foo [all, 5]);
115 wilcoxon (foo [all, 1], foo [all, 6]);
118 wilcoxon (foo [all, 2], foo [all, 4]);
121 wilcoxon (foo [all, 2], foo [all, 5]);
124 wilcoxon (foo [all, 2], foo [all, 6]);
127 wilcoxon (foo [all, 3], foo [all, 4]);
130 wilcoxon (foo [all, 3], foo [all, 5]);
133 wilcoxon (foo [all, 3], foo [all, 6]);