Distributions

There are rarely truly static parameters in life. In business, either. Creating distribution-based business cases is pretty easy to do and a powerful way to model and add probability to your estimates.

Let's create the fundamental primatives for working with distributions. Then let's introduce some math to manipulate them.

Instantiating and plotting distributions

Let's first create some distributions using the DistP class we just made, starting with a normal and a lognormal distribution.

The following distributions functions are available.

  1. normal
  2. uniform
  3. exponential
  4. lognormal
  5. triangular
  6. beta
  7. gamma
  8. weibull
  9. custom

N.b., that the idea behind the custom distribution is actually to use real data. in other words, why fit a distribution if you have actual data? This is implemented in the python version of this package, but not yet in javascript.

Normal distribution

Lognormal distribution

Beta distribution

Beta distributions are super flexible. They can be uniform, or resemble lognormal skewed left or right. Play around.

Operations on distributions for business cases

I'm convinced that almmost everyone builds terrible business cases. Every parameter in a business case is actually a distribution. Thus, distributions as an object or entity are important to be able to use, and on which we're able to do some quick math.

Let's say that the prevalence of a disease across counties varies in an approximatly lognormal manner, centered about ~20% prevalence. Let's say it's actually a beta distribution.

Let's create that distribution and visualize it.

Let's explore chaining

Let's add two distributions together.

// Chain operations
const addResult = new DistP({
    name: "Normal + Lognormal",
    samples: [...normalBase.samples],
    size: 5000
}).chainAdd(uniformDist);
view(addResult.plot())

Let's multiply two distributions together.

// Chain operations
const multResult = new DistP({
    name: "Normal × Uniform",
    samples: [...normalBase.samples],
    size: 5000
}).chainMult(uniformDist);

//plot it
view(multResult.plot())

Let's divide two distributions.

const divResult = new DistP({
    name: "Normal ÷ Uniform",
    samples: [...normalBase.samples],
    size: 5000,
}).chainDivide(uniformDist);

//plot it
view(multResult.plot())