randsign(diffs [,trials:n]), REAL vector diffs, positive integer n |

randsign(diffs) computes sum(s_i * diffs_i) for all 2^length(diffs) possible combinations of signs s_i and returns these as a REAL vector. randsign(diffs,trials:n) samples from the distribution of sum(s_i * diffs_i) based on n sets of random signs. This is appropriate when diffs is long, as 2^length(diffs) grows quickly!! You can use the results of randsign to compute p-values for the randomization equivalent of the paired t-test by finding the fraction of the total differences based on random signs as extreme or more extreme than the observed total difference for the two groups. Examples: Cmd> x1 <- vector(1,4,2,4,6,3,7) # data set 1 Cmd> x2 <- vector(3,5,3,6,2,9,8) # data set 2 Cmd> diffs <- x2-x1 Cmd> diffs # the differences (1) 2 1 1 2 -4 (6) 6 1 Cmd> sum(diffs) # observed total difference (1) 9 Cmd> out <- randsign(diffs) # all differences with random signs Cmd> stemleaf(out) 1 -1s|7 4 -1f|555 9 -1t|33333 16 -1*|1111111 24 -0.|99999999 32 -0s|77777777 41 -0f|555555555 52 -0t|33333333333 64 -0*|111111111111 64 +0*|111111111111 52 +0t|33333333333 41 +0f|555555555 32 +0s|77777777 24 +0.|99999999 16 1*|1111111 9 1t|33333 4 1f|555 1 1s|7 1*|1 represents 11 Leaf digit unit = 1 Cmd> sum(out >= 9)/128 # one sided randomization p-value (1) 0.1875 See also randt(), randt2().

Gary Oehlert 2003-01-15