---
title: "SignedRankTest"
language: "en"
type: "Symbol"
summary: "SignedRankTest[data] tests whether the median of data is zero. SignedRankTest[{data1, data2}] tests whether the median of data1 - data2 is zero. SignedRankTest[dspec, \\[Mu] 0] tests a location measure against \\[Mu] 0. SignedRankTest[dspec, \\[Mu] 0,  property] returns the value of  property."
keywords: 
- hypothesis testing
- test of location
- mean test
- mean difference test
- equal mean test
- test of shift
- Oja signed rank test
- signed rank test
- Wilcoxon signed rank test
- wilcoxon mann whitney test
- wilcoxon rank sum test
- rank sum test
- Wilcoxon-Mann-Whitney U test
- nonparametric test
- median difference
- equal medians
canonical_url: "https://reference.wolfram.com/language/ref/SignedRankTest.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Hypothesis Tests"
    link: "https://reference.wolfram.com/language/guide/HypothesisTests.en.md"
related_functions: 
  - 
    title: "HypothesisTestData"
    link: "https://reference.wolfram.com/language/ref/HypothesisTestData.en.md"
  - 
    title: "LocationTest"
    link: "https://reference.wolfram.com/language/ref/LocationTest.en.md"
  - 
    title: "LocationEquivalenceTest"
    link: "https://reference.wolfram.com/language/ref/LocationEquivalenceTest.en.md"
  - 
    title: "VarianceTest"
    link: "https://reference.wolfram.com/language/ref/VarianceTest.en.md"
  - 
    title: "VarianceEquivalenceTest"
    link: "https://reference.wolfram.com/language/ref/VarianceEquivalenceTest.en.md"
  - 
    title: "DistributionFitTest"
    link: "https://reference.wolfram.com/language/ref/DistributionFitTest.en.md"
  - 
    title: "MannWhitneyTest"
    link: "https://reference.wolfram.com/language/ref/MannWhitneyTest.en.md"
  - 
    title: "PairedTTest"
    link: "https://reference.wolfram.com/language/ref/PairedTTest.en.md"
  - 
    title: "PairedZTest"
    link: "https://reference.wolfram.com/language/ref/PairedZTest.en.md"
  - 
    title: "SignTest"
    link: "https://reference.wolfram.com/language/ref/SignTest.en.md"
  - 
    title: "TTest"
    link: "https://reference.wolfram.com/language/ref/TTest.en.md"
  - 
    title: "ZTest"
    link: "https://reference.wolfram.com/language/ref/ZTest.en.md"
---
# SignedRankTest

SignedRankTest[data] tests whether the median of data is zero. 

SignedRankTest[{data1, data2}] tests whether the median of data1 - data2 is zero.

SignedRankTest[dspec, μ0] tests a location measure against μ0.

SignedRankTest[dspec, μ0, "property"] returns the value of "property".

## Details and Options

* ``SignedRankTest`` tests the null hypothesis $H_0$ against the alternative hypothesis $H_a$:

|                |                                                  |                                                      |
| -------------- | ------------------------------------------------ | ---------------------------------------------------- |
|                | $H_0$              | $H_a$                  |
| data           | $\mu =\mu _0$      | $\mu \neq \mu _0$      |
| {data1, data2} | $\mu _{12}=\mu _0$ | $\mu _{12}\neq \mu _0$ |

* where ``μ`` is the population median for ``data`` and ``μ12`` is the median of the paired differences of the two datasets $\text{\textit{data}}_1-\text{\textit{data}}_2$.

* By default, a probability value or $p$-value is returned.

* A small $p$-value suggests that it is unlikely that $H_0$ is true.

* The data in ``dspec`` can be univariate ``{x1, x2, …}`` or multivariate ``{{x1, y1, …}, {x2, y2, …}, …}``.

* If two samples are given, they must be of equal length.

* The argument ``μ0`` can be a real number or a real vector with length equal to the dimension of the data.

* ``SignedRankTest`` assumes that the data is symmetric about the median in the univariate case and elliptically symmetric in the multivariate case. For this reason, ``SignedRankTest`` is also a test of means.

* ``SignedRankTest[dspec, μ0, "HypothesisTestData"]`` returns a ``HypothesisTestData`` object ``htd`` that can be used to extract additional test results and properties using the form ``htd["property"]``.

* ``SignedRankTest[dspec, μ0, "property"]`` can be used to directly give the value of ``"property"``.

* Properties related to the reporting of test results include:

|                       |                                                                                 |
| --------------------- | ------------------------------------------------------------------------------- |
| "DegreesOfFreedom"    | the degrees of freedom used in a test                                           |
| "PValue"              | list of $p$-values                                |
| "PValueTable"         | formatted table of $p$-values                     |
| "ShortTestConclusion" | a short description of the conclusion of a test                                 |
| "TestConclusion"      | a description of the conclusion of a test                                       |
| "TestData"            | list of pairs of test statistics and $p$-values   |
| "TestDataTable"       | formatted table of $p$-values and test statistics |
| "TestStatistic"       | list of test statistics                                                         |
| "TestStatisticTable"  | formatted table of test statistics                                              |

* The ``SignedRankTest`` is a more powerful alternative to the ``SignTest``.

* For univariate samples, ``SignedRankTest`` performs the Wilcoxon signed rank test for medians of paired samples. A correction for ties is applied for permutation-based $p$-values. By default, the test statistic is corrected for continuity and an asymptotic result is returned.

* For multivariate samples, ``SignedRankTest`` performs an affine invariant test for paired samples using standardized spatial signed ranks. The test statistic is assumed to follow a ``ChiSquareDistribution[dim]`` where ``dim`` is the dimension of the data.

* The following options can be used:

|                        |           |                                                                          |
| ---------------------- | --------- | ------------------------------------------------------------------------ |
| AlternativeHypothesis  | "Unequal" | the inequality for the alternative hypothesis                            |
| MaxIterations          | Automatic | max iterations for multivariate median tests                             |
| Method                 | Automatic | the method to use for computing $p$-values |
| SignificanceLevel      | 0.05      | cutoff for diagnostics and reporting                                     |
| VerifyTestAssumptions  | Automatic | what assumptions to verify                                               |

* For the ``SignedRankTest``, a cutoff $\alpha$ is chosen such that $H_0$ is rejected only if $p<\alpha$. The value of $\alpha$ used for the ``"TestConclusion"`` and ``"ShortTestConclusion"`` properties is controlled by the ``SignificanceLevel`` option. This value $\alpha$ is also used in diagnostic tests of assumptions including a test for symmetry. By default, $\alpha$ is set to ``0.05``.

* Named settings for ``VerifyTestAssumptions`` in ``SignedRankTest`` include:

"Symmetry"	verify that all data is symmetric

---

## Examples (40)

### Basic Examples (4)

Test whether the median of a population is zero:

```wl
In[1]:= data = RandomVariate[NormalDistribution[], 100];

In[2]:= DistributionChart[data]

Out[2]= [image]

In[3]:= SignedRankTest[data]

Out[3]= 0.152126
```

---

Compare the median difference for paired data to a particular value:

```wl
In[1]:= data = RandomVariate[MultinormalDistribution[{2, 0}, {{1, .75}, {.75, 1}}], 1000];

In[2]:= BoxWhiskerChart[Transpose@data]

Out[2]= [image]

In[3]:= SignedRankTest[Transpose@data, 2]

Out[3]= 0.995939
```

Report the test results in a table:

```wl
In[4]:= SignedRankTest[Transpose@data, 2, "TestDataTable"]

Out[4]=
| ""            | "Statistic" | "P‐Value" |
| :------------ | :---------- | :-------- |
| "Signed‐Rank" | 250297.     | 0.995939  |
```

---

Test whether the spatial median of a multivariate population is some value:

```wl
In[1]:= data = RandomVariate[MultinormalDistribution[{4, 5, 6}, IdentityMatrix[3]], 10^2];

In[2]:= SignedRankTest[data, {4, 5, 6}]

Out[2]= 0.145411
```

Compute the test statistic:

```wl
In[3]:= SignedRankTest[data, {4, 5, 6}, "TestStatistic"]

Out[3]= 5.38932
```

---

Create a ``HypothesisTestData`` object for repeated property extraction:

```wl
In[1]:= data = RandomVariate[StudentTDistribution[4], 100];

In[2]:= ℋ = SignedRankTest[data, Automatic, "HypothesisTestData"]

Out[2]=
HypothesisTestData[SignedRankTest, {CompressedData["«1170»"], "SampleToNull", 1, Rational[1, 20], {0, "Unequal", Automatic, Automatic}, Automatic, 
  {}}, {"Normality" -> 0, "EqualVariance" -> 0, "Symmetry" -> 0}]
```

A list of available properties:

```wl
In[3]:= ℋ["Properties"]

Out[3]= {"DegreesOfFreedom", "HypothesisTestData", "Properties", "PValue", "PValueTable", "ShortTestConclusion", "SignedRank", "TestConclusion", "TestData", "TestDataTable", "TestEntries", "TestStatistic", "TestStatisticTable"}
```

Extract a single property or a list of properties:

```wl
In[4]:= ℋ["TestData"]

Out[4]= {2621., 0.742639}

In[5]:= ℋ["TestDataTable", "PValue", "TestStatistic"]

Out[5]=
{| ""            | "Statistic" | "P‐Value" |
| :------------ | :---------- | :-------- |
| "Signed‐Rank" | 2621.       | 0.742639  |, 0.742639, 2621.}
```

### Scope (13)

#### Testing (10)

Test $H_0:$$\mu =0$ versus $H_a:$$\mu \neq 0$ :

```wl
In[1]:=
data1 = RandomVariate[NormalDistribution[0, 1], 500];
data2 = RandomVariate[NormalDistribution[3, 1], 500];
```

The $p$-values are typically large when the median is close to ``μ0`` :

```wl
In[2]:= SignedRankTest[data1]

Out[2]= 0.0327488
```

The $p$-values are typically small when the location is far from ``μ0`` :

```wl
In[3]:= SignedRankTest[data2]

Out[3]= 1.2685250602309246`*^-83
```

---

Using ``Automatic`` is equivalent to testing for a median of zero:

```wl
In[1]:= data = RandomVariate[NormalDistribution[0, 1], 500];

In[2]:= SignedRankTest[data, 0]

Out[2]= 0.752217

In[3]:= SignedRankTest[data, Automatic]

Out[3]= 0.752217
```

---

Test $H_0:$$\mu =3$ versus $H_a:$$\mu \neq 3$ :

```wl
In[1]:=
data1 = RandomVariate[NormalDistribution[3, 1], 500];
data2 = RandomVariate[NormalDistribution[0, 1], 500];
```

The $p$-values are typically large when median is close to ``μ0`` :

```wl
In[2]:= SignedRankTest[data1, 3]

Out[2]= 0.405548
```

The $p$-values are typically small when the location is far from ``μ0`` :

```wl
In[3]:= SignedRankTest[data2, 3]

Out[3]= 1.2685250602309246`*^-83
```

---

Test whether the median vector of a multivariate population is the zero vector:

```wl
In[1]:= data = RandomVariate[MultinormalDistribution[{.1, 0, -.5, 0}, IdentityMatrix[4]], 10^2];

In[2]:= SignedRankTest[data]

Out[2]= 4.954575224600739`*^-7
```

Alternatively, test against ``{0.1, 0, -.5, 0}`` :

```wl
In[3]:= SignedRankTest[data, {0.1, 0, -.5, 0}]

Out[3]= 0.102291
```

---

Test $H_0$$:\mu _1-\mu _2=0$ versus $H_a$$:\mu _1-\mu _2\neq 0$ :

```wl
In[1]:=
data1 = RandomVariate[NormalDistribution[0, 1], 100];
data2 = RandomVariate[NormalDistribution[1, 1], 100];
data3 = RandomVariate[NormalDistribution[0, 2], 100];
```

The $p$-values are generally small when the locations are not equal:

```wl
In[2]:= SignedRankTest[{data1, data2}, 0]

Out[2]= 5.733770393107215`*^-10
```

The $p$-values are generally large when the locations are equal:

```wl
In[3]:= SignedRankTest[{data1, data3}, 0]

Out[3]= 0.314555
```

---

Test $H_0$$:\mu _1-\mu _2=3$ versus $H_a$$:\mu _1-\mu _2\neq 3$ :

```wl
In[1]:=
data1 = RandomVariate[NormalDistribution[3, 1], 100];
data2 = RandomVariate[NormalDistribution[0, 1], 100];
```

The order of the datasets affects the test results:

```wl
In[2]:= SignedRankTest[{data1, data2}, 3]

Out[2]= 0.444255

In[3]:= SignedRankTest[{data2, data1}, 3]

Out[3]= 3.955911608899571`*^-18
```

---

Test whether the median difference vector of two multivariate populations is the zero vector:

```wl
In[1]:= data1 = RandomVariate[MultinormalDistribution[{.5, 0, -.5, 0}, IdentityMatrix[4]], 10^2];

In[2]:= data2 = RandomVariate[MultinormalDistribution[{-.5, 0, .5, 0}, IdentityMatrix[4]], 10^2];

In[3]:= SignedRankTest[{data1, data2}]

Out[3]= 5.7562468325158316`*^-11
```

Alternatively, test against ``{1, 0, -1, 0}`` :

```wl
In[4]:= SignedRankTest[{data1, data2}, {1, 0, -1, 0}]

Out[4]= 0.808417
```

---

Create a ``HypothesisTestData`` object for repeated property extraction:

```wl
In[1]:= data = RandomVariate[NormalDistribution[], {2, 10^4}];

In[2]:= ℋ = SignedRankTest[data, 0, "HypothesisTestData"];
```

The properties available for extraction:

```wl
In[3]:= ℋ["Properties"]

Out[3]= {"DegreesOfFreedom", "HypothesisTestData", "Properties", "PValue", "PValueTable", "ShortTestConclusion", "SignedRank", "TestConclusion", "TestData", "TestDataTable", "TestEntries", "TestStatistic", "TestStatisticTable"}
```

---

Extract some properties from a ``HypothesisTestData`` object:

```wl
In[1]:= data = RandomVariate[NormalDistribution[], {2, 10^4}];

In[2]:= ℋ = SignedRankTest[data, 0, "HypothesisTestData"];
```

The $p$-value and test statistic:

```wl
In[3]:= ℋ["PValue"]

Out[3]= 0.0722162

In[4]:= ℋ["TestStatistic"]

Out[4]= 2.4483494*^7
```

---

Extract any number of properties simultaneously:

```wl
In[1]:= data = RandomVariate[NormalDistribution[], {2, 10^4}];

In[2]:= ℋ = SignedRankTest[data, 0, "HypothesisTestData"];
```

The $p$-value and test statistic:

```wl
In[3]:= ℋ["PValue", "TestStatistic"]

Out[3]= {0.865568, 2.5051374*^7}
```

#### Reporting (3)

Tabulate the test results:

```wl
In[1]:= data = RandomVariate[NormalDistribution[], {2, 20}];

In[2]:= ℋ = SignedRankTest[data, 0, "HypothesisTestData"];

In[3]:= ℋ["TestDataTable"]

Out[3]=
| ""            | "Statistic" | "P‐Value" |
| :------------ | :---------- | :-------- |
| "Signed‐Rank" | 148.        | 0.112595  |
```

---

Retrieve the entries from a test table for customized reporting:

```wl
In[1]:= data = RandomVariate[NormalDistribution[], {1000, 25}];

In[2]:= res = Table[SignedRankTest[i, 0, "TestData", VerifyTestAssumptions -> None], {i, data}];

In[3]:= ListPlot[res, PlotStyle -> PointSize[Medium]]

Out[3]= [image]
```

---

Tabulate $p$-values or test statistics:

```wl
In[1]:= data = RandomVariate[NormalDistribution[], {2, 10^2}];

In[2]:= ℋ = SignedRankTest[data, 0, "HypothesisTestData"];

In[3]:= ℋ["PValueTable"]

Out[3]=
| ""            | "P‐Value" |
| :------------ | :-------- |
| "Signed‐Rank" | 0.763526  |
```

The $p$-value from the table:

```wl
In[4]:= ℋ["PValue"]

Out[4]= 0.763526

In[5]:= ℋ["TestStatisticTable"]

Out[5]=
| ""            | "Statistic" |
| :------------ | :---------- |
| "Signed‐Rank" | 2613.       |
```

The test statistic from the table:

```wl
In[6]:= ℋ["TestStatistic"]

Out[6]= 2613.
```

### Options (12)

#### AlternativeHypothesis (3)

A two-sided test is performed by default:

```wl
In[1]:= data = RandomVariate[NormalDistribution[], {2, 100}];
```

Test $H_0$$: \mu _1-\mu _2=0$ versus $H_a$$: \mu _1-\mu _2\neq 0$ :

```wl
In[2]:= SignedRankTest[data, 0, AlternativeHypothesis -> "Unequal"]

Out[2]= 0.375958

In[3]:= SignedRankTest[data, 0, AlternativeHypothesis -> Automatic]

Out[3]= 0.375958
```

---

Perform a two-sided test or a one-sided alternative:

```wl
In[1]:= data = RandomVariate[NormalDistribution[], {2, 100}];
```

Test $H_0:\mu =0$ versus $H_a:\mu \neq 0$ :

```wl
In[2]:= SignedRankTest[data, 0, AlternativeHypothesis -> "Unequal"]

Out[2]= 0.147267
```

Test $H_0:\mu \geq 0$ versus $H_a:\mu <0$ :

```wl
In[3]:= SignedRankTest[data, 0, AlternativeHypothesis -> "Less"]

Out[3]= 0.926845
```

Test $H_0:\mu \leq 0$ versus $H_a:\mu >0$ :

```wl
In[4]:= SignedRankTest[data, 0, AlternativeHypothesis -> "Greater"]

Out[4]= 0.0736333
```

---

Perform tests with one-sided alternatives when ``μ0`` is given:

```wl
In[1]:=
data1 = RandomVariate[NormalDistribution[2.9, 1], 1000];
data2 = RandomVariate[NormalDistribution[0, 1], 1000];

In[2]:= Mean[data1 - data2]

Out[2]= 2.88212
```

Test $H_0: \mu \geq 3$ versus $H_a: \mu <3$ :

```wl
In[3]:= SignedRankTest[{data1, data2}, 3, AlternativeHypothesis -> "Less"]

Out[3]= 0.00445705
```

Test $H_0: \mu \geq 2.9$ versus $H_a: \mu <2.9$ :

```wl
In[4]:= SignedRankTest[{data1, data2}, 2.9, AlternativeHypothesis -> "Less"]

Out[4]= 0.33818
```

#### MaxIterations (2)

Set the maximum number of iterations to use for multivariate tests:

```wl
In[1]:=
data1 = RandomVariate[BinormalDistribution[.5], 25];
data2 = RandomVariate[BinormalDistribution[.5], 25];
```

By default, 500 iterations are allowed:

```wl
In[2]:= SignedRankTest[{data1, data2}, Automatic, MaxIterations -> 500]

Out[2]= 0.367252

In[3]:= SignedRankTest[{data1, data2}, Automatic, MaxIterations -> Automatic]

Out[3]= 0.367252
```

---

Setting the maximum number of iterations may result in lack of convergence:

```wl
In[1]:=
BlockRandom[SeedRandom[2];
	data1 = RandomVariate[BinormalDistribution[.5], 25];
	data2 = RandomVariate[BinormalDistribution[.5], 25];]
```

The $p$-values are not equivalent:

```wl
In[2]:= SignedRankTest[{data1, data2}, Automatic, MaxIterations -> 1]
```

SignedRankTest::cvmit: Failed to converge to the requested accuracy or precision within 1 iterations.

```wl
Out[2]= 0.854572

In[3]:= SignedRankTest[{data1, data2}, Automatic, MaxIterations -> Automatic]

Out[3]= 0.862316
```

#### Method (4)

By default, $p$-values are computed using asymptotic test statistic distributions:

```wl
In[1]:= data = RandomVariate[NormalDistribution[], {2, 100}];

In[2]:= SignedRankTest[data, 0, Method -> Automatic]

Out[2]= 0.136995

In[3]:= SignedRankTest[data, 0, Method -> "Asymptotic"]

Out[3]= 0.136995
```

---

Permutation methods can be used:

```wl
In[1]:= data = RandomVariate[NormalDistribution[], {2, 35}];

In[2]:= SignedRankTest[data, 0, Method -> "Asymptotic"]

Out[2]= 0.58321

In[3]:= SignedRankTest[data, 0, Method -> "Permutation"]

Out[3]= 0.5808
```

---

Set the number of permutations to use:

```wl
In[1]:= data = RandomVariate[NormalDistribution[], {2, 35}];

In[2]:= SignedRankTest[data, 0, Method -> {"Permutation", "MonteCarloSamples" -> 10^3}]

Out[2]= 0.17

In[3]:= SignedRankTest[data, 0, Method -> {"Permutation", "MonteCarloSamples" -> 10^5}]

Out[3]= 0.18
```

By default, $10^4$ random permutations are used:

```wl
In[4]:= SignedRankTest[data, 0, Method -> {"Permutation", "MonteCarloSamples" -> 10^4}]

Out[4]= 0.18
```

---

Set the seed used for generating random permutations:

```wl
In[1]:= data = RandomVariate[NormalDistribution[], {2, 35}];

In[2]:= SignedRankTest[data, 0, Method -> {"Permutation", "RandomSeed" -> 0}]

Out[2]= 0.1174

In[3]:= SignedRankTest[data, 0, Method -> {"Permutation", "RandomSeed" -> 9}]

Out[3]= 0.1256
```

#### SignificanceLevel (1)

The significance level is used for ``"TestConclusion"`` and ``"ShortTestConclusion"`` :

```wl
In[1]:= BlockRandom[SeedRandom[1];data = RandomVariate[NormalDistribution[0, 1], {2, 100}]];

In[2]:= ℋ1 = SignedRankTest[data, .2, "HypothesisTestData", SignificanceLevel -> .05];

In[3]:= ℋ2 = SignedRankTest[data, .2, "HypothesisTestData", SignificanceLevel -> .001];

In[4]:= ℋ1["TestConclusion"]//TraditionalForm

Out[4]//TraditionalForm=
$$\text{The null hypothesis that }\text{the }\text{median}\text{ difference is }0.2 \text{is rejected at the }5.\text{ percent level }\text{based
on the }\text{Signed-Rank}\text{ test.}$$

In[5]:= ℋ2["TestConclusion"]//TraditionalForm

Out[5]//TraditionalForm=
$$\text{The null hypothesis that }\text{the }\text{median}\text{ difference is }0.2 \text{is not rejected at the }0.1\text{ percent level }\text{based
on the }\text{Signed-Rank}\text{ test.}$$

In[6]:= ℋ1["ShortTestConclusion"]

Out[6]= "Reject"

In[7]:= ℋ2["ShortTestConclusion"]

Out[7]= "Do not reject"
```

#### VerifyTestAssumptions (2)

Diagnostics can be controlled as a group using ``All`` or ``None`` :

```wl
In[1]:=
data1 = RandomVariate[ExponentialDistribution[1], 100];
data2 = RandomVariate[ExponentialDistribution[1], 100];
```

Verify all assumptions:

```wl
In[2]:= SignedRankTest[{data1, data2}, 0, VerifyTestAssumptions -> All]
```

SignedRankTest::ntsymmd: The p-value in {1.05156\*10^-8}, resulting from a test for symmetry, is below 0.05\`. The tests in {SignedRank} require that the data is symmetric about a common median.

```wl
Out[2]= 0.571663
```

Check no assumptions:

```wl
In[3]:= SignedRankTest[{data1, data2}, 0, VerifyTestAssumptions -> None]

Out[3]= 0.571663
```

---

Diagnostics can be controlled independently:

```wl
In[1]:=
data1 = RandomVariate[ExponentialDistribution[1], 1000];
data2 = RandomVariate[ExponentialDistribution[1], 1000];
```

Check for symmetry:

```wl
In[2]:= SignedRankTest[{data1, data2}, 0, VerifyTestAssumptions -> "Symmetry"]
```

SignedRankTest::ntsymmd: The p-value in {1.1619\*10^-116}, resulting from a test for symmetry, is below 0.05\`. The tests in {SignedRank} require that the data is symmetric about a common median.

```wl
Out[2]= 0.0494125
```

Set the symmetry assumption to ``True`` :

```wl
In[3]:= SignedRankTest[{data1, data2}, 0, VerifyTestAssumptions -> "Symmetry" -> True]

Out[3]= 0.0494125
```

### Applications (1)

Twelve sets of identical twins were given psychological tests to measure aggressiveness. It is hypothesized that the first-born twin will tend to be more aggressive than the second-born:

```wl
In[1]:=
first = {86, 71, 77, 68, 91, 72, 77, 91, 70, 71, 88, 87};
second = {88, 77, 76, 64, 96, 72, 65, 90, 65, 80, 81, 72};

In[2]:= BarChart[first - second]

Out[2]= [image]
```

There is insufficient evidence to reject $H_0$ that birth order has no effect on aggressiveness:

```wl
In[3]:= SignedRankTest[{first, second}, 0, "TestDataTable", AlternativeHypothesis -> "Greater"]

Out[3]=
| ""            | "Statistic" | "P‐Value" |
| :------------ | :---------- | :-------- |
| "Signed‐Rank" | 41.5        | 0.238235  |
```

### Properties & Relations (8)

The ``SignedRankTest`` is generally more powerful than the ``SignTest`` :

```wl
In[1]:= data = RandomVariate[NormalDistribution[1, 1], {250, 15}];

In[2]:=
Subscript[p, SR] = Table[SignedRankTest[i, VerifyTestAssumptions -> None], {i, data}];
Subscript[p, SGN] = Table[SignTest[i], {i, data}];

In[3]:= Probability[x ≤ .05, x\[Distributed]Subscript[p, SR]]//N

Out[3]= 0.924

In[4]:= Probability[x ≤ .05, x\[Distributed]Subscript[p, SGN]]//N

Out[4]= 0.8
```

---

The univariate Wilcoxon signed rank test statistic:

```wl
In[1]:= data = RandomVariate[NormalDistribution[], 100];

In[2]:= Subscript[μ, 0] = 0;
```

In the absence of ties, ``Ordering`` can be used to compute ranks:

```wl
In[3]:= WSR[data_, μ0_] := With[{dat = data - μ0}, Total[Pick[Sign[dat] * Ordering[Ordering[Abs@dat]], Sign[dat], 1]]]

In[4]:= WSR[data, Subscript[μ, 0]]

Out[4]= 2858

In[5]:= SignedRankTest[data, Subscript[μ, 0], "TestDataTable"]

Out[5]=
| ""            | "Statistic" | "P‐Value" |
| :------------ | :---------- | :-------- |
| "Signed‐Rank" | 2858.       | 0.252938  |
```

The asymptotic two-sided $p$-value:

```wl
In[6]:= WSRP[data_] := With[{ranks = Sign[data] Ordering[Ordering[Abs[data]]], d = NormalDistribution[]}, 2. Min[CDF[d, (Total[ranks] + 1/Sqrt[ranks.ranks])], SurvivalFunction[d, (Total[ranks] - 1/Sqrt[ranks.ranks])]]]

In[7]:= WSRP[data - Subscript[μ, 0]]

Out[7]= 0.252938
```

---

For univariate data, the test statistic is asymptotically normal:

```wl
In[1]:= data = RandomVariate[NormalDistribution[], {1000, 100}];

In[2]:= T = Table[Quiet@SignedRankTest[i, Automatic, "TestStatistic"], {i, data}];

In[3]:= DistributionFitTest[T, NormalDistribution[μ, σ]]

Out[3]= 0.325971
```

---

For multivariate data, the test statistic follows a ``ChiSquareDistribution`` under $H_0$ :

```wl
In[1]:= data = RandomVariate[BinormalDistribution[.5], {250, 15}];

In[2]:= T = Table[SignedRankTest[i, Automatic, "TestStatistic"], {i, data}];
```

The degree of freedom is equal to the dimension of the data:

```wl
In[3]:= df = Dimensions[data[[1]]][[2]]

Out[3]= 2

In[4]:= DistributionFitTest[T, ChiSquareDistribution[df]]

Out[4]= 0.276203
```

---

For multivariate data, the ``SignedRankTest`` effectively tests uniformity about a unit sphere:

```wl
In[1]:= μ = {{0, 0}, {.5, .5}, {1, 1}, {10, 10}};

In[2]:= data = Table[RandomVariate[ProductDistribution[NormalDistribution[i[[1]], 1], NormalDistribution[i[[2]], 1]], 100], {i, μ}];
```

A function for computing the spatial signed ranks of a matrix:

```wl
In[3]:= SSR[data_] := Block[{n, p, item, dmt, dpt, dm, dp, out = {}}, {n, p} = Dimensions[data];Do[dmt = dpt = Table[0., {p}];Do[dm = i - j;dp = i + j;dmt = dmt + (If[#1 == 0, dm, (dm/#1)]&)[Sqrt[dm.dm]];dpt = dpt + (If[#1 == 0, dp, (dp/#1)]&)[Sqrt[dp.dp]];, {j, data}];item = (dmt + dpt/2 n);out = Join[{item}, out], {i, data}];out]
```

Deviations from ``μ0`` yield clustering of spatial signed ranks and larger test statistics:

```wl
In[4]:= Table[Show[ListPlot[SSR[i], AspectRatio -> 1, PlotStyle -> PointSize[Medium], PlotLabel -> Row[{"SR: ", SignedRankTest[i, Automatic, "TestStatistic"]}], PlotRange -> {{-1, 1}, {-1, 1}}], Graphics[Circle[]]], {i, data}]

Out[4]= {[image], [image], [image], [image]}
```

---

The test statistic is affine invariant for multivariate data:

```wl
In[1]:= data = RandomVariate[MultinormalDistribution[{0, 0}, IdentityMatrix[2]], 100];

In[2]:= \[ScriptCapitalT] = AffineTransform[{{{1, 2}, {3, 4}}, {1, 2}}];

In[3]:= SignedRankTest[data, {0, 0}, "TestDataTable"]

Out[3]=
| ""            | "Statistic" | "P‐Value" |
| :------------ | :---------- | :-------- |
| "Signed‐Rank" | 0.0432064   | 0.978628  |

In[4]:= SignedRankTest[\[ScriptCapitalT][data], \[ScriptCapitalT][{0, 0}], "TestDataTable"]

Out[4]=
| ""            | "Statistic" | "P‐Value" |
| :------------ | :---------- | :-------- |
| "Signed‐Rank" | 0.0432064   | 0.978628  |
```

---

The signed rank test works with the values only when the input is a ``TimeSeries`` :

```wl
In[1]:=
ts = TemporalData[TimeSeries, {CompressedData["«1188»"], {{0, 100, 1}}, 1, {"Continuous", 1}, {"Discrete", 1}, 1, 
  {ValueDimensions -> 1, ResamplingMethod -> None}}, False, 10.1];

In[2]:= SignedRankTest[ts]

Out[2]= 0.783778

In[3]:= SignedRankTest[ts["Values"]]

Out[3]= 0.783778
```

---

The signed rank test works with all the values together when the input is a ``TemporalData`` :

```wl
In[1]:=
td = TemporalData[Automatic, {CompressedData["«2294»"], {{0, 100, 1}}, 2, {"Continuous", 2}, {"Discrete", 1}, 1, 
  {ValueDimensions -> 1, ResamplingMethod -> None}}, False, 10.1];

In[2]:= SignedRankTest[td]

Out[2]= 0.476672
```

Test all the values only:

```wl
In[3]:=
data = td["ValueList"]//Flatten;
SignedRankTest[data]

Out[3]= 0.476672
```

Test the difference of the medians of the two paths:

```wl
In[4]:= {data1, data2} = td["ValueList"];

In[5]:= SignedRankTest[{data1, data2}]

Out[5]= 0.466404
```

### Possible Issues (1)

``SignedRankTest`` requires that the data be symmetric about a common median:

```wl
In[1]:=
BlockRandom[SeedRandom[3];data1 = RandomVariate[NormalDistribution[], 100];
	data2 = RandomVariate[ExponentialDistribution[2], 100]];

In[2]:= SignedRankTest[{data1, data2}, VerifyTestAssumptions -> "Symmetry"]
```

SignedRankTest::ntsymmd: The p-value in {0.0097608}, resulting from a test for symmetry, is below 0.05\`. The tests in {SignedRank} require that the data is symmetric about a common median.

```wl
Out[2]= 0.0000158295
```

Use ``SignTest`` if the data is not symmetric:

```wl
In[3]:= SignTest[{data1, data2}]

Out[3]= 0.00178993
```

### Neat Examples (1)

Compute the statistic when the null hypothesis $H_0$ is true:

```wl
In[1]:=
data1 = RandomVariate[NormalDistribution[], {2500, 100}];
data2 = RandomVariate[NormalDistribution[], {2500, 100}];

In[2]:= T1 = MapThread[SignedRankTest[{#1, #2}, 0, "TestStatistic"]&, {data1, data2}];
```

The test statistic given a particular alternative:

```wl
In[3]:= T2 = MapThread[SignedRankTest[{#1, #2}, 1, "TestStatistic"]&, {data1, data2}];
```

Compare the distributions of the test statistics:

In[4]:= SmoothHistogram[{T1,T2},Filling->Axis,PlotLegends->{"Subscript[H, 0] is True","Subscript[H, 0] is False"}]

```wl
Out[4]= [image]
```

## See Also

* [`HypothesisTestData`](https://reference.wolfram.com/language/ref/HypothesisTestData.en.md)
* [`LocationTest`](https://reference.wolfram.com/language/ref/LocationTest.en.md)
* [`LocationEquivalenceTest`](https://reference.wolfram.com/language/ref/LocationEquivalenceTest.en.md)
* [`VarianceTest`](https://reference.wolfram.com/language/ref/VarianceTest.en.md)
* [`VarianceEquivalenceTest`](https://reference.wolfram.com/language/ref/VarianceEquivalenceTest.en.md)
* [`DistributionFitTest`](https://reference.wolfram.com/language/ref/DistributionFitTest.en.md)
* [`MannWhitneyTest`](https://reference.wolfram.com/language/ref/MannWhitneyTest.en.md)
* [`PairedTTest`](https://reference.wolfram.com/language/ref/PairedTTest.en.md)
* [`PairedZTest`](https://reference.wolfram.com/language/ref/PairedZTest.en.md)
* [`SignTest`](https://reference.wolfram.com/language/ref/SignTest.en.md)
* [`TTest`](https://reference.wolfram.com/language/ref/TTest.en.md)
* [`ZTest`](https://reference.wolfram.com/language/ref/ZTest.en.md)

## Related Guides

* [Hypothesis Tests](https://reference.wolfram.com/language/guide/HypothesisTests.en.md)

## History

* [Introduced in 2010 (8.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn80.en.md)