# How is the signed rank statistic defined in Matlab?

1. Given a sequence of sample points $X_1, \dots, X_n$, I am trying to find a Matlab function to

• compute the signed rank statistic defined as $$\sum_{i=1}^n sign(X_i) r_i$$ where $r_i$ is the rank of $|X_i|$ in $|X_1|, \dots, |X_n|$, and $sign(X_i)$ returns $1$ if $X_i >0$ and $-1$ if $X_i <0$.

• and also to compute the p-value of this signed rank statistic.

2. The function I suspect to be relevant is signrank in Matlab. Matlab signrank function takes the minimum between the sum of the ranks of positive differences and the sum of the ranks of negative differences. In the implementation of signrank function

% Compute signed rank statistic (most extreme version)
w = sum(tierank(neg));
w = min(w, n*(n+1)/2-w);

Questions:

1. I was wondering why Matlab signrank function takes the minimum between the sum of the ranks of positive differences and the sum of the ranks of negative differences? I checked the following references listed in the source file of signrank.m, but haven't found them taking the minimum as the signed rank statistic.

%   References:
%      [1] Hollander, M. and D. A. Wolfe.  Nonparametric Statistical
%          Methods. Wiley, 1973.
%      [2] Gibbons, J.D.  Nonparametric Statistical Inference,
%          2nd ed.  M. Dekker, 1985.

2. Is the p value provided by Matlab signrank function, same as the p value I want?

Thanks and regards!