---
title: "Method 1"
canonical: "https://modelassist.epixanalytics.com/space/EA/26575273/Method%201"
format: markdown
---
# Generating your own distribution when you know the cdf, pdf or pmf

  


#### Situation:

You wish to use a parametric probability distribution that is not available in your software, and you know:

  


[The cumulative distribution function](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26574886/) (continuous variable);

[The probability density function](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26574888/) (continuous variable); or

[The probability mass function](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26574887/) (discrete variable).

  


This section describes the technique for each situation.

  


---

####  

#### Known cumulative distribution function (cdf)

This method applies when you know the cdf of a [continuous probability distribution](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26575215/). The algebraic equation of the cdf can often be inverted to make x the subject of the equation. For example, the cdf of the [Exponential](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26575227/) probability distribution is:

  
(1)

![image](media://c0f19692-9842-479f-a642-08c5a0688405)

  


> Macro (mathblock)

                                                                        

Where b is the mean of the [Exponential distribution](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26575227/). Inverting equation 1 to make x its subject gives:

  
(2)

![image](media://1d8588a4-239b-409c-a77e-1aff31448ca6)

  


> Macro (mathblock)

                                                                         

A random sample from any continuous probability distribution has equal probability of lying in any equally sized range of F(x) between [zero and one](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26575291/). For example, the variable X has a 10% probability of producing a value between x<sub>1</sub> and x<sub>2</sub> (x<sub>2</sub>>x<sub>1</sub>) where F(x<sub>2</sub>)-F(x<sub>1</sub>) = 0.1. Looking at it the other way around, F(x) can be thought of as being a [Uniform](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26575256/)(0,1) random variable. Thus, we can write Equation 2 as a general formula to generate values from an Exponential distribution with a mean of 23 as follows:

  
(3)

= -23*LN(1-Uniform(0,1))                           

  


or [can you see why?]:

  
(4)

= -23*LN(Uniform(0,1))                              

  


This is exactly equivalent to writing:

  


=Exponential(1/23)

  


in a cell. [Try it if you like]. Since we have used one distribution to generate another, if we use <u><span style="color: #0000ff"> </span></u><u><span style="color: #0000ff">[Latin Hypercube Sampling](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26575293/)</span></u> (LHS) to draw from the Uniform(0,1) distribution, we will get Latin Hypercube samples from the constructed [Exponential](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26575227/) distribution too. Similarly, if we force the Uniform distribution to sample from its lower end – a technique necessary for advanced sensitivity analysis and stress analysis for example, Equation 3 (but *not* Equation 4) will generate values from the lower end of the Exponential distribution.

  


##### Disadvantage

The method hinges on being able to perform the algebra that inverts the cdf. If that proves too difficult, it may be easier to [construct](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26575276) the cdf with a [Cumulative](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26575435/) distribution.

#### **Known probability density function (****[pdf](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26574888)****)**

We may sometimes start with the pdf for a variable, determine the cdf by integration, and then use the [first method](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26575273/) although this generally requires good maths skills. Another reason one might like to determine the cdf could be an interest in the probability of the variable being below, between or above certain values. Integration of the pdf will give the cdf which can give you these probabilities. The example below shows you how to determine a cdf, starting with a pdf, in this case of a sine curve distribution.

  


Imagine that you want to design a distribution that followed the shape of a sine curve from 0 to *a*, where *a* is an input to the distribution. This distribution shape is shown in Figure 1.

![image](media://531b1c84-ed18-42d8-ac68-ee06e9a07668)

**Figure 1**: The sine curve distribution we wish to create in our example

  


The probability density function *f(x)* is given by:

![image](media://dc527c59-aa32-43a4-a51c-0c17b55a3a34)

  


  


> Macro (mathblock)

  


where *b* is a constant to be determined so that the area under the curve equals one, as required for a probability distribution.

  


The cdf *F(x)* is then (0<x<a):

![image](media://4f0ca524-a511-457b-bad6-a2644c1c4738)

  


<span style="color: #ff0000">                </span>  


> Macro (mathblock)

  


![image](media://8d85fe51-0f3b-4202-9423-9ba57324dd83)

  


  


> Macro (mathblock)

  
(1)

![image](media://27025cba-b8df-4e24-904e-0814692f89f2)

<span style="color: #ff0000">                       </span>  


> Macro (mathblock)

<span style="color: #ff0000">                </span>

<span style="color: #ff0000">                                                                           </span>

<span style="color: #000000">For the area under the curve to equal one, </span><span style="color: #000000">*b*</span><span style="color: #000000"> must be determined such that </span><span style="color: #000000">*F(a)*</span><span style="color: #000000"> = 1, i.e.:</span>

  


![image](media://7f91471e-180f-4673-b673-c10bfc2e0ce4)

<span style="color: #000000">                </span>  


> Macro (mathblock)

  


  


<span style="color: #000000">Therefore,</span>

![image](media://14485db0-e259-45fb-8361-8adf5fd6e92a)

  


<span style="color: #000000">                </span>  


> Macro (mathblock)

  


  


<span style="color: #000000">and, from Equation 1, </span><span style="color: #000000">*F(x)*</span><span style="color: #000000"> becomes:</span>

![image](media://01cf6518-02e8-4907-ac87-ea6c68bed437)

  


<span style="color: #000000">                </span>  


> Macro (mathblock)

  


  


<span style="color: #000000">We now need to find the inverse function to </span><span style="color: #000000">*F(x)*</span><span style="color: #000000">. So, rearranging the equation above for </span><span style="color: #000000">*x*</span><span style="color: #000000">:</span>

![image](media://590dbe92-ac65-4ad0-8b7c-36c825b3b185)

  


<span style="color: #000000">                </span>  


> Macro (mathblock)

  


  


To generate this distribution, we put a Uniform(0,1) distribution in cell A1 (say), the value for *a* in cell B1 (say) and, in the cell that generates values of *x*, we write:

  


                = B1/PI() * ACOS (1-2*A1)   (The Excel function ACOS(y) returns cos<sup>-1</sup>(y) )

  


If we use [Latin Hypercube Sampling](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26575293/) to generate the values from the Uniform(0,1) distribution, we will generate a smoothly distributed set of *x*-values that will replicate the desired distribution.

  


  


#### **Known probability mass function (****[pmf](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26574887)****)**

If you know the pmf of a distribution, it is a simple matter (in principle) to create the distribution in your software. The techniques above are not applicable because a cdf for a discrete variable is just the sum of the discrete probabilities, and it is thus not possible to construct an inverse transformation.

  


The method requires that you use two columns of data in Excel:

  


The first column is a set of value that the variable might take, e.g. {0,1,...99,100}

The second column is a set of probabilities using the pmf calculated for each of these values {p(0),p(1),...p(99),p(100)}

  


These two arrays are then used to construct the required distribution using a discrete distribution, such as the one implemented in [Crystal Ball's Discrete distribution](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26575279/).

  


Of course, this method can become cumbersome if the {x} array is very large. In which case:

  


1. Make the {x} list with spacing larger than 1, e.g. {0,5,10,..495,500};
2. Calculate the associated probabilities {p(0),p(5),...p(495),p(500)}
3. Construct a [General distribution](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26575232/).
4. In the cell in which you need the final distribution, wrap a ROUND function around the cell containing the General distribution; =ROUND(A5,0) to return discrete value
5. Note that using a minimum = -0.5 (x<sub>1</sub>-0.5) and a maximum 500.5 (x<sub>n</sub>=0.5) will allocate a more accurate probability to the end values.

  


  


  


---