gizmobench

Beta and Lognormal Distribution Lab

Set alpha and beta, or switch to lognormal and set μ and σ of log X, and the density redraws with your interval shaded. Beside it you get the mean, variance, median, mode, skewness and excess kurtosis; the probability between two values with the CDF subtraction written out; the quantile for any probability from 0.000001 to 0.999999 with its round trip back through the CDF; and up to 10,000 seeded draws, drawn as a histogram over the curve, summarised with a standard error and downloadable as CSV. What it does differently: a beta density that is infinite at 0 or 1 is labelled as infinite at that end instead of drawn as a tall finite peak, a tail too small for a double is printed from its logarithm instead of as 0, and a beta quantile next to 1 is shown as 1 minus its complement, computed separately so its digits survive.

Beta(2, 5)density, 0.1 to 0.4 shaded
Family

Alpha and beta each from 0.1 to 100. Below 1, the density is infinite at that end.

Show
Beta(2, 5) density on 0 to 1. Highest density drawn: 2.457600 at x 0.2. Shaded: 0.1 to 0.4, probability 0.652455.
Probability by bin
xmodeldraws
0 to 0.10.114265-
0.1 to 0.20.230375-
0.2 to 0.30.235185-
0.3 to 0.40.186895-
0.4 to 0.50.123905-
0.5 to 0.60.068415-
0.6 to 0.70.030025-
0.7 to 0.80.009335-
0.8 to 0.90.001545-
0.9 to 15.50000e-5-
results6 decimal places
mean
2/7 = 0.285714
variance
5/196 = 0.025510
SD
0.159719
median
0.264450
mode
1/5 = 0.200000
skewness
0.596285
excess kurtosis
-0.120000
Interval probability

P(0.1 < X < 0.4) = 0.652455

CDF(0.4) - CDF(0.1) = 0.766720 - 0.114265

x = 0.264450

round trip: CDF(0.264450) = 0.500000, relative gap 2.2e-16

Simulate

Drawing once the page has loaded.

Mean
0.285714
SD
0.159719
P(0.1 < X < 0.4)
0.652455
Median
0.264450
  • Beta(1, 1)mean, variance, CDF at 0.25
    mean 1/2 = 0.500000, variance 1/12 = 0.083333, CDF(0.25) = 0.250000
  • Beta(2, 1)CDF at 0.5, mean, variance
    CDF(0.5) = 0.250000, mean 2/3 = 0.666667, variance 1/18 = 0.055556
  • Lognormal, μ 0, σ 1CDF at 1, median, mean
    CDF(1) = 0.500000, median 1.000000, mean exp(0.5) = 1.648721
Accuracy. The parameters describe a mathematical model, not a fit to data or a prediction about real events, and in lognormal mode μ and σ are the mean and standard deviation of log(X), not of X. Probabilities, quantiles and moments are computed numerically, the incomplete beta by a continued fraction, and printed to six decimal places (six significant figures in e-notation below 0.0001 or from a billion up), with each quantile's round trip through the CDF shown; simulated summaries carry sampling error, shown as a standard error, and the same seed gives the same draws. A beta density that is infinite at 0 or 1 is labelled at that end rather than drawn as a finite peak.

Common questions

What do alpha and beta do to the shape of a beta distribution?
The mean is α/(α + β), and the larger α + β is, the tighter the distribution sits around it: the variance is αβ/((α + β)²(α + β + 1)). Equal values give a symmetric curve, and α = β = 1 is the flat uniform distribution. A shape below 1 makes the density infinite at its end: α below 1 at x = 0, β below 1 at x = 1, and the lab labels that end instead of drawing a finite peak. With whole-number shapes the mean and variance are also shown as exact fractions, such as 2/7 and 5/196 for Beta(2, 5).
How is the beta CDF computed?
The CDF of a beta distribution is the regularized incomplete beta function I_x(α, β). The lab evaluates it with a continued fraction (the Lentz method) on whichever side of (α + 1)/(α + β + 2) it converges faster, and takes the other tail from that one, carrying both as logarithms so a tail far below the smallest double, such as 4.52698e-542 for Beta(100, 100) below 0.000001, still prints. The fraction stops after 2,000 terms and reports a failure rather than show a half-converged value; across α and β from 0.1 to 100 it converges in a few dozen terms, at most 58 in the cases tested.
What are μ and σ in a lognormal distribution?
They are the mean and standard deviation of log(X), not of X. The median of X is e^μ, the mean is e^(μ + σ²/2) and the mode is e^(μ - σ²). The log x view plots the density of log X, which is the normal curve with mean μ and standard deviation σ. The lab reads μ from -10 to 10 and σ from 0.05 to 3.
How do I find a quantile (inverse CDF) of the beta distribution?
Enter a probability p from 0.000001 to 0.999999. The lab solves I_x(α, β) = p for x on the small side, so a quantile next to 1 keeps its digits: Beta(0.1, 0.1) at p = 0.99 prints as 1 - 8.86928e-18. It then puts x back through the CDF and shows the relative gap from p. A probability of exactly 0 or 1 is an end of the support, which the lab names rather than computes.
Why does the simulated mean not match the model mean exactly?
Draws carry sampling error. The lab shows the sample mean beside the model mean, the standard error (the sample standard deviation over the square root of the number of draws) and how many standard errors apart the two are, and the share of draws inside your interval beside the model probability. The same seed always gives the same draws, and New draws picks a fresh seed. With a lognormal and a large sigma the sample mean settles slowly, because a few very large draws dominate it.
What is in the CSV download?
One row per draw: the draw number, x, and for a beta 1 - x (kept separately, so a draw within about 1e-16 of 1 keeps its digits) or for a lognormal ln x. The file name records the parameters and the seed, and every cell below the header row is a plain number.

The parameters describe a mathematical model, not a fit to data or a prediction about real events, and in lognormal mode μ and σ are the mean and standard deviation of log(X), not of X. Probabilities, quantiles and moments are computed numerically, the incomplete beta by a continued fraction, and printed to six decimal places (six significant figures in e-notation below 0.0001 or from a billion up), with each quantile's round trip through the CDF shown; simulated summaries carry sampling error, shown as a standard error, and the same seed gives the same draws. A beta density that is infinite at 0 or 1 is labelled at that end rather than drawn as a finite peak.