6
$\begingroup$

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 ?

$\endgroup$
  • $\begingroup$ Hi ! I don't think this is a Mathematica related issue rather than a mathematics one. $\endgroup$ – Sektor Oct 16 '14 at 20:51
  • $\begingroup$ 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. $\endgroup$ – rhermans Oct 16 '14 at 21:37
11
$\begingroup$

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]

Mathematica graphics

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]];
$\endgroup$
  • 1
    $\begingroup$ 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. $\endgroup$ – wolfies Oct 17 '14 at 7:34
  • $\begingroup$ @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. $\endgroup$ – rhermans Oct 17 '14 at 11:01
  • 1
    $\begingroup$ Thanks for making this question useful! $\endgroup$ – Yves Klett Oct 17 '14 at 13:10
3
$\begingroup$

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

enter image description here

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

enter image description here

$\endgroup$

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.