# Getting the Cumulative Distribution Function of f(x) from a dataset of x

I've a data set $\mathcal{X}$ which consists of randomly generated numbers.

Let's say for example

data = RandomVariate[ExponentialDistribution[1], 10^4];


My aim is to use Mathematica to obtain and plot the cumulative distribution function (CDF) of $f(x)$, specifically the square root of $x\in \mathcal{X}$, without generating a new data set for $\sqrt{x}$.

Can somebody let me know how to take the approach here ?

• Hi ! I don't think this is a Mathematica related issue rather than a mathematics one. – Sektor Oct 16 '14 at 20:51
• Hi @peeppeep, welcome to Mathematica.SE, please consider taking the tour so you learn the basic rules of the site. Now that I did your homework, please take some time learn from the site and help others when you can. Your question has been answered, but its a good idea to wait a few hour for other answers before accepting the best one for you. – rhermans Oct 16 '14 at 21:37

First I create a set of data to simulate yours.

data = RandomVariate[ExponentialDistribution[1], 10^4];


Now you can take advantage of the EmpiricalDistribution function to define a model-free distribution based on your data.

edist = EmpiricalDistribution[data];


The core of what you are asking for is to obtain a TransformedDistribution, i.e starting from the distribution of $x$ to obtain the distribution of $f(x)$

ted = TransformedDistribution[Sqrt[x], x \[Distributed] edist];


Once you have any distribution, plotting the cumulative probability function becomes trivial using CDF

Plot[CDF[ted, x], {x, 0, 4}, PlotRange -> All]


Notice that an empirical distribution that allows the possibility of negative numbers should be truncated using TruncatedDistribution to avoid Sqrt of a negative.

ted = TransformedDistribution[Sqrt[x], x \[Distributed] TruncatedDistribution[{0,\[Infinity]},edist]];

• Using a Normal distribution (which generates negative values) to illustrate does not seem ideal if the intention is to take square roots of the data. – wolfies Oct 17 '14 at 7:34
• @wolfies, I have changed the example to an ExponentialDistributionbut kept the TruncatedDistribution explanation, as empirical distributions based on Kernel density may have non zero probability densities for x<0. Thanks for the correction. – rhermans Oct 17 '14 at 11:01
• Thanks for making this question useful! – Yves Klett Oct 17 '14 at 13:10

You can apply your transformation to your sample data and use EmpiricalDistribution on the transformed data without having to use TransformedDistribution:

data = RandomVariate[ExponentialDistribution[1], 10^4];
ed = EmpiricalDistribution[data];
edtr = EmpiricalDistribution[Sqrt@data];

Plot[{CDF[ed, x], CDF[edtr, x]}, {x, 0, 4},
PlotLegends -> {"CDF\nEmpiricalDistribution[data]", "CDF\nEmpiricalDistribution[Sqrt@data]"}]


data2 = RandomVariate[NormalDistribution[], 10^4];
ed2 = EmpiricalDistribution[data2];
edtr2 = EmpiricalDistribution[Abs@data2];

Plot[{CDF[ed2, x], CDF[edtr2, x]}, {x, -4, 4},
PlotLegends -> {"CDF\nEmpiricalDistribution[data]",  "CDF\nEmpiricalDistribution[Abs@data]"}]