Imagine I have two populations that I want to test whether they exhibit similar shape distributions. Is there such a function that does this sort of testing already implemented?

I am asking this since one of the assumptions of the Mann-Whitney U test is that both populations to compare exhibit similar shapes. I could compare whether they exhibited similar variance, but this is not what this assumption requires.

For instance, if I have

data1=RandomVariate[NormalDistribution[2, 3], 10^3];
data2=RandomVariate[LaplaceDistribution[1, 2], 10^3];

This function would test whether data1 and data2 exhibit similar shapes. Sorry if this is a very small question.

Edit0: I had posted the following 2 edits before seeing there were two answers that already tackle the main issue here. These two edits are side questions for this thread and should probably be asked elsewhere. Sorry for that.

Edit1: The assumptions indicated in the documentation for MannWhitneyTest[] indicates MannWhitneyTest assumes that the data is elliptically symmetric about a common spatial median in the multivariate case.. I wonder if the assumption about the shape of the two populations is not required in this case?

Edit2: Is it possible that LocationTest[{data1,data2},Automatic, "MannWhitney"] could bypass the issue of sample shape?

The reason why I'm asking these two questions is that the number of tests I'm performing is very large.


  • $\begingroup$ Are you sure you don't want to ask on stats.SE or math.SE? Once you have a theoretical answer, you could ask how to implement it in M, if you need to. In any caes, I think the Kolmogorov-Smirnov test is for this sort of thing, although it's outside my comfort zone. $\endgroup$ – Michael E2 Oct 13 '15 at 16:44
  • $\begingroup$ I would have expected that something like KolmogorovSmirnovTest[ data1, EmpiricalDistribution[data2] ] would work, but apparently it doesn't. $\endgroup$ – rhermans Oct 13 '15 at 16:44
  • 2
    $\begingroup$ Nope. From documentation: "KolmogorovSmirnovTest[data,dist] tests whether data is distributed according to dist using the Kolmogorov-Smirnov test." $\endgroup$ – rhermans Oct 13 '15 at 16:47
  • 2
    $\begingroup$ QuantilePlot[data1,data2] would give you a visual idea (Q-Q plot). straight line for equally distributed sets. $\endgroup$ – rhermans Oct 13 '15 at 16:51
  • 1
    $\begingroup$ Thanks, I usually do accept most meaningful answers that I get in 24-72 hours, as you can see for most of my threads (>80% of them should have accepted answers; the ones that don't are because the potential answers do not entirely address the issue at hand). ...I hope the problem wasn't related with my upvotes, as I really think both answers introduced useful information. $\endgroup$ – Sos Oct 14 '15 at 14:25


data1 = RandomVariate[NormalDistribution[2, 3], 10^3];
data2 = RandomVariate[LaplaceDistribution[1, 2], 10^3];

Visual comparison

DistributionFitTest and KolmogorovSmirnovTest seem to work. But first check visually.

QuantilePlot[data1, data2]

Mathematica graphics

Clearly not equally distributed.

For contrast

data3 = RandomVariate[LaplaceDistribution[1, 2], 10^4];

QuantilePlot[data3, data2]

Mathematica graphics

Equally distributed


KolmogorovSmirnovTest[data1, data2]
KolmogorovSmirnovTest[data3, data2]
DistributionFitTest[data3, data2, "ShortTestConclusion"]

"Do not reject"

DistributionFitTest[data1, data2, "ShortTestConclusion"]


That been "Reject" the hypothesis that the two distributions are equal.

| improve this answer | |
  • 1
    $\begingroup$ I was just now looking into the KolmogorovSmirnovTest too! But shouldn't it be KolmogorovSmirnovTest[data1, EmpiricalDistribution[data2]]? $\endgroup$ – Sos Oct 13 '15 at 17:20
  • 4
    $\begingroup$ Read the documentation for KolmogorovSmirnovTest basic examples under "Compare the distributions of two datasets:" $\endgroup$ – rhermans Oct 13 '15 at 17:21
  • $\begingroup$ sorry! :) Thank you! $\endgroup$ – Sos Oct 13 '15 at 17:22

data1 = RandomVariate[NormalDistribution[2, 3], 10^3];
data2 = RandomVariate[LaplaceDistribution[1, 2], 10^3];

Use ProbabilityPlot for a visual comparison.

 Evaluate[Tooltip /@ {data1, data2}],
 PlotLegends -> {"data1", "data2"}]

enter image description here

This indicates that data1 is normal but that data2 is not.

ProbabilityPlot[data1, data2]

enter image description here

This indicates that the distributions are not similar. Similar distributions are close to the diagonal.

Use DistributionFitTest to test if data is normally distributed (default) or any other specified distribution.

    #, Automatic, "HypothesisTestData"][
   "TestDataTable", All] & /@ {data1, data2}

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.