--- title: "Creating Distributions" sidebar_position: 8 --- import TOCInline from "@theme/TOCInline"; import { SquiggleEditor } from "../../src/components/SquiggleEditor"; import Admonition from "@theme/Admonition"; import Tabs from "@theme/Tabs"; import TabItem from "@theme/TabItem"; ## To `(5thPercentile: float) to (95thPercentile: float)` `to(5thPercentile: float, 95thPercentile: float)` 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. When `5 to 10` is entered, both numbers are positive, so it generates a lognormal distribution with 5th and 95th percentiles at 5 and 10. `5 to 10` does the same thing as `to(5,10)`. When `-5 to 5` is entered, there's negative values, so it generates a normal distribution. This has 5th and 95th percentiles at 5 and 10. It's very easy to generate distributions with very long tails. If this happens, you can click the "log x scale" box to view this using a log scale. ### Arguments - `5thPercentile`: Float - `95thPercentile`: Float, greater than `5thPercentile`

"To" is a great way to generate probability distributions very quickly from your intuitions. It's easy to write and easy to read. It's often a good place to begin an estimate.

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?: float[])` `mx(...distributions: Distribution[], weights?: float[])` The `mixture` mixes combines multiple distributions to create a mixture. You can optionally pass in a list of proportional weights. ### Arguments - `distributions`: A set of distributions or floats, each passed as a paramater. Floats will be converted into Delta distributions. - `weights`: An optional array of floats, 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 assignment. 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,

🔒 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.

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 assignment. I think I have an 80% chance of doing it.

## Normal `normal(mean:float, standardDeviation:float)` Creates a [normal distribution](https://en.wikipedia.org/wiki/Normal_distribution) with the given mean and standard deviation. ### Arguments - `mean`: Float - `standard deviation`: Float greater than zero [Wikipedia](https://en.wikipedia.org/wiki/Normal_distribution) ## Log-normal `lognormal(mu: float, sigma: float)` Creates a [log-normal distribution](https://en.wikipedia.org/wiki/Log-normal_distribution) with the given mu and sigma. ### Arguments - `mu`: Float - `sigma`: Float greater than zero [Wikipedia](https://en.wikipedia.org/wiki/Log-normal_distribution) ### Argument Alternatives `Mu` and `sigma` can be difficult to directly reason about. Because of this complexity, we recommend typically using the to syntax.
❓ 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:float, high:float)` Creates a [uniform distribution](https://en.wikipedia.org/wiki/Uniform_distribution_(continuous)) with the given low and high values. ### Arguments - `low`: Float - `high`: Float 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.

## Beta ``beta(alpha:float, beta:float)`` Creates a [beta distribution](https://en.wikipedia.org/wiki/Beta_distribution) with the given `alpha` and `beta` values. For a good summary of the beta distribution, see [this explanation](https://stats.stackexchange.com/a/47782) on Stack Overflow. ### Arguments - `alpha`: Float greater than zero - `beta`: Float 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
## Exponential ``exponential(rate:float)`` Creates an [exponential distribution](https://en.wikipedia.org/wiki/Exponential_distribution) with the given rate. ### Arguments - `rate`: Float greater than zero ## Triangular distribution ``triangular(low:float, mode:float, high:float)`` Creates a [triangular distribution](https://en.wikipedia.org/wiki/Triangular_distribution) with the given low, mode, and high values. #### Validity ### Arguments - `low`: Float - `mode`: Float greater than `low` - `high`: Float greater than `mode` ## FromSamples Creates a sample set distribution using an array of samples. #### Validity For `fromSamples(xs)`, - `xs.length > 5` - Strictly every element of `xs` must be a number.