Wolfram Alpha:

```Non Parametric Tests
--------------------

Up until now it has been assumed that the underlying distributions
from which the samples have been drawn is normally distributed
OR the sample sizes are big enough (typically greater than 30)
so that the central limit theorem applies (i.e. the means of
the samples follow a normal distribution). But what if these
assertions are not true - we are dealing with small sample sizes
and we know nothing about the parent population?  Enter non
parametric testing!   There are 6 non-parametric tests of
importance.

The Sign Test
-------------

This is used for testing hypotheses about the central tendency
of a non-parametric distribution.  It provides inferences about
the population median, η, rather than the population mean, μ.

H0:  η = η0
H1:  η < η0 or η > η0
η ≠ η0

Test statistic:

S = # of measurements < (or >) η0 (1 tailed)

= Larger of # of measurements < η0 and > η0 (2 tailed)

p value:  P(x ≥ S)  (1 tailed)
2P(x ≥ S)  (2 tailed)

Where x has a binomial distribution with n = p = 0.5.
P(x ≥ S) = Probability of S successes in n trials.

Reject H0 if p value ≤ α

Large Samples
------------

If n ≥ 30 we can use the normal approximation to the binomial.

Z = [(S - 0.5) - 0.5n]/0.5√n

Where 0.5 is the 'continuity correction', the mean, np = 0.5n
and the standard deviation is √(npq) =  √(n(0.5)(0.5)) = 0.5√n

Example:

Determine whether η is less than 1.00.

H0:  η = 1.00
H1:  η < 1.00

Test Results
------------
0.78
0.51
3.79
0.23
0.77
0.98
0.96
0.89

S = # of measurements < η

= 7

P(x ≥ 7) = Probability of 7 successes in 8 trials

= 1 - P(x ≤ 6)

= 1 - 0.965 from Binomial tables

= 0.035

Therefore, reject H0 at the α = 0.05 level.

The Wilcoxon Rank Sum (a.k.a The Mann-Whitney U Test)
-----------------------------------------------------

This is the non-parametric analog of the independent samples
t-test.

H0:  The 2 distributions D1 and D2 are identical.
H1:  D1 is shifted to the right of D2.
D1 is shifted to the left of D2.
D1 is shifted either to the left or the right of D2.

Test statistic:

Rank every observation as though they were all drawn from the
same population with Rank 1 being the lowest observation.
Assign ascending ranks to observation with the same value and
divide by the number of observations with the same value.

For example

Rank:          1    3    2    4    8    5    7    6    9   10

Observation:  1.1  2.3  2.1  3.3  4.2  3.3  4.0  3.3  4.4  5.2

=>             1    3    2    5*   8    5*   7    5*   9   10

* 3.3 => (4 + 5 + 6)/3 = 5

To find the test statstic we take the sum of the ranks for
the smaller sample size (or either if n1 = n2).

Use the Wilcoxon Rank Sum Tables to obtain the upper and lower
rejection regions, TU and TL.  n1 corresponds to columns and
n2 corresponds to rows.

Rejection region:

If n1 < n2:

T1 ≥ TU : T1 ≤ TL (1 tailed).

T1 ≥ TU or T1 ≤ TL (2 tailed).

If n2 < n1:

T2 ≥ TU : T2 ≤ TL (1 tailed).

T2 ≥ TU or T2 ≤ TL (2 tailed).

Large Samples
------------

If n1 ≥ 10 and n2 ≥ 10 we can use the Z statistic for the
hypthesis test.

T1 - (n1(n1 + n2 + 1))/2
Z =  -----------------------
√(n1n2(n1 + n2 + 1)/12)

Example:

Comparison of drug reaction times.

Drug A                     Drug B
Reaction Time   Rank       Reaction Time   Rank
-------------   ----       -------------   ----

1.96             4          2.11            6
2.24             7          2.43            9
1.71             2          2.07            5
2.41             8          2.71           11
1.62             1          2.50           10
1.93             3          2.84           12
2.88           13
--                         --
Rank Sum            25                         66
Sample Size, n       6                          7

H0:  The reaction times for A and B have the same
probability distribution.
H1:  The reaction times for A are shifted to the left
or right of the reaction times for B.

T1 = 25
T2 = 66

From the Wilcoxon Paired Difference Rank Sum Tables:

n1 = 6, n2 = 7, α = 0.05 => TL = 28 and TU = 56 (2 tailed)

Therefore, reject H0 at the α = 0.05 level because T1 (the
smaller sample size) falls in the rejection region.

t-test comparison:

The t-value is -2.9927. The 2 tailed p-value is 0.0122.
The result is significant at p < 0.05.

Note:  If we had a 1 tailed test with H1:  A is shifted to
the left of B then TL = 30 and TU = 54 (1 tailed) for α = 0.05.
In this case T1 is not in the rejection region so we would
accept H0.

Wilcoxon Paired Difference Signed Rank Test
-------------------------------------------

This is the non-parametric analog of the paired t-test.

H0:  The 2 distributions D1 and D2 are identical.
H1:  D1 is shifted to the right of D2.
D1 is shifted to the left of D2.
D1 is shifted either to the left or the right of D2.

Test statistic:

Calculate the ranks of the absolute values of the differences.
Rank every observation as though they were all drawn from the
same population with Rank 1 being the lowest observation.
Determine the sum of the ranks of the positive and negative
differences of the original measurements.  0 differences are
eliminated and n reduced accordingly.

Find T0 from the Wilcoxon Paired Difference Signed Rank
Tables with n = number of pairs.

Rejection region:

Consider the difference between 2 distributions D1 - D2.

1 tailed:

If D1 is to the right of D2, more positive differences should
occur.  Therefore, T+ > T- and the rejection criterion is
T- ≤ T0.

If D1 is to the left of D2, more negative differences should
occur.  Therefore, T- > T+ and the rejection criterion is
T+ ≤ T0

2 tailed:

If D1 is shifted to the left or right of D2 then the rejection
criterion is the smaller of T- or T+ ≤ T0.

Large Samples
------------

If n1 ≥ 10 and n2 ≥ 10 we can use the Z statistic for the
hypthesis test.

T1 - n(n + 1)/4
Z =  ---------------------
√(n(n + 1)(2n + 1)/24)

Example:

Before and after test.

A    B    (A - B)  |A - B|   Rank   Modified Rank
--   --   -------  -------   ----   ------------
12    8      4        4        4         4.5
16   10      6        6        7         7
8     9     -1        1        1         1
10    8      2        2        2         2
19   12      7        7        8         8
14   17     -3        3        3         3
12    4      8        8        9         9
10    6      4        4        5         4.5
12   17     -5        5        6         6
16    4     12       12        10        10

H0:  A and B have the same probability distribution.
H1:  A and B have different probability distributions.

T- = 10
T+ = 45

From the Wilcoxon Paired Difference Signed Rank Tables:

n = 10, α = 0.05  => T0 = 8 (2 tailed)

Therefore, accept H0 at the α = 0.05 level because T- is
not in the rejection region.

t-test comparison:

The t-value is 2.0466. The 2 tailed p-value is 0.0710.
The result is not significant at p < 0.05.

Note:  If we had a 1 tailed test with H1:  A is shifted to
the left of B then T0 = 11 for α = 0.05.  In this case T+
is not in the rejection region so we would again accept H0.

Kruskal-Wallis H Test
---------------------

This is the non-parametric analog of the ANOVA test for a
completely randomized design.

H0:  The distributions Dk are identical.
H1:  At least 2 of the distributions differ in location.

Test statistic:
_    _
H = (12/n(n + 1))Σnj(Rj - R)2

or, equivalently:

H = (12/n(n + 1))ΣRj2/nj - 3(n + 1)

Where,

Rj = Rank sum for sample j.

nj = number of measurements in jth sample.
_
Rj = Rj/nj = mean rank sum for sample j.
_
R = (n + 1)/2 = mean of all ranks.

n = n1 + n2 + ... + nk = total sample size.

= number of ranks.

Rejection region:

H > χα2 with k - 1 df

Example:

Comparison of unoccupied bed space for 3 different hospitals
on 10 successive days.

H1              H2             H3
Beds   Rank     Beds   Rank    Beds  Rank
----   ----     ----   ----    ----  ----
6      5        34     25      13     5
38     27        28     19      35    26
3      2        42     30      19    15
17     13        13     9.5      4     3
11      8        40     29      29    20
30     21        31     22       0     1
15     11         9      7       7     6
16     12        32     23      33    24
25     17        39     28      18    14
5      4        27     18      24    16
---              -----         -----
Rank suns         120              210.5         134.5

H0:  Distributions for all 3 hospitals are the same.
H1:  At least 2 of the hospitals have distributions
that differ in location.

n1 = n2 = n3 = 10
_
R1 = 120/10 = 12.0
_
R2 = 210.5/10 = 21.05
_
R3 = 134.5/10 = 13.45
_
R = (30 + 1)/2 = 15.5

=> H = 6.097

From the χ2 tables with α = 0.05 and (k - 1) = 2 df we get

χ0.052 = 5.991

Since H > 5.991 we can reject H0.

Friedman F Test
---------------

This is the non-parametric analog of the ANOVA test for a
randomized block design.

Test statistic:
_    _
F = (12b/k(k + 1))Σ(Rj - R)2

or, equivalently:

F = (12/bk(k + 1))ΣRj2 - 3b(k + 1)

Where,

b = number of blocks.

k = number of treatments.

nj = number of measurements in jth sample.

Rj = Rank sum for jth treatment where the rank of each
measurement is found relative to its position in its
own block (the measurements can are ranked in blocks).
_
Rj = Rj/nj = mean rank sum for sample j.
_
R = (n + 1)/2 = mean of all ranks where n = number of ranks.

Rejection region:

F > χα2 with k - 1 df

Example:

Drug reaction times.

Block   Drug A  Rank   Drug B   Rank   Drug C   Rank
-----   ------  ----   ------   ----   ------   ----
1      1.21    1      1.48     2      1.56     3
2      1.63    1      1.85     2      2.01     3
3      1.42    1      2.06     3      1.70     2
4      2.43    2      1.98     1      2.64     3
5      1.16    1      1.27     2      1.48     3
6      1.94    1      2.44     2      2.81     3
--              --              --
Rank sums        7              12              17

H0:  The reaction times for A, B and C have the same
probability distributions.
H1:  At least 2 of the drugs have reaction times whose
distributions differ by location.

k = 3
b = 9
_
R1 = 7/6 = 1.167
_
R2 = 12/6 = 2.0
_
R3 = 17/6 = 2.833
_
R = (3 + 1)/2 = 2.0

=> F = 8.33

From the χ2 tables with α = 0.05 and (k - 1) = 2 df we get

χ0.052 = 5.991

Spearman's Rank Correlation
---------------------------

This is the non-parametric analog of Pearson correlation.

SSuv
rS  = ----------
√(SSuuSSvv)

Where:
_       _
SSuv = Σ(ui - u)(vi - v) ≡ ΣuiΣvi/n
_
SSuu = Σ(ui - u)2 ≡ Σ(ui)2 - (Σui)2/n
_
SSvv = Σ(vi - v)2 ≡ Σ(vi)2 - (Σvi)2/n

n is the number of data points.

ui is the rank of the ith observation in sample 1.

vi is the rank of the jth observation in sample 2.

In this case the independent variables are ranked separately.

Example:

Cigarettes smoked per day vesus birth weight.

Cigs/day   Rank    Weight     Rank
--------   ----    ------     ----
12         1       7.7        2
15         2       8.1        3
35         5       6.9        1
21         4       8.2        4.5
20         3       8.2        4.5

SSuu = 10

SSvv = 9.5

SSuv = -0.5

rS = -0.5/√(10*9.5) = -0.051```