# Distributions: Creation

## To

`(5thPercentile: number) to (95thPercentile: number)`

`to(5thPercentile: number, 95thPercentile: number)`

The `to`

function is an easy way to generate simple distributions using predicted *5th* and *95th* percentiles.

If both values are above zero, a `lognormal`

distribution is used. If not, a `normal`

distribution is used.

- 5 to 10
- to(5,10)
- -5 to 5
- 1 to 10000

`5 to 10`

is entered, both numbers are positive, so it generates a lognormal distribution with 5th and 95th percentiles at 5 and 10.### Arguments

`5thPercentile`

: number`95thPercentile`

: number, greater than`5thPercentile`

"

If you haven't tried calibration training, you're likely to be overconfident. We recommend doing calibration training to get a feel for what a 90 percent confident interval feels like.

## Mixture

`mixture(...distributions: Distribution[], weights?: number[])`

`mx(...distributions: Distribution[], weights?: number[])`

`mixture(distributions: Distribution[], weights?: number[])`

`mx(distributions: Distribution[], weights?: number[])`

The `mixture`

mixes combines multiple distributions to create a mixture. You can optionally pass in a list of proportional weights.

- Simple
- With Weights
- With Continuous and Discrete Inputs
- Array of Distributions Input

### Arguments

`distributions`

: A set of distributions or numbers, each passed as a paramater. Numbers will be converted into point mass distributions.`weights`

: An optional array of numbers, each representing the weight of its corresponding distribution. The weights will be re-scaled to add to`1.0`

. If a weights array is provided, it must be the same length as the distribution paramaters.

### Aliases

`mx`

### Special Use Cases of Mixtures

## 🕐 Zero or Continuous

One common reason to have mixtures of continous and discrete distributions is to handle the special case of 0. Say I want to model the time I will spend on some upcoming project. I think I have an 80% chance of doing it.

In this case, I have a 20% chance of spending 0 time with it. I might estimate my hours with,

There's a temporary bug where the below render is compressed. If you toggle the code it will fix render correctly.

## 🔒 Model Uncertainty Safeguarding

One technique several Foretold.io users used is to combine their main guess, with a "just-in-case distribution". This latter distribution would have very low weight, but would be very wide, just in case they were dramatically off for some weird reason.

## Normal

`normal(mean:number, standardDeviation:number)`

Creates a normal distribution with the given mean and standard deviation.

- normal(5,1)
- normal(1G, 1G)

### Arguments

`mean`

: Number`standard deviation`

: Number greater than zero

## Log-normal

`lognormal(mu: number, sigma: number)`

Creates a log-normal distribution with the given mu and sigma.

`Mu`

and `sigma`

represent the mean and standard deviation of the normal which results when
you take the log of our lognormal distribution. They can be difficult to directly reason about.
Because of this complexity, we recommend typically using the to syntax instead of estimating `mu`

and `sigma`

directly.

### Arguments

`mu`

: Number`sigma`

: Number greater than zero

## ❓ Understanding mu and sigma

The log of `lognormal(mu, sigma)`

is a normal distribution with mean `mu`

and standard deviation `sigma`

. For example, these two distributions are identical:

## Uniform

`uniform(low:number, high:number)`

Creates a uniform distribution with the given low and high values.

### Arguments

`low`

: Number`high`

: Number greater than`low`

While uniform distributions are very simple to understand, we find it rare to find uncertainties that actually look like this. Before using a uniform distribution, think hard about if you are really 100% confident that the paramater will not wind up being just outside the stated boundaries.

One good example of a uniform distribution uncertainty would be clear physical limitations. You might have complete complete uncertainty on what time of day an event will occur, but can say with 100% confidence it will happen between the hours of 0:00 and 24:00.

## Point Mass

`pointMass(value:number)`

Creates a discrete distribution with all of its probability mass at point `value`

.

Few Squiggle users call the function `pointMass()`

directly. Numbers are converted into point mass distributions automatically, when it is appropriate.

For example, in the function `mixture(1,2,normal(5,2))`

, the first two arguments will get converted into point mass distributions
with values at 1 and 2. Therefore, this is the same as `mixture(pointMass(1),pointMass(2),pointMass(5,2))`

.

`pointMass()`

distributions are currently the only discrete distributions accessible in Squiggle.

- pointMass(3)
- mixture(1,3,5)
- normal(5,2) * 6
- dotAdd(normal(5,2), 6)
- dotMultiply(normal(5,2), 6)

### Arguments

`value`

: Number

## Beta

`beta(alpha:number, beta:number)`

`beta({mean: number, stdev: number})`

Creates a beta distribution with the given `alpha`

and `beta`

values. For a good summary of the beta distribution, see this explanation on Stack Overflow.

- beta(10, 20)
- beta(1000, 1000)
- beta(1, 10)
- beta(10, 1)
- beta(0.8, 0.8)
- beta({mean: 0.39, stdev: 0.1})

### Arguments

`alpha`

: Number greater than zero`beta`

: Number greater than zero

Squiggle struggles to show beta distributions when either alpha or beta are below 1.0. This is because the tails at ~0.0 and ~1.0 are very high. Using a log scale for the y-axis helps here.

## Examples

- beta(0.3, 0.3)
- beta(0.5, 0.5)
- beta(0.8, 0.8)
- beta(0.9, 0.9)

## Exponential

`exponential(rate:number)`

Creates an exponential distribution with the given rate.

### Arguments

`rate`

: Number greater than zero

## Triangular distribution

`triangular(low:number, mode:number, high:number)`

Creates a triangular distribution with the given low, mode, and high values.

### Arguments

`low`

: Number`mode`

: Number greater than`low`

`high`

: Number greater than`mode`

## SampleSet.fromList

`SampleSet.fromList(samples:number[])`

Creates a sample set distribution using an array of samples.

### Arguments

`samples`

: An array of at least 5 numbers.

Samples are converted into PDF shapes automatically using kernel density estimation and an approximated bandwidth. Eventually Squiggle will allow for more specificity.

## PointSet.makeContinuous

`PointSet.makeContinuous(points:{x: number, y: number})`

Creates a continuous point set distribution using a list of points.

### Arguments

`points`

: An array of at least 3 coordinates.

## PointSet.makeDiscrete

`PointSet.makeDiscrete(points:{x: number, y: number})`

Creates a discrete point set distribution using a list of points.

### Arguments

`points`

: An array of at least 1 coordinate.