---
title: "Fitting a continuous non-parametric second-order distribution to data"
canonical: "https://modelassist.epixanalytics.com/space/EA/26575314/Fitting%20a%20continuous%20non-parametric%20second-order%20distribution%20to%20data"
format: markdown
---
When we do not have a great deal of data, a considerable amount of uncertainty will remain about an empirical distribution determined directly from the data. It would be very useful to have the flexibility of using an empirical distribution, i.e. not having to assume a [parametric distribution](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26575199/), and also to be able to quantify the uncertainty about that distribution. The following Bayesian technique provides these requirements.

 

Consider a set of *n* data values {*x*<sub>*j*</sub>} drawn from a distribution, and ranked in ascending order {*x*<sub>*i*</sub>} so *x*<sub>*i*</sub>*<x*<sub>*i*</sub>*+1*. Data thus ranked are known as the order statistics of {*x*}. We can use these order statistics to construct a second order empirical cumulative distribution

 

Here are the mathematics behind the technique:

| Individually, each of the values of {*x*<sub>*j*</sub>} may map as a U(0,1) onto the cumulative probability of the parent distribution *F(x)*. We take a U(0,1) distribution as the prior distribution for the cumulative probability for any value of *x*. We can thus use a U(0,1) prior for *P*<sub>*i*</sub> = *F(x*<sub>*i*</sub>*)* for the value of the *i*<sup>th</sup> observation. However, we have the additional information that of *n* values drawn randomly from this distribution, *xi* ranked *i*<sup>th</sup>, i.e. (*i*-1) of the data values are less than *x*<sub>*i*</sub> and (*n-i*) values are greater than *x*<sub>*i*</sub>. Using [Bayes' Theorem](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26574955) and the [Binomial Theorem](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26574954), the posterior marginal distribution for *P*<sub>*i*</sub> can readily be determined, remembering that *Pi* has a U(0,1) prior and therefore a prior probability density = 1:<br>![image](media://1fd85cf1-313d-499b-92a0-5eddf0ce2133)<br>> Macro (mathblock)<br>which is simply the standard Beta distribution Beta(*i*,*n*-*i*+1):<br>![image](media://e090c501-9643-4f17-9daf-9cd040313503)<br>> Macro (mathinline)

                           (1)<br>Equation 1 could actually be determined directly from the fact that the beta distribution is the conjugate to the binomial likelihood function and that a U(0,1) = Beta(1,1). The mean of the Beta(*i*, *n-i*+1) distribution equals *i */ (*n*+1): a formula that has been used to estimate the [best-fitting first-order non-parametric cumulative distribution](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26575313).<br>Since *P*<sub>*i+1*</sub>>*P*<sub>*i*</sub>, these Beta distributions are not independent so we need to determine the conditional distribution f(*P*<sub>*i+1*</sub>*|P*<sub>*i*</sub>), as follows. The joint distribution f(*P*<sub>*i*</sub>*,P*<sub>*j*</sub>) for any two *P*<sub>*i*</sub>, *P*<sub>*j*</sub> is calculated using the Binomial Theorem in a similar manner to the numerator of the equation for f(*P*<sub>*i*</sub>*|x*<sub>*i*</sub>; i=1,n), i.e.:<br>![image](media://714d1a3e-c3eb-4b4e-817b-efadce46a6b3)<br>> Macro (mathblock)<br>where *P*<sub>*j*</sub>>*P*<sub>*i*</sub> and remembering that the prior probability densities for *P*<sub>*i*</sub> and *P*<sub>*j*</sub> equal 1 since they have U(0,1) priors.<br>For *j*=*i*+1:<br>![image](media://9877e041-f0bc-43be-8a42-8c3d6144d724)<br>> Macro (mathblock)<br>The conditional probability f(*P*<sub>*i+1*</sub>*|P*<sub>*i*</sub>) is thus given by:<br>![image](media://38eb67f2-ac1f-4fff-96ba-8a06c94b9a74)<br>> Macro (mathblock)<br>where *k* is some constant. The corresponding cumulative distribution function F(*P*<sub>*i+1*</sub>*|P*<sub>*i*</sub>) is then given by:<br>![image](media://5f148cf4-3c53-4bc2-85b5-585175d4df81)<br>> Macro (mathblock)<br>F(*P*<sub>*i+1*</sub>*|P*<sub>*i*</sub>)=1 at *P*<sub>*i+1*</sub>=1, so *k* = (*n*-*i*) and the formula reduces to:<br>![image](media://7c809ff3-36cf-4bd2-8b56-3bb8e30b77f2)<br>> Macro (mathinline)

    (2)<br>Equations 1 and 2 provide us with the tools to construct a non-parametric second-order distribution for a continuous variable given a data set sampled from that distribution. The distribution for the cumulative probability *P*<sub>*1*</sub> that maps onto the first order statistic X<sub>*1*</sub> can be obtained from Equation 1 by setting *i* = 1:<br>![image](media://b87ff60d-a59a-4b55-b29e-cfbfed92ac95)<br>> Macro (mathinline)

                                   (3)<br>The distribution for the cumulative probability *P*<sub>*2*</sub> that maps onto the first order statistic *X*<sub>*2*</sub> can be obtained from Equation 2. F(*P*<sub>*i+1*</sub>*|P*<sub>*i*</sub>), being a cumulative distribution function, is Uniform(0, 1) distributed. Thus, writing *U*<sub>*i+1*</sub> to represent a Uniform(0, 1) distribution in place of F(*P*<sub>*i+1*</sub>*|P*<sub>*i*</sub>), using the identity 1-U(0, 1) = U(0, 1), and rewriting for *P*<sub>*i+1*</sub>, we obtain:<br>![image](media://26368dcd-a126-412d-871d-141b09d61d94)<br>> Macro (mathinline)

                (4)<br>which gives:<br>![image](media://0f8f5dce-e4ca-4724-94d1-eaa171578d08)<br>> Macro (mathblock)<br>![image](media://cdbd186a-75d3-4f24-a4b9-8fe10b8279da)<br>> Macro (mathblock)<br>etc..<br>Note that each of the *U*<sub>*2*</sub>*, U*<sub>*3*</sub>*, …U*<sub>*n*</sub> Uniform distributions are independent of each other. |
| --- |

  


 

Recapping from the proof, the formulae from Equations 3 and 4 are:

 

         > Macro (mathinline)

                                            (3) 

![image](media://36d7a4d2-0265-4907-9c6c-f31be32df8e6)


          > Macro (mathinline)

                         (4)

![image](media://cc6f23cb-2a7d-47ee-a6d9-468dd0bc62b4)


 

where P<sub>*j*</sub> represents the estimate of the cumulative distribution function at x<sub>j</sub>, = F(x<sub>*j*</sub>). These can be used as inputs to construct a [Cumulative distribution](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26575222/), together with subjective estimates of the minimum and maximum values that the variable may take, which can also be assigned subjective distributions.

 

Model [NonParaCont2](#NonParaCont2) creates a second-order distribution using this technique.

> Macro (anchor)



The links to the NonParaCont2 software specific models are provided here:

<details>
<summary>Crystal Ball</summary>

> Macro (inline-media-image)

 [NonParaCont2](/wiki/download/attachments/26579343/NonParaCont2-CB.xlsx?version=1&modificationDate=1506113497000&cacheVersion=1&api=v2)

 

Note that in Crystal Ball, as F(x) changes from iteration to iteration, the Custom Distribution therefore needs to be capable of [dynamic referencing](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26575288/).

 

##### Using this technique in a second order model

Use [Crystal Ball's 2-D simulation Tool](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26575571/), as also illustrated [here](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26575534):

- Select "Run" >> "Tools" >> 2D Simulation;
- In Step 1 of 3, select "Forecast" (Cell I14) as target;
- Click Next
- In Step 2 of 3, select the assumption "Distribution (Model)" as Variability (all other assumptions are uncertainty)
- Click Next
- If you run the outer (uncertainty) simulation for 10 trials and run inner (variability) simulation for 1000 trials, this will result in the following second order model:

 

![image](media://3d30e61e-6f15-4b5f-b46e-60fe6264e0d0)
</details>

<details>
<summary>@Risk</summary>

> Macro (inline-media-image)

 [NonParaCont2](/wiki/download/attachments/26581760/NonParaCont2-AtRISK.xlsx?version=1&modificationDate=1506097517000&cacheVersion=1&api=v2)

 

In @Risk the inputs to [RiskCumul](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26581732) can be formulated as: <span style="color: #000000">=RiskCumul(min, max, {x</span>*j*<span style="color: #000000">}, {P</span>*j*<span style="color: #000000">})</span>

  


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

##### Using this technique in a second order model

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

- The uncertainty distributions for *F(x)* are nominated as outputs;
- A smallish number of iterations are run;
- The resultant data are exported back to a spreadsheet;
- Those data are then used to perform multiple simulations (the ”outer loop”) of uncertainty using @RISK’s RiskSimtable function: the ”inner loop” of comes from the Cumulative distribution itself
</details>

##### Limitations

There are a few limitations to this technique. In using a [Cumulative distribution](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26575222/), one is assuming a histogram style probability distribution function between each of the {x} values. When there are a large number of data points, this approximation becomes irrelevant. However, for small data sets the approximation will tend to accentuate the tails of the distribution: a result of the histogram "squaring-off" effect of using the Cumulative distribution. In other words, the variability will be slightly exaggerated. However, the squaring effect can be reduced, if required, by using some sort of smoothing algorithm and defining points between each observed value. In addition, for small data sets, 'the tails' contribution to the variability will often be more influenced by the subjective estimates of the minimum and maximum values: a fact one can view positively (one is recognizing the real uncertainty about a distribution's tail), and negatively (the smaller the data set, the more the technique relies on subjective assessment).

 

The fewer the data points, the wider the confidence intervals will become quite naturally and, in general, the more emphasis will be placed on the subjectively defined minimum and maximum values. Conversely, the more data points available, the less influence the minimum and maximum estimates will have on the estimated distribution. In any case, the values of the minimum and maximum only have influence on the width (and therefore height) of the end two histogram bars in the fitted distribution. The fact that the technique is non-parametric, i.e. that no statistical distribution with a particular cumulative distribution function is assumed to be underlying the data, allows the analyst a far greater degree of flexibility and objectivity than that afforded by fitting parametric distributions.

 

 

 

---