# Is there any function that compares distributions of two populations?

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.

Thanks

• 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. – Michael E2 Oct 13 '15 at 16:44
• I would have expected that something like KolmogorovSmirnovTest[ data1, EmpiricalDistribution[data2] ] would work, but apparently it doesn't. – rhermans Oct 13 '15 at 16:44
• Nope. From documentation: "KolmogorovSmirnovTest[data,dist] tests whether data is distributed according to dist using the Kolmogorov-Smirnov test." – rhermans Oct 13 '15 at 16:47
• QuantilePlot[data1,data2] would give you a visual idea (Q-Q plot). straight line for equally distributed sets. – rhermans Oct 13 '15 at 16:51
• 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. – Sosi Oct 14 '15 at 14:25

## Data

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] Clearly not equally distributed.

For contrast

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

QuantilePlot[data3, data2] Equally distributed

## Tests

KolmogorovSmirnovTest[data1, data2]

0

KolmogorovSmirnovTest[data3, data2]

0.17038

DistributionFitTest[data3, data2, "ShortTestConclusion"]


"Do not reject"

DistributionFitTest[data1, data2, "ShortTestConclusion"]


"Reject"

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

• I was just now looking into the KolmogorovSmirnovTest too! But shouldn't it be KolmogorovSmirnovTest[data1, EmpiricalDistribution[data2]]? – Sosi Oct 13 '15 at 17:20
• Read the documentation for KolmogorovSmirnovTest basic examples under "Compare the distributions of two datasets:" – rhermans Oct 13 '15 at 17:21
• sorry! :) Thank you! – Sosi Oct 13 '15 at 17:22
SeedRandom;

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


Use ProbabilityPlot for a visual comparison.

ProbabilityPlot[
Evaluate[Tooltip /@ {data1, data2}],
PlotLegends -> {"data1", "data2"}] This indicates that data1 is normal but that data2 is not.

ProbabilityPlot[data1, data2] 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.

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