---
title: "LocationTest"
language: "en"
type: "Symbol"
summary: "LocationTest[data] tests whether the mean or median of the data is zero. LocationTest[{data1, data2}] tests whether the means or medians of data1 and data2 are equal. LocationTest[dspec, \\[Mu]0] tests a location measure against \\[Mu]0. LocationTest[dspec, \\[Mu]0,  property] returns the value of  property."
keywords: 
- hypothesis testing
- test of location
- test of means
- test of medians
- mean test
- mean difference test
- equal mean test
- median test
- test of shift
- Student T-test
- T-test
- t test
- Student's test
- paired T-test
- sign test
- Wilcoxon signed rank test
- rank-sum test
- signed rank test
- Mann-Whitney U test
- Hotelling's T Squared test
- Satterthwaite degrees of freedom
- Welch approximation
- Welch-Satterthwaite
- mean
- equal means
canonical_url: "https://reference.wolfram.com/language/ref/LocationTest.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Hypothesis Tests"
    link: "https://reference.wolfram.com/language/guide/HypothesisTests.en.md"
  - 
    title: "Probability & Statistics with Quantities"
    link: "https://reference.wolfram.com/language/guide/ProbabilityWithQuantities.en.md"
  - 
    title: "Random Variables"
    link: "https://reference.wolfram.com/language/guide/RandomVariables.en.md"
  - 
    title: "Statistical Data Analysis"
    link: "https://reference.wolfram.com/language/guide/Statistics.en.md"
  - 
    title: "Scientific Data Analysis"
    link: "https://reference.wolfram.com/language/guide/ScientificDataAnalysis.en.md"
related_functions: 
  - 
    title: "HypothesisTestData"
    link: "https://reference.wolfram.com/language/ref/HypothesisTestData.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: "IndependenceTest"
    link: "https://reference.wolfram.com/language/ref/IndependenceTest.en.md"
  - 
    title: "LogRankTest"
    link: "https://reference.wolfram.com/language/ref/LogRankTest.en.md"
  - 
    title: "MannWhitneyTest"
    link: "https://reference.wolfram.com/language/ref/MannWhitneyTest.en.md"
  - 
    title: "SignTest"
    link: "https://reference.wolfram.com/language/ref/SignTest.en.md"
  - 
    title: "SignedRankTest"
    link: "https://reference.wolfram.com/language/ref/SignedRankTest.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"
---
# LocationTest

LocationTest[data] tests whether the mean or median of the data is zero. 

LocationTest[{data1, data2}] tests whether the means or medians of data1 and data2 are equal.

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

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

## Details and Options

* ``LocationTest`` performs a hypothesis test on ``data`` with null hypothesis $Subscript[H, 0]$ that the true population location parameter is some value $μ = Subscript[μ, 0]$, and alternative hypothesis $Subscript[H, a]$ that $μ ≠ Subscript[μ, 0]$.

* Given ``data1`` and ``data2``, ``LocationTest`` tests null hypothesis $Subscript[H, 0]$ against alternative hypothesis $Subscript[H, a]$, where $Subscript[H, 0]$ and $Subscript[H, a]$ are defined for each test accordingly.

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

* A small $p$-value suggests that it is unlikely that $Subscript[H, 0]$ is true.

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

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

* ``LocationTest[dspec]`` will choose the most powerful test that applies to ``dspec``.

* ``LocationTest[dspec, Automatic]`` is equivalent to $Subscript[μ, 0] = 0$.

* ``LocationTest[dspec, μ0, All]`` will choose all tests that apply to ``dspec``.

* ``LocationTest[dspec, μ0, "test"]`` reports the $p$-value according to ``"test"``.

* Tests based on means assume the data in ``dspec`` is normally distributed. Some tests assume the data is symmetric about a common median. Tests that do not assume symmetry or normality are classified as robust.

* A paired sample test assumes equal-length dependent data.

* The following tests can be used:

|               |           |                                             |
| ------------- | --------- | ------------------------------------------- |
| "PairedT"     | normality | paired sample test with unknown variance    |
| "PairedZ"     | normality | paired sample test with known variance      |
| "Sign"        | robust    | median test for one sample or matched pairs |
| "SignedRank"  | symmetry  | median test for one sample or matched pairs |
| "T"           | normality | mean test for one or two samples            |
| "MannWhitney" | symmetry  | median test for two independent samples     |
| "Z"           | normality | mean test with known variance               |

* The ``"T"`` test performs Student $t$-test for univariate data and Hotelling's $T^2$ test for multivariate data.

* The ``"Z"`` test performs a $z$-test assuming the sample variance is the known variance for univariate data and Hotelling's $T^2$ test assuming the sample covariance is the known covariance for multivariate data.

* The ``"PairedT"`` and ``"PairedZ"`` tests perform ``"T"`` and ``"Z"`` tests on the paired differences of two datasets. A single dataset is treated as a list of differences.

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

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

* Properties related to the reporting of test results include:

|                       |                                                                             |
| --------------------- | --------------------------------------------------------------------------- |
| "AllTests"            | list of all applicable tests                                                |
| "AutomaticTest"       | test chosen if Automatic is used                                            |
| "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 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 tests of location, a cutoff $α$ is chosen such that $Subscript[H, 0]$ is rejected only if $p < α$. The value of $α$ used for the ``"TestConclusion"`` and ``"ShortTestConclusion"`` properties is controlled by the ``SignificanceLevel`` option. This value $α$ is also used in diagnostic tests of assumptions including tests for normality, equal variance, and symmetry. By default, $α$ is set to ``0.05``.

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

|                 |                                                 |
| --------------- | ----------------------------------------------- |
| "EqualVariance" | verify that data1 and data2 have equal variance |
| "Normality"     | verify that all data is normally distributed    |
| "Symmetry"      | verify symmetry about a common median           |

---

## Examples (58)

### Basic Examples (3)

Test whether the mean or median of a population is zero using a collection of tests:

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

In[2]:= Mean[data]

Out[2]= -0.00160314

In[3]:= ℋ = LocationTest[data, Automatic, {"TestDataTable", All}]

Out[3]=
| ""            | "Statistic"  | "P‐Value" |
| :------------ | :----------- | :-------- |
| "Paired T"    | -0.159523    | 0.87326   |
| "Paired Z"    | -0.159523    | 0.873257  |
| "Sign"        | 4977         | 0.652713  |
| "Signed‐Rank" | 2.4967455*^7 | 0.903383  |
| "T"           | -0.159523    | 0.87326   |
| "Z"           | -0.159523    | 0.873257  |
```

---

Test whether the means of two populations differ by 2:

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

The mean difference $Subscript[μ, 1] - Subscript[μ, 2]$ :

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

Out[2]= 1.78404

In[3]:= SmoothHistogram[{data1, data2 + 2}]

Out[3]= [image]
```

At the ``0.05`` level, $Subscript[μ, 1] - Subscript[μ, 2]$ is significantly different from 2:

```wl
In[4]:= LocationTest[{data1, data2}, 2]

Out[4]= 9.723994369898542`*^-7
```

---

Compare the locations of multivariate populations:

```wl
In[1]:=
data1 = RandomVariate[MultinormalDistribution[{1, 2}, IdentityMatrix[2]], 10^3];
data2 = RandomVariate[MultinormalDistribution[{0, 0}, IdentityMatrix[2]], 10^3];
```

The mean difference vector $Subscript[μ, 1] - Subscript[μ, 2]$ :

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

Out[2]= {0.958105, 1.91831}

In[3]:= Histogram3D[{data1, Transpose[Transpose[data2] + {1, 2}]}, 40]

Out[3]= [image]
```

At the ``0.05`` level, $Subscript[μ, 1] - Subscript[μ, 2]$ is not significantly different from ``{1, 2}`` :

```wl
In[4]:= LocationTest[{data1, data2}, {1, 2}]

Out[4]= 0.378046
```

### Scope (17)

#### Testing (13)

Test $Subscript[H, 0] : μ = 0$ versus $Subscript[H, a] : μ ≠ 0$ :

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

The $p$-values are typically large when the mean is close to 0:

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

Out[2]= 0.899667
```

The $p$-values are typically small when the mean is far from 0:

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

Out[3]= 2.0413976215659536`*^-251
```

---

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

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

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

Out[2]= 0.994132

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

Out[3]= 0.994132
```

---

Test $Subscript[H, 0] : μ = 3$ versus $Subscript[H, a] : μ ≠ 3$ :

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

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

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

Out[2]= 0.42084
```

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

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

Out[3]= 5.442457353963206`*^-252
```

---

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

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

In[2]:= LocationTest[data]

Out[2]= 0.00252549
```

Alternatively, test against ``{0.1, 0, -0.05, 0}`` :

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

Out[3]= 0.285579
```

---

Using ``Automatic`` applies the generally most powerful appropriate test:

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

In[2]:= LocationTest[data, 0, Automatic]

Out[2]= 0.949974
```

The property ``"AutomaticTest"`` can be used to determine which test was chosen:

```wl
In[3]:= LocationTest[data, 0, "AutomaticTest"]

Out[3]= "T"
```

---

Test $Subscript[H, 0] : Subscript[μ, 1] - Subscript[μ, 2] = 0 $ versus $Subscript[H, a] : Subscript[μ, 1] - Subscript[μ, 2] ≠ 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]:= LocationTest[{data1, data2}, 0]

Out[2]= 1.565294675480648`*^-11
```

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

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

Out[3]= 0.511758
```

---

Test $Subscript[H, 0] : Subscript[μ, 1] - Subscript[μ, 2] = 3 $ versus $Subscript[H, a] : Subscript[μ, 1] - Subscript[μ, 2] ≠ 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]:= LocationTest[{data1, data2}, 3]

Out[2]= 0.676413

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

Out[3]= 1.673172533295071`*^-103
```

---

Test whether the mean 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]:= LocationTest[{data1, data2}]

Out[3]= 9.303668946358812`*^-14
```

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

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

Out[4]= 0.657079
```

---

Perform a particular test for equal locations:

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

In[2]:= LocationTest[data, 0, "T"]

Out[2]= 0.871296
```

Any number of tests can be performed simultaneously:

```wl
In[3]:= LocationTest[data, 0, {"T", "Sign", "MannWhitney"}]

Out[3]= {0.871296, 0.924426, 0.960441}
```

---

Perform all tests appropriate to the data simultaneously:

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

In[2]:= LocationTest[data, 0, All]

Out[2]= {0.528765, 0.602298, 0.601834, 0.342799, 0.55125, 0.617989, 0.617769}
```

Use the property ``"AllTests"`` to identify which tests were used:

```wl
In[3]:= LocationTest[data, 0, "AllTests"]

Out[3]= {"MannWhitney", "PairedT", "PairedZ", "Sign", "SignedRank", "T", "Z"}
```

---

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

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

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

The properties available for extraction:

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

Out[3]= {"AllTests", "AutomaticTest", "DegreesOfFreedom", "HypothesisTestData", "MannWhitney", "PairedT", "PairedZ", "Properties", "PValue", "PValueTable", "ShortTestConclusion", "Sign", "SignedRank", "T", "TestConclusion", "TestData", "TestDataTable", "TestEntries", "TestStatistic", "TestStatisticTable", "Z"}
```

---

Extract some properties from a ``HypothesisTestData`` :

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

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

The $p$-value and test statistic from a $t$-type test:

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

Out[3]= 0.451612

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

Out[4]= 0.752746
```

---

Extract any number of properties simultaneously:

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

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

The $p$-value and test statistic from a Mann–Whitney test:

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

Out[3]= {0.160761, 4.9427411*^7}
```

#### Reporting (4)

Tabulate the results from a selection of tests:

```wl
In[1]:=
data1 = RandomVariate[NormalDistribution[], 2000];
data2 = RandomVariate[NormalDistribution[], 2300];

In[2]:= ℋ = LocationTest[{data1, data2}, 0, "HypothesisTestData"];
```

A full table of all appropriate test results:

```wl
In[3]:= ℋ["TestDataTable", All]

Out[3]=
| ""             | "Statistic" | "P‐Value" |
| :------------- | :---------- | :-------- |
| "Mann‐Whitney" | 2.307881*^6 | 0.846094  |
| "T"            | 0.149488    | 0.881176  |
| "Z"            | 0.150082    | 0.8807    |
```

A table of selected test results:

```wl
In[4]:= ℋ["TestDataTable", {"T", "Z"}]

Out[4]=
| ""  | "Statistic" | "P‐Value" |
| :-- | :---------- | :-------- |
| "T" | 0.149488    | 0.881176  |
| "Z" | 0.150082    | 0.8807    |
```

---

Retrieve the entries from a test table for customized reporting:

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

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

In[3]:= res = ℋ["TestData", All];

In[4]:= tests = ℋ["AllTests"]

Out[4]= {"MannWhitney", "PairedT", "PairedZ", "Sign", "SignedRank", "T", "Z"}
```

The $p$-values are above ``0.05``, so there is not enough evidence to reject $Subscript[H, 0]$ at that level:

```wl
In[5]:= Show[BarChart[res[[All, 2]], ChartLabels -> Placed[tests, Center], BarOrigin -> Left], Graphics[{Dashed, InfiniteLine[{{.05, 0}, {.05, 1}}]}]]

Out[5]= [image]
```

---

Tabulate $p$-values for a test or group of tests:

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

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

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

Out[3]=
| ""  | "P‐Value" |
| :-- | :-------- |
| "T" | 0.580203  |
```

The $p$-value from the table:

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

Out[4]= 0.580203
```

A table of $p$-values from all appropriate tests:

```wl
In[5]:= ℋ["PValueTable", All]

Out[5]=
| ""             | "P‐Value" |
| :------------- | :-------- |
| "Mann‐Whitney" | 0.437881  |
| "Paired T"     | 0.57346   |
| "Paired Z"     | 0.572182  |
| "Sign"         | 0.271253  |
| "Signed‐Rank"  | 0.39669   |
| "T"            | 0.580203  |
| "Z"            | 0.579577  |
```

A table of $p$-values from a subset of tests:

```wl
In[6]:= ℋ["PValueTable", {"T", "Sign", "MannWhitney"}]

Out[6]=
| ""             | "P‐Value" |
| :------------- | :-------- |
| "T"            | 0.580203  |
| "Sign"         | 0.271253  |
| "Mann‐Whitney" | 0.437881  |
```

---

Report the test statistic from a test or group of tests:

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

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

In[3]:= ℋ[Automatic]

Out[3]= 0.603784
```

The test statistic from the table:

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

Out[4]= 493299.
```

A table of test statistics from all appropriate tests:

```wl
In[5]:= ℋ["TestStatisticTable", All]

Out[5]=
| ""             | "Statistic" |
| :------------- | :---------- |
| "Mann‐Whitney" | 493299.     |
| "Sign"         | 500         |
| "Signed‐Rank"  | 245679.     |
```

### Options (20)

#### AlternativeHypothesis (3)

A two-sided test is performed by default:

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

Test $Subscript[H, 0] : μ = 0$ versus $Subscript[H, a] : μ ≠ 0$ :

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

Out[2]= 0.400088

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

Out[3]= 0.400088
```

---

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

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

Test $Subscript[H, 0] : μ = 0$ versus $Subscript[H, a] : μ ≠ 0$ :

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

Out[2]= 0.979286
```

Test $Subscript[H, 0] : μ ≥ 0$ versus $Subscript[H, a] : μ < 0$ :

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

Out[3]= 0.510357
```

Test $Subscript[H, 0] : μ ≤ 0$ versus $Subscript[H, a] : μ > 0$ :

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

Out[4]= 0.489643
```

---

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] - Mean[data2]

Out[2]= 2.94025
```

Test $Subscript[H, 0] : Subscript[μ, 1] - Subscript[μ, 2] ≥ 3 $ versus $Subscript[H, a] : Subscript[μ, 1] - Subscript[μ, 2] < 3$ :

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

Out[3]= 0.0874962
```

Test $Subscript[H, 0] : Subscript[μ, 1] - Subscript[μ, 2] ≥ 2.9 $ versus $Subscript[H, a] : Subscript[μ, 1] - Subscript[μ, 2] < 2.9$ :

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

Out[4]= 0.819568
```

#### MaxIterations (1)

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

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

In[2]:= LocationTest[{data1, data2}, Automatic, "Sign", MaxIterations -> 100]

Out[2]= 0.347564

In[3]:= LocationTest[{data1, data2}, Automatic, "SignedRank", MaxIterations -> 100]

Out[3]= 0.507884

In[4]:= LocationTest[{data1, data2}, Automatic, "MannWhitney", MaxIterations -> 100]

Out[4]= 0.477678
```

#### Method (6)

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

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

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

Out[2]= 0.0609504

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

Out[3]= 0.0609504
```

---

For univariate median-based tests, $p$-values can be obtained using permutation methods:

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

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

Out[2]= 0.617382

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

Out[3]= 0.6174
```

---

Set the number of permutations to use:

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

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

Out[2]= 0.072

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

Out[3]= 0.06544
```

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

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

Out[4]= 0.068
```

---

For some tests, the permutation result is exact:

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

In[2]:= LocationTest[data, 0, "Sign", Method -> "Permutation"]

Out[2]= 0.0568879
```

The result is not affected by the number of permutations when exact tests are used:

```wl
In[3]:= LocationTest[data, 0, "Sign", Method -> {"Permutation", "MonteCarloSamples" -> 10^7}]

Out[3]= 0.0568879
```

---

For mean-based tests, the $p$-value is exact under the assumptions of the test:

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

In[2]:= LocationTest[data, 0, "T", Method -> "Permutation"]

Out[2]= 0.214479

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

Out[3]= 0.214479
```

---

Set the seed used for generating random permutations:

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

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

Out[2]= 0.3006

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

Out[3]= 0.2792
```

#### SignificanceLevel (3)

Set the significance level for diagnostic tests:

```wl
In[1]:= data = BlockRandom[SeedRandom[2];RandomVariate[StudentTDistribution[3], 50]];

In[2]:= LocationTest[data, 0, "T", SignificanceLevel -> .0001]

Out[2]= 0.169902
```

By default, ``0.05`` is used:

```wl
In[3]:= LocationTest[data, 0, "T"]
```

LocationTest::nortst: At least one of the p-values in {0.00416643}, resulting from a test for normality, is below 0.05\`. The tests in {T} require that the data is normally distributed.

```wl
Out[3]= 0.169902
```

---

Setting the significance level may alter which test is automatically chosen:

```wl
In[1]:= data = BlockRandom[SeedRandom[2];RandomVariate[StudentTDistribution[3], {2, 50}]];

In[2]:= LocationTest[data, 0, "AutomaticTest", SignificanceLevel -> .0005]

Out[2]= "T"
```

A median-based test would have been chosen by default:

```wl
In[3]:= LocationTest[data, 0, "AutomaticTest", SignificanceLevel -> Automatic]

Out[3]= "MannWhitney"
```

---

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

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

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

In[3]:= ℋ2 = LocationTest[data, .395, "HypothesisTestData", SignificanceLevel -> .00001];

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

Out[4]//TraditionalForm= "The null hypothesis that ""the ""mean"" of the population is equal to "0.395" ""is rejected at the "5." percent level ""based on the ""T"" test."

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

Out[5]//TraditionalForm= "The null hypothesis that ""the ""mean"" of the population is equal to "0.395" ""is not rejected at the "0.001" percent level ""based on the ""T"" test."

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

Out[6]= "Reject"

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

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

#### VerifyTestAssumptions (7)

By default, normality and equal variance are tested when appropriate:

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

In[2]:= LocationTest[{data1, data2}, 0, "T", VerifyTestAssumptions -> Automatic]

Out[2]= 0.620837
```

If assumptions are not checked, some test results may differ:

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

Out[3]= 0.620698
```

---

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

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

Verify all assumptions:

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

Out[2]= 0.565634
```

Check no assumptions:

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

Out[3]= 0.565443
```

---

Diagnostics can be controlled independently:

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

Assume normality and symmetry but check for equal variances:

```wl
In[2]:= LocationTest[{data1, data2}, 0, "T", VerifyTestAssumptions -> "EqualVariance"]

Out[2]= 0.331557
```

Only check for normality:

```wl
In[3]:= LocationTest[{data1, data2}, 0, "T", VerifyTestAssumptions -> "Normality"]

Out[3]= 0.330954
```

---

Unlisted assumptions are not tested:

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

Normality is assumed:

```wl
In[2]:= LocationTest[data, 0, "T", VerifyTestAssumptions -> {"EqualVariance", "Symmetry"}]

Out[2]= 0.916362
```

The result is the same but a warning is issued:

```wl
In[3]:= LocationTest[data, 0, "T", VerifyTestAssumptions -> All]
```

LocationTest::nortst: At least one of the p-values in {0}, resulting from a test for normality, is below 0.05\`. The tests in {T} require that the data is normally distributed.

```wl
Out[3]= 0.916362
```

---

Test assumption values can be explicitly set:

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

In[2]:= LocationTest[data, 0, "TestDataTable"]

Out[2]=
| ""            | "Statistic" | "P‐Value" |
| :------------ | :---------- | :-------- |
| "Signed‐Rank" | 1998.       | 0.0702527 |

In[3]:= LocationTest[data, 0, "TestDataTable", VerifyTestAssumptions -> "Normality" -> True]

Out[3]=
| ""  | "Statistic" | "P‐Value" |
| :-- | :---------- | :-------- |
| "T" | -1.21529    | 0.227144  |
```

The sign test was previously chosen because the data is not normally distributed:

```wl
In[4]:= LocationTest[data, 0, {"TestDataTable", "T"}]
```

LocationTest::nortst: At least one of the p-values in {0}, resulting from a test for normality, is below 0.05\`. The tests in {T} require that the data is normally distributed.

```wl
Out[4]=
| ""  | "Statistic" | "P‐Value" |
| :-- | :---------- | :-------- |
| "T" | -1.21529    | 0.227144  |
```

---

Bypassing diagnostic tests can save compute time:

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

In[2]:= LocationTest[data, Automatic, {"TestDataTable", "T"}, VerifyTestAssumptions -> All]//AbsoluteTiming

Out[2]=
{3.042039, | ""  | "Statistic" | "P‐Value" |
| :-- | :---------- | :-------- |
| "T" | 6.19267     | 0.102731  |}

In[3]:= LocationTest[data, Automatic, {"TestDataTable", "T"}, VerifyTestAssumptions -> None]//AbsoluteTiming

Out[3]=
{0.015600, | ""  | "Statistic" | "P‐Value" |
| :-- | :---------- | :-------- |
| "T" | 6.19267     | 0.102731  |}
```

---

It is often useful to bypass diagnostic tests for simulation purposes:

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

In[2]:= AbsoluteTiming[T = Quiet@LocationTest[#, Automatic, {"TestStatistic", "T"}]& /@ data;]

Out[2]= {2.947710, Null}
```

The assumptions of the test hold by design, so a great deal of time can be saved:

```wl
In[3]:= AbsoluteTiming[T2 = Quiet@LocationTest[#, Automatic, {"TestStatistic", "T"}, VerifyTestAssumptions -> None]& /@ data;]

Out[3]= {0.466396, Null}
```

The results are identical:

```wl
In[4]:= SmoothHistogram[{T, T2}]

Out[4]= [image]
```

### Applications (4)

Test whether the locations of some populations are equivalent:

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

In[2]:= BoxWhiskerChart[{data1, data2, data3}, "Notched", ChartStyle -> "SolarColors"]

Out[2]= [image]
```

The first two populations have similar locations:

```wl
In[3]:= LocationTest[{data1, data2}, Automatic, "TestDataTable"]

Out[3]=
| ""  | "Statistic" | "P‐Value" |
| :-- | :---------- | :-------- |
| "T" | 0.211406    | 0.832788  |
```

The third population differs in location from the first:

```wl
In[4]:= LocationTest[{data1, data3}, Automatic, "TestDataTable"]

Out[4]=
| ""  | "Statistic" | "P‐Value"               |
| :-- | :---------- | :---------------------- |
| "T" | -23.0041    | 7.727013745127145`*^-58 |
```

---

The heart and body weights of a group of house cats were obtained:

```wl
In[1]:= ExampleData[{"Statistics", "FisherCats"}, "ColumnDescriptions"]

Out[1]= {"Sex of the cat \"F\" or \"M\"", "Body weight in kg", "Heart weight in g"}

In[2]:= {sex, heart, weight} = Transpose@ExampleData[{"Statistics", "FisherCats"}];
```

The heart weight of male cats is significantly greater than that of female cats:

```wl
In[3]:= LocationTest[{Pick[heart, sex, "M"], Pick[heart, sex, "F"]}, 0, "TestDataTable", AlternativeHypothesis -> "Greater"]

Out[3]=
| ""             | "Statistic" | "P‐Value"               |
| :------------- | :---------- | :---------------------- |
| "Mann‐Whitney" | 3801.5      | 4.100251117160905`*^-11 |
```

Perhaps male cats are just larger in general:

```wl
In[4]:=
maleHBR = Pick[heart / weight, sex, "M"];
femaleHBR = Pick[heart / weight, sex, "F"];

In[5]:= SmoothHistogram[{maleHBR, femaleHBR}, PlotLegends -> {"maleHBR", "femaleHBR"}]

Out[5]= [image]
```

The ratio of heart weight to body weight is not significantly different between the sexes:

```wl
In[6]:= LocationTest[{maleHBR, femaleHBR}, 0, "TestDataTable"]

Out[6]=
| ""  | "Statistic" | "P‐Value" |
| :-- | :---------- | :-------- |
| "T" | 0.262874    | 0.793028  |
```

---

Six measurements were taken for 100 counterfeit Swiss banknotes and 100 genuine ones:

```wl
In[1]:= data = ExampleData[{"Statistics", "SwissBankNotes"}];

In[2]:= ExampleData[{"Statistics", "SwissBankNotes"}, "ColumnDescriptions"]

Out[2]= {"Length of bill in mm", "Width of left edge in mm", "Width of right edge in mm", "Bottom margin width in mm", "Top margin width in mm", "Length of image diagonal in mm", "Genuine 0 or counterfeit 1"}

In[3]:=
cBills = Pick[data[[All, {1, 2}]], data[[All, -1]], 1];
gBills = Pick[data[[All, {1, 2}]], data[[All, -1]], 0];
```

A plot of two of the measures for counterfeit and genuine notes:

```wl
In[4]:= ListPlot[{cBills, gBills}, PlotStyle -> {PointSize -> .025}, Frame -> True, AspectRatio -> 1, PlotRange -> {{213, 217}, {128, 132}}]

Out[4]= [image]
```

A test of the bivariate median vectors shows a significant difference:

```wl
In[5]:= LocationTest[{cBills, gBills}, 0, {"TestDataTable", "MannWhitney"}]

Out[5]=
| ""             | "Statistic" | "P‐Value"                |
| :------------- | :---------- | :----------------------- |
| "Mann‐Whitney" | 77.0635     | 1.8444496901137102`*^-17 |
```

---

Samples were drawn from a pool of water at 10 randomly selected locations. Each sample was tested for zinc concentration at both the surface of the water and the bottom of the pool:

```wl
In[1]:=
bottom = {.430, .266, .567, .531, .707, .716, .651, .589, .469, .723};
surface = {.415, .238, .390, .410, .605, .609, .632, .523, .411, .612};
```

A visual inspection of the data. The distance between the vertical bars shows the quantity being tested under an assumption of dependence and independence respectively:

```wl
In[2]:= MeanLine[data_, h_] := Graphics[{Thick, Purple, Line[{{Mean[data], 0}, {Mean[data], h}}]}]

In[3]:= {Show[SmoothHistogram[bottom - surface, PlotLabel -> "Paired", PlotStyle -> Darker[Green]], MeanLine[bottom - surface, 6], MeanLine[{0}, 6], Axes -> {Automatic, None}, ImageSize -> 200], Show[SmoothHistogram[{bottom, surface}, PlotLabel -> "Independent", PlotLegends -> {"bottom", "surface"}], MeanLine[bottom, 2.5], MeanLine[surface, 2.5], Axes -> {Automatic, None}, ImageSize -> 200]}

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

Assuming the data is paired yields a significant result not present under independence:

```wl
In[4]:= LocationTest[{bottom, surface}, 0, {"TestDataTable", "PairedT"}]

Out[4]=
| ""         | "Statistic" | "P‐Value"   |
| :--------- | :---------- | :---------- |
| "Paired T" | 4.86381     | 0.000891115 |

In[5]:= LocationTest[{bottom, surface}, 0, {"TestDataTable", "T"}]

Out[5]=
| ""  | "Statistic" | "P‐Value" |
| :-- | :---------- | :-------- |
| "T" | 1.29131     | 0.212933  |
```

Assume a laboratory test showed that zinc concentrations form a gradient that becomes higher with increasing depth. This information justifies the use of a one-sided alternative:

```wl
In[6]:= LocationTest[{bottom, surface}, 0, {"TestDataTable", "PairedT"}, AlternativeHypothesis -> "Greater"]

Out[6]=
| ""         | "Statistic" | "P‐Value"   |
| :--------- | :---------- | :---------- |
| "Paired T" | 4.86381     | 0.000445558 |
```

### Properties & Relations (9)

The $p$ - value suggests the expected proportion of false positives (Type I errors):

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

In[2]:= pvals = Table[LocationTest[i, 0, "T", VerifyTestAssumptions -> None], {i, data}];
```

Setting the size of a test to ``0.05`` results in an erroneous rejection of $Subscript[H, 0]$ about 5% of the time:

```wl
In[3]:= Probability[x ≤ 0.05, x\[Distributed]pvals]//N

Out[3]= 0.05
```

---

Type II errors arise when $Subscript[H, 0]$ is not rejected, given it is false:

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

In[2]:= ℋs = Table[LocationTest[i, 0, "T", VerifyTestAssumptions -> None], {i, data}];
```

Increasing the size of the test lowers the Type II error rate:

```wl
In[3]:= ListLinePlot[Table[{sz, Probability[x > sz, x\[Distributed]ℋs]//N}, {sz, Range[0.001, .25, .01]}], AxesLabel -> {"Size", "Type II Error"}]

Out[3]= [image]
```

---

The power of each test is the probability of rejecting $Subscript[H, 0]$ when it is false:

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

In[2]:= tests = {"Sign", "SignedRank", "T", "Z"};

In[3]:= p = Transpose@Table[LocationTest[i, 0, tests, VerifyTestAssumptions -> None], {i, data}];

In[4]:= α = {.001, .005, .01, .025, .05, .1};
```

The power of the tests at six different levels. The sign test has the lowest power in general:

```wl
In[5]:= N[Grid[Join[{Join[{""}, α]}, Table[Join[{tests[[i]]}, (Probability[x ≤ #1, x\[Distributed]p[[i]]]&) /@ α], {i, Length[tests]}]], Alignment -> Left, Dividers -> {{False, True}, {False, True}}]]

Out[5]=
| ""           | 0.001 | 0.005 | 0.01  | 0.025 | 0.05  | 0.1   |
| :----------- | :---- | :---- | :---- | :---- | :---- | :---- |
| "Sign"       | 0.281 | 0.398 | 0.521 | 0.631 | 0.733 | 0.835 |
| "SignedRank" | 0.466 | 0.678 | 0.773 | 0.878 | 0.927 | 0.959 |
| "T"          | 0.523 | 0.72  | 0.802 | 0.894 | 0.937 | 0.969 |
| "Z"          | 0.587 | 0.76  | 0.826 | 0.9   | 0.942 | 0.972 |
```

---

The power of tests decreases with smaller sample sizes:

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

In[2]:= tests = {"Sign", "SignedRank", "T", "Z"};

In[3]:= p = Transpose@Table[LocationTest[i, 0, tests, VerifyTestAssumptions -> None], {i, data}];

In[4]:= α = {.001, .005, .01, .025, .05, .1};
```

The power of the tests is lower than in the previous example:

```wl
In[5]:= N[Grid[Join[{Join[{""}, α]}, Table[Join[{tests[[i]]}, (Probability[x ≤ #1, x\[Distributed]p[[i]]]&) /@ α], {i, Length[tests]}]], Alignment -> Left, Dividers -> {{False, True}, {False, True}}]]

Out[5]=
| ""           | 0.001 | 0.005 | 0.01  | 0.025 | 0.05  | 0.1   |
| :----------- | :---- | :---- | :---- | :---- | :---- | :---- |
| "Sign"       | 0.    | 0.027 | 0.027 | 0.139 | 0.139 | 0.139 |
| "SignedRank" | 0.    | 0.    | 0.057 | 0.146 | 0.219 | 0.387 |
| "T"          | 0.022 | 0.061 | 0.107 | 0.189 | 0.288 | 0.436 |
| "Z"          | 0.104 | 0.167 | 0.212 | 0.297 | 0.394 | 0.502 |
```

---

For dependent samples, paired tests are more powerful than their non-paired counterparts:

```wl
In[1]:=
data1 = Sort@RandomVariate[NormalDistribution[1, 1], {1000, 20}];
data2 = Sort@RandomVariate[NormalDistribution[1.5, 1], {1000, 20}];

In[2]:= tests = {"T", "PairedT", "Z", "PairedZ"};

In[3]:= p = Table[MapThread[LocationTest[{#1, #2}, 0, i, VerifyTestAssumptions -> None]&, {data1, data2}], {i, tests}];
```

Paired tests assume observations in one dataset are matched with observations in the other:

```wl
In[4]:= N[Table[{tests[[i]], Probability[x ≤ 0.05, x\[Distributed]p[[i]]]}, {i, Length[tests]}]]//TableForm

Out[4]//TableForm=
|           |       |
| :-------- | :---- |
| "T"       | 0.331 |
| "PairedT" | 0.337 |
| "Z"       | 0.357 |
| "PairedZ" | 0.387 |
```

---

A paired $t$-test is equivalent to a $t$-test applied to the point-wise differences of two datasets:

```wl
In[1]:=
data1 = Sort@RandomVariate[NormalDistribution[1, 1], 25];
data2 = Sort@RandomVariate[NormalDistribution[1, 1], 25];

In[2]:= LocationTest[{data1, data2}, 0, {"TestDataTable", "PairedT"}]

Out[2]=
| ""         | "Statistic" | "P‐Value"  |
| :--------- | :---------- | :--------- |
| "Paired T" | -3.4808     | 0.00193194 |

In[3]:= LocationTest[data1 - data2, 0, {"TestDataTable", "T"}]

Out[3]=
| ""  | "Statistic" | "P‐Value"  |
| :-- | :---------- | :--------- |
| "T" | -3.4808     | 0.00193194 |
```

Paired tests assume that the data represents differences when given a single dataset:

```wl
In[4]:= LocationTest[data1 - data2, 0, {"TestDataTable", "PairedT"}]

Out[4]=
| ""         | "Statistic" | "P‐Value"  |
| :--------- | :---------- | :--------- |
| "Paired T" | -3.4808     | 0.00193194 |
```

---

A two-sided $p$-value is twice the smaller of the two one-sided $p$-values:

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

In[2]:= twoSided = LocationTest[{data1, data2}, 0, All, AlternativeHypothesis -> "Unequal"];

In[3]:= minOneSided = Min /@ Transpose[{LocationTest[{data1, data2}, 0, All, AlternativeHypothesis -> "Less"], LocationTest[{data1, data2}, 0, All, AlternativeHypothesis -> "Greater"]}];

In[4]:= twoSided - 2 minOneSided

Out[4]= {0., 0., 0., 0., 0., 0., 0.}
```

---

The ``LocationTest`` 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]:= LocationTest[ts, Automatic, {"TestDataTable", All}]

Out[2]=
| ""            | "Statistic" | "P‐Value" |
| :------------ | :---------- | :-------- |
| "Paired T"    | 0.298517    | 0.765928  |
| "Paired Z"    | 0.298517    | 0.765309  |
| "Sign"        | 52          | 0.842382  |
| "Signed‐Rank" | 2657.       | 0.783778  |
| "T"           | 0.298517    | 0.765928  |
| "Z"           | 0.298517    | 0.765309  |

In[3]:= LocationTest[ts["Values"], Automatic, {"TestDataTable", All}]

Out[3]=
| ""            | "Statistic" | "P‐Value" |
| :------------ | :---------- | :-------- |
| "Paired T"    | 0.298517    | 0.765928  |
| "Paired Z"    | 0.298517    | 0.765309  |
| "Sign"        | 52          | 0.842382  |
| "Signed‐Rank" | 2657.       | 0.783778  |
| "T"           | 0.298517    | 0.765928  |
| "Z"           | 0.298517    | 0.765309  |

In[4]:= %% == %

Out[4]= True
```

---

``LocationTest`` 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]:= LocationTest[td]

Out[2]= 0.466027
```

Test all the values only:

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

Out[3]= 0.466027
```

Test whether the means or medians of the two paths are equal:

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

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

Out[5]= 0.532502
```

### Possible Issues (3)

Unknown variances and covariances are estimated from the data when using $z$-type tests:

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

For large samples, the estimation has little effect on the results:

```wl
In[2]:= LocationTest[data1, 0, {"TestDataTable", {"T", "Z"}}]

Out[2]=
| ""  | "Statistic" | "P‐Value" |
| :-- | :---------- | :-------- |
| "T" | -0.118548   | 0.905657  |
| "Z" | -0.118548   | 0.905633  |
```

With small samples, $t$-type tests should be used to account for the estimation:

```wl
In[3]:= LocationTest[data2, 0, {"TestDataTable", {"T", "Z"}}]

Out[3]=
| ""  | "Statistic" | "P‐Value"              |
| :-- | :---------- | :--------------------- |
| "T" | 5.2803      | 0.00186468             |
| "Z" | 5.2803      | 1.289705646749669`*^-7 |
```

---

Median-based tests should be used if the data is not normally distributed:

```wl
In[1]:= data = BlockRandom[SeedRandom[1];RandomVariate[StudentTDistribution[3], 100]];

In[2]:= LocationTest[data, 0, "T"]
```

LocationTest::nortst: At least one of the p-values in {0.000737949}, resulting from a test for normality, is below 0.05\`. The tests in {T} require that the data is normally distributed.

```wl
Out[2]= 0.823491
```

Median-based tests do not assume normality:

```wl
In[3]:= LocationTest[data, 0, "SignedRank"]

Out[3]= 0.889251
```

---

Changing the significance level affects internal diagnostics:

```wl
In[1]:=
BlockRandom[SeedRandom[1];
	data1 = RandomVariate[NormalDistribution[0, 1], 35];
	data2 = RandomVariate[NormalDistribution[0, 1.5], 35];
	]

In[2]:=
ℋ1 = LocationTest[{data1, data2}, 0, "HypothesisTestData", SignificanceLevel -> .05];
ℋ2 = LocationTest[{data1, data2}, 0, "HypothesisTestData", SignificanceLevel -> .01];
```

The degrees of freedom are affected by a test for variance:

```wl
In[3]:= VarianceEquivalenceTest[{data1, data2}] > 0.05

Out[3]= False

In[4]:= VarianceEquivalenceTest[{data1, data2}] > 0.01

Out[4]= True

In[5]:= {ℋ1["DegreesOfFreedom", "T"], ℋ2["DegreesOfFreedom", "T"]}

Out[5]= {59.2363, 68}
```

The $p$-values are not equivalent:

```wl
In[6]:= ℋ1["T"] == ℋ2["T"]

Out[6]= False
```

### Neat Examples (2)

A visual comparison of the discriminating power of some tests across the three alternatives:

```wl
In[1]:= data = RandomVariate[NormalDistribution[], {500, 50}];

In[2]:=
tests = {"T", "Z", "SignedRank", "Sign"};
alts = {"Less", "Unequal", "Greater"};

In[3]:= res = Table[(Quiet@LocationTest[#1, 0, i, AlternativeHypothesis -> j, VerifyTestAssumptions -> None]&) /@ data, {i, tests}, {j, alts}];

In[4]:= m = Mean /@ data;

In[5]:= Grid[Join[{Join[{""}, alts]}, Join[Partition[Thread[Rotate[tests, (π/2)]], 1], Table[ListPlot[Transpose[{m, res[[i, j]]}], FrameTicks -> None, Frame -> True, PlotRange -> {{-.5, .5}, {0, 1}}], {i, 4}, {j, 3}], 2]]]

Out[5]=
|                                          |         |           |           |
| ---------------------------------------- | ------- | --------- | --------- |
| ""                                       | "Less"  | "Unequal" | "Greater" |
| Rotate["T ... image]   |
| Rotate["Z", 1.5707963267948966]          | [image] | [image]   | [image]   |
| Rotate["SignedRank", 1.5707963267948966] | [image] | [image]   | [image]   |
| Rotate["Sign", 1.5707963267948966]       | [image] | [image]   | [image]   |
```

---

Compute the statistic when the null hypothesis $Subscript[H, 0]$ is true:

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

In[2]:= T1 = LocationTest[#, 0, "TestStatistic", VerifyTestAssumptions -> None]& /@ data;
```

The test statistic given a particular alternative:

```wl
In[3]:= T2 = LocationTest[#, 2, "TestStatistic", VerifyTestAssumptions -> None]& /@ data;
```

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"}]

Out[4]=
Subscript[H, 0] is True
	Subscript[H, 0] is False

## See Also

* [`HypothesisTestData`](https://reference.wolfram.com/language/ref/HypothesisTestData.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)
* [`IndependenceTest`](https://reference.wolfram.com/language/ref/IndependenceTest.en.md)
* [`LogRankTest`](https://reference.wolfram.com/language/ref/LogRankTest.en.md)
* [`MannWhitneyTest`](https://reference.wolfram.com/language/ref/MannWhitneyTest.en.md)
* [`SignTest`](https://reference.wolfram.com/language/ref/SignTest.en.md)
* [`SignedRankTest`](https://reference.wolfram.com/language/ref/SignedRankTest.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)
* [Probability & Statistics with Quantities](https://reference.wolfram.com/language/guide/ProbabilityWithQuantities.en.md)
* [Random Variables](https://reference.wolfram.com/language/guide/RandomVariables.en.md)
* [Statistical Data Analysis](https://reference.wolfram.com/language/guide/Statistics.en.md)
* [Scientific Data Analysis](https://reference.wolfram.com/language/guide/ScientificDataAnalysis.en.md)

## History

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