%Van Der Waerden Rank Correlation
% Rabbits Example
%
x=[1848 1532 1460 1947 1810 1718 1686 1617 ...
               1724 1873 1928 2226 1708 1605 1822];
y=[1738 1440 1388 1756 1692 1629 1583 1499 ...
               1596 1794 1785 2044 1602 1491 1702];

n=15

Rx = ranks(x); Ry=ranks(y); Rz=1:n;
zx=norminv(Rx/(n+1));
zy=norminv(Ry/(n+1));
zz=norminv(Rz/(n+1));
rhovdw = sum(zx .* zy)/sum(zz.^2)  % 0.9714

var = 1/(n-1) * sum(zz.^2)^2   %7.9773

pval = 2 * normcdf(-abs(rhovdw), sqrt(var))  %1.4719e-04