Probability in numbers
Statistics and Special Functions: Distributions, Tails and Quantiles

Statistical software leans on a small family of special functions. The normal distribution rests on the error function, the chi-square and Poisson distributions on the incomplete gamma function, and the t and F distributions on the incomplete beta function. This section explains those building blocks and the calculations on top of them: densities, tail probabilities, quantiles and random draws.
The normal family
Everything starts with the bell curve. The normal probability density is the formula, and the area under it up to a point is the distribution function, which equals a shifted and rescaled error function. Going the other direction, from a probability to the point that has it, needs an inverse. The inverse error function page works one by hand and tabulates values, and the inverse normal distribution page treats the same job in terms of quantiles. A confidence level of 95 percent corresponds to the multiplier 1.96, and the rest of the family follows the same pattern.
Tails and tests
A p-value is a tail probability, the chance of a result at least as extreme as the observed one. For small samples it comes from the t distribution, and for comparing variances from the F distribution. The pages on the Student t tail and the F distribution tail show how those numbers are obtained. The incomplete gamma function, treated on its own page, serves chi-square tails and Poisson sums.
Random numbers
Simulation needs draws from named distributions. The usual recipe starts from uniform random numbers and transforms them, either by inverting the distribution function or by an acceptance scheme. Pages here cover binomial, gamma and Poisson generators, and a page on histograms for checking that the sample looks like its target.
Practical advice
Read tables and software output with the convention in mind. Some routines return the lower tail, some the upper tail, and some a two-sided probability; mixing them up doubles or halves a p-value without any visible sign.
Compute tails directly. For extreme events, subtracting a probability that is nearly 1 from 1 destroys the digits that matter, so careful code evaluates the small tail itself. And test any distribution routine at a few points whose values you know independently, for example the median of the normal distribution at 0.
Quantile and tail ideas in action appear in the overview of numerical methods in practice. Matrix methods for fitting models are in linear algebra, and the glossary defines the terms used.
Questions about statistics
What is a p-value?
A p-value is the probability, assuming the null hypothesis is true, of seeing a result at least as extreme as the one observed. It is not the probability that the hypothesis is true. A small value indicates that the data would be unusual under the null model, while a large one means only that the data are compatible with it.
When should I use the t distribution instead of the normal?
Use the t distribution when the population standard deviation is unknown and has to be estimated from a small sample. Its tails are heavier than the normal’s, which allows for the extra uncertainty. As the sample grows the two curves become nearly identical, and beyond a few dozen observations the difference is small.
What is the difference between a probability density and a probability?
A density gives relative likelihood at a point, and its values can exceed 1. Probabilities come from areas: the chance that a variable falls between two values is the integral of the density across that interval. For a continuous variable, the probability of any single exact value is zero.
How do I check that random numbers have the right distribution?
Generate a large sample and compare its mean, variance and histogram with the theoretical values. A binomial sample with n trials and probability p, for instance, should average near np. A histogram against the expected density, or a quantile comparison, shows shape problems that moments alone can miss.
Binomial Random Numbers (binornd)
Binomial random numbers count successes in n trials; two exact methods, direct counting and inversion, are shown with a worked case.
F Distribution Tail Probability (ftail)
The upper tail of the F distribution gives the p-value of a variance-ratio test; here is how it is defined, computed and checked.
Gamma Random Numbers (gamrnd)
Gamma variates come from exponential sums when the shape is an integer and from a rejection method otherwise, with a worked example of each.
Histograms: Bins, Counts and Density
A histogram counts observations in adjacent bins; the page covers bin choice, density scaling and a small hand-checked example.
Incomplete Gamma Function
The regularized incomplete gamma function P(a, x) underlies chi-square and Poisson probabilities; a series and a continued fraction compute it.
Inverse Error Function (erfinv): Formula, Calculator Method and Table of Values
The inverse error function erfinv(x), its series formula, a hand-worked Newton calculation, and a table of values linking it to normal quantiles.
Inverse Normal Distribution (Quantile Function)
The inverse normal function turns a probability into the point on the axis that has that much area below it; Newton iteration computes it.
Normal Probability Density (normpdf)
The normal density function gives the height of the bell curve at a point; the page shows the formula, hand-checked values and the log form.
Poisson Random Numbers (poissrnd)
Poisson random numbers count events at a fixed average rate; the multiplication method and table inversion are worked through with real numbers.
Student t Tail Probability (ttail)
The t tail function returns P(T > t) for given degrees of freedom; exact cases and a small table help verify any implementation.