← Laboratorium Mathematics · experiment

Mathematics · probability theory

Probability chance has its laws

Nobody can predict a single roll of a die. But a thousand rolls fall into a shape you can calculate to a fraction of a percent. Roll dice, drop balls through a Galton board, play against Monty Hall, and find out why a positive test doesn't always mean “you're sick” — and how a chart can lie even when every number on it is true.

P(A) = favorableall E[X] = Σ xi · pi P(A | B) = P(B | A) · P(A)P(B)
Q–Y modes Challenges 0/6

Law of large numbers

What we throw

Throws0
Most common result—
Measured mean—
Expected value7
Selected bar—

The gambler's fallacy

After five heads in a row, “tails is due”? A coin has no memory. Let's check, over a huge number of tosses, what comes up right after a run of heads.

Click, and the computer will toss a million times and find every run.
heads —tails —

Can you fake randomness?

Type 50 “random” tosses off the top of your head: the letter H is heads, T is tails (or click the buttons). Then compare your sequence with a truly random one. People usually switch too often and avoid long runs — yet in 50 tosses a run of 5 or more identical results happens about 4 times out of 5.

0/50
Your sequencelongest run: — · switches: —
True randomnesslongest run: — · switches: —

The red frame marks the longest run. A truly random sequence of 50 tosses has on average about 24–25 switches, and its longest run is usually 5–7 tosses.

MathematicsHow to calculate chance

Probability and frequency

When all outcomes of a trial (a throw, a draw) are equally likely, the probability of an event A is the ratio of the number of favorable outcomes to the number of all outcomes:

P(A) = |A||Ω|, P(sum 7) = 636 = 16

The law of large numbers says that in a long series of independent trials the frequency nA/n approaches P(A). Typical fluctuations shrink like 1/√n: to make the error ten times smaller, you need a hundred times more trials. The law does not work by “evening out” — a coin doesn't remember previous tosses; an excess of heads simply gets diluted in an ever larger number of tosses.

Independence and conditional probability

P(A and B) = P(A) · P(B) (if independent), P(A | B) = P(A and B)P(B)

From this follows Bayes' theorem — a recipe for reversing a condition:

P(sick | +) = P(+ | sick) · P(sick)P(+ | sick) · P(sick) + P(+ | healthy) · P(healthy)

For a disease that affects 1 in 1000 people and a test with 99% sensitivity and specificity, the answer is only about 9%: false alarms among the 999 healthy people outnumber the truly sick ten to one. Psychologist Gerd Gigerenzer showed that people reason about this much better when, instead of percentages, they get natural frequencies: “10 sick out of 10,000, the test catches almost all of them; 100 false positives.”

Distribution, mean and deviation

A distribution tells you how often each result occurs. The two basic numbers are the mean (the center of mass) and the standard deviation (the typical distance from the mean):

x̄ = x1 + … + xnn, σ = √(Σ (xi − x̄)² / n)

The median is the middle value once the data are sorted from smallest to largest — half the results are smaller, half larger. It is robust to outliers; the mean is not. The mode is the most common result. The expected value E[X] = Σ xi pi is the average you can expect over a very long series — for a casino, it is simply its profit per bet.

The binomial distribution and the Gaussian curve

A ball on a Galton board turns right in each of the n rows with probability p, independently of earlier bounces. The number of right turns k has a binomial distribution:

P(k) = n!k! (n − k)! pk (1 − p)n−k, μ = np, σ = √(np(1 − p))

For large n it resembles the normal distribution (the Gaussian curve). By the central limit theorem, the sum of many independent terms with finite variance behaves the same way — which is why the bell shows up in measurement errors and, approximately, in people's heights. About 68% of results lie within μ ± σ, about 95% within μ ± 2σ, and about 99.7% within μ ± 3σ.

f(x) = 1σ√(2π) · e−(x − μ)² / (2σ²)

Correlation vs. causation, samples and error

The correlation coefficient r (from −1 to 1) measures how closely the points line up along a straight line. A high r doesn't tell you what causes what: ice cream sales and drownings rise together because both are driven by summer. In a poll with a sample of n random people, the error of the result (at about 95% confidence) is roughly ±1/√n: for 1000 people, about ±3 percentage points — as long as the sample is truly random.

Simplifications on this page

The balls on the Galton board are not physically simulated: each bounce is a separate random draw with probability p, and the motion is just animation. In the Monty Hall game the host always opens a door with a goat and always offers a switch. The birthday paradox assumes 365 equally likely days (no February 29). The second test in Bayes mode is independent of the first — real repeated tests often aren't. The data on height, income, cities, ice cream and polls are generated for illustration; they only roughly match the shape of real data.

Did you know…?

  • It takes only 23 people for the chance that two of them share a birthday to exceed 50% (exactly 50.7%). With 70 people it's already over 99.9%.
  • A deck of 52 cards can be arranged in 52! ≈ 8 · 10⁶⁷ ways. So a well-shuffled deck is almost certainly in an order that no one has ever seen before.
  • Stanisław Ulam, a mathematician from Lwów, came up with the Monte Carlo method while playing solitaire as he recovered from an illness, wondering how often a game could be won. Instead of calculating, it was easier to… play it many times.

Challenges

  • Most common sum of two diceRoll two dice at least 10,000 times and click the bar of the most common sum.not completed
  • A bell curve from 500 ballsCollect at least 500 balls in the bins of the Galton board.not completed
  • 20 wins by switchingWin 20 Monty Hall games (3 doors) by switching doors.not completed
  • The birthday paradox thresholdFind the smallest number of people for which a shared birthday is more likely than not.not completed
  • A test you can trustSet the prevalence, sensitivity and specificity so that a single positive result means disease in more than 90% of cases.not completed
  • Mean versus medianShow data in which the mean exceeds the median by more than half (e.g., median 10, mean over 15).not completed

Challenges check themselves. Progress is saved in this browser.

See also

Genetic drift, radioactive decay, the speeds of gas molecules and measurement in quantum mechanics — probability rules them all.