Interactive figures
Every figure in the track. Each one is a small experiment: drag, slide, and watch the numbers. The link under each figure takes you to the lesson that explains it.
Lesson 1 · Probability and Bayes' rule
Press "Condition on B". Everything outside B (blue) fades, and is stretched to fill the whole square: it is the new sample space. The share of the new square covered by (aqua) is . Compare it with the share of the old square covered by A (violet), which is . Then drag the corner dots, and try the presets: in "independent", covers the same share of as of . In "disjoint", .
First set your guess, then press "Test everyone". Each small square is one of 10,000 people. Aqua squares are sick people who test positive; faint aqua squares are sick people the test misses. Magenta squares are healthy people with a positive test (false alarms). is the aqua count divided by aqua plus magenta. Raise the prevalence to 20% and watch the answer change, with the same test. Then press "Second test": only the positives are tested again.
Add test results with + and −. The axis is the log-odds, with probabilities written on top. The violet dot is the prior. Each aqua arrow is one update: every independent positive is a step of the same length, , to the right. Now raise the dependence : with probability the second test only copies the first (same blood sample, same cable). Repeated results then carry less evidence. The magenta dashed track is the naive update that still multiplies the full likelihood ratios, so it counts the same evidence twice.
Play a few games by clicking a door, then press "Run 1,000 games". The chart shows the running win rate of stay (violet) and switch (aqua); the orange dashed lines are the exact values 1/3 and 2/3. Try 10 doors. Then choose "opens doors at random": the host may now show the car, and we keep only the games where he showed goats. Both strategies then win half of the kept games.
Press "Pool the groups". Each block is one treatment. Its two columns are the patient groups, with widths proportional to the number of patients. The blue height is the success rate, so the blue area is the number of successes. Pooling levels the blue area inside each block without changing it; the yellow dashed line is the pooled rate. Then choose "same case mix": with equal weights, A wins pooled too.
Lesson 2 · Random variables and expectation
Move and , then switch the distribution. The top panel shows the distribution in orange: bars for the sum of two dice, a curve for the exponential and the normal. The probability of the interval is yellow: the sum of the shaded bars, or the shaded area. In the CDF below, the same number is the rise of the curve from to (the thick yellow bar). For the exponential with rate 2, notice that the curve starts at height 2: a density value is not a probability.
Predict where the beam balances, then drag the dark triangle (the fulcrum) there. The orange discs are the probabilities , placed at the values . The readout shows the torque ; the beam is level when it is 0. Press "Show the mean" to see (yellow) and the band (violet). Then try "one far mass": a mass of 0.1 at moves the balance point from 1 to 1.7 and makes the variance much larger.
Move the level , then press "Draw 500". The yellow path goes from on the vertical axis across to the orange CDF and down to . Each draw uses a new uniform . The blue histogram of the samples matches the orange density below. Notice that for the CDF is steepest at , and most samples land there. Try "discrete": the CDF is a staircase, and each step catches the levels that belong to one value.
Move the interval, then switch the map . is uniform on . The yellow interval on the -axis holds probability equal to its width. The map (orange curve) sends it to the yellow interval on the -axis, which holds the same probability. Where is wide, the density of is low; where it is narrow, the density is high. The blue histogram of simulated values of matches the orange formula for . For , the values pile up near 0.
Lesson 3 · Common distributions
Choose a family and move its parameters, then press "Sample 1000". The orange bars or curve are the formula (PMF or PDF). The dark vertical line marks the mean, and the bar at the top spans mean ± one standard deviation. The blue histogram shows 1000 samples; compare the sample mean and variance with the formulas in the side panel. Try the gamma with (it is the exponential), and the beta with (it is the uniform distribution).
Increase the number of trials , with the mean fixed. The blue bars are ; the orange bars are . With the binomial is visibly narrower. As grows, the bars agree. The side panel shows the total variation distance (the largest possible difference between the probabilities of any event) and Le Cam's bound : both shrink like .
Press "New run", then make the run longer. Blue ticks on the timeline are events at rate . The left histogram collects the gaps between events, the right one the counts in windows of length 1. The orange curves are the formulas and . Then lower the keep probability : each event is kept (aqua) or removed (magenta) by an independent coin. The kept events again form a Poisson process, with rate (thinning).
Drag "already waited ", then change the lifetime family. The orange curve is the survival curve of a new item, with mean lifetime 10 years. The yellow part is the curve beyond . Rescaled by and moved back to time 0, it becomes the aqua curve: the survival curve of an item that has already lasted . For the exponential, aqua and orange are the same curve. For a gamma with (wear-out), an item that lasted 10 years survives 10 more with probability 0.146 instead of 0.423 for a new one. Press "Simulate" to count 10,000 simulated lifetimes (blue).
Move the three sliders, or try the presets. Each point is one probability vector , drawn by normalising three independent gammas; each corner is one class with probability 1. Blue points are samples, and the orange dot is the mean . With all the points fill the triangle evenly. With all they crowd into the corners and edges (sparse vectors: most mass on one or two classes). With all they gather near the centre. The side panel compares the variance and covariance with the formulas.
Lesson 4 · Joint distributions and covariance
Click a column to see its conditional distribution. The cells are the joint PMF (blue, darker = more mass); the bars on the right and at the bottom are the marginals. The side panel compares the conditional with the marginal . Click a cell and move the slider to change its mass (the other cells rescale so the total stays 1). Press Make independent: the table becomes , every column gets the same shape and the rank drops to 1.
Move the sliders and watch the bar. Three classes with their own scores (blue dots) and their own means (orange marks). The bar splits into the within-class part and the between-class part . Set the gap between the means to 0: the between part disappears. New sample draws new students; the sample variance (black tick) stays close to the exact total.
Move the slider and watch the colours. Each point is coloured by the sign of : aqua = positive, magenta = negative. The readouts show the sample covariance and correlation. Then drag the yellow point far away: one outlier can change the correlation a lot, because its product is large.
Switch the examples. Each cloud has correlation , but the orange curve (the mean of in narrow bins of ) or the orange band (± one standard deviation in each bin) changes with , so depends on . The second readout, the correlation of and , is far from 0 for every dependent example. Only "independent" has both readouts near 0.
Drag the yellow handle to turn the direction , and watch the variance of the projections . The samples are blue; the orange ellipses are 1 and 2 standard deviations of , and the orange arrows are the eigenvectors scaled by . The projected variance is largest () when points along the long axis, and smallest () along the short axis. Set and to get the two-thermometer matrix up to scale.
Lesson 5 · The multivariate Gaussian
Drag the yellow square (left) and watch its image (right). The blue points are samples in the square; they keep their colour and their number after the map, so no mass is created or lost. The readout compares the area ratio of the image with at the centre. Switch to polar or tanh and make the square smaller with the slider: for a curved map the two numbers agree only for small squares.
Press Play: z → x to watch the round cloud of become the ellipse of . Then change . The blue points are samples; the orange ellipses are Mahalanobis distance 1 and 2; the violet arrows are the columns of . Drag the yellow point: its Euclidean distance and its Mahalanobis distance can be very different. In 2-D, about 39% of the samples fall inside distance 1 and about 86% inside distance 2.
Drag the yellow handle up and down to move the line . The aqua curve is the slice (the conditional of given ); its centre moves on the dashed orange line, but its width does not change. The violet curve at the bottom is the shadow (the marginal of ). Move towards : the slice gets narrower, the shadow does not.
Press Draw 1000 more a few times and compare the two cases. In "", both histograms of and (blue) match the orange curve, and the correlation is about 0. But the scatter is an X shape, and the histogram of has a spike at 0 that holds half of the samples, and the correlation of and is exactly 1. In "independent ", follows the curve. In both cases : the variance cannot see the difference.
Drag the yellow handle at the left edge up and down to set the observation of , and move the noise slider . The sensor reads with noise . The violet ellipses are the prior of ; the blue band is the observation ; the aqua ellipses are the posterior (the conditional given the observation). The curves at the bottom are the distribution of before (violet) and after (aqua). is never observed, but its uncertainty shrinks because it is correlated with . Drag the handle: only the centre moves, the size stays. Set the noise to 0: the posterior collapses onto the line , and the readouts become the 2-D formulas of section 2.
Lesson 6 · LLN, CLT and confidence intervals
Press "Draw 1,000" several times, then change and draw again. The top chart shows the population density (orange) and the latest sample (blue dots). The bottom chart is the histogram of all sample means (blue) with the normal curve (orange). Notice: the observed SD of the means matches , and for the histogram is close to a bell even for the skewed population.
Press Play and watch the paths. Each blue line is the running mean of one sequence of flips; path 1 is highlighted. The orange band is . Switch to 20 paths: at every , about 95% of the paths are inside the band. Switch to the die: the band is wider (the die has , the coin ), but it shrinks at the same rate.
Press "Drop 100", then "Drop 1,000 at once". The blue bars count the balls in each bin, the orange ticks are the expected counts from the binomial distribution, and the dashed orange curve is the normal curve with mean and SD . Change the number of rows: the bell gets wider like .
Choose a base distribution and increase . The blue histogram shows 20,000 simulated values of ; the orange curve is . The KS distance (the largest gap between the two CDFs) shrinks as grows. Notice: the uniform and the die look Gaussian already at , the exponential needs about , and Bernoulli(0.1) is still lumpy at . Then choose Cauchy: the mean of Cauchy values never gets narrower.
Press "Draw 100 intervals" a few times. Each bar is one 95% interval from a new data set; it is blue if it contains the true mean (orange line) and magenta if it misses. Then press "Draw 10,000" and read the coverage. With and the estimated SD at , the coverage is about 0.92, not 0.95. Switch to : it goes back to 0.95. Then switch to skewed data: even gives only about 0.90 at .
Lesson 7 · Concentration inequalities
Move and and compare the curves on the log scale. Blue is the exact binomial tail, dashed orange the CLT approximation. The bounds: Markov (grey), Chebyshev (violet), Hoeffding (aqua) and Chernoff (magenta). Notice: at Chebyshev still gives 0.05 while the truth is about ; the exponential bounds stay parallel to the truth. Then set : Chernoff becomes much better than Hoeffding, because it uses the small variance of a rare event.
Move to the lowest point of the orange curve. The curve is the bound for each ; every point on it is a valid bound. The yellow dot is your , the aqua dot the best one, , and the blue line the exact tail. For the Gaussian, and the bound is . Try "Exp(1)" with : the best Chernoff bound (0.74) is worse than Markov (0.5). Chernoff is strong for large deviations and for sums, not everywhere.
Choose and , then press Simulate. The widget runs 1,000 experiments of size and plots their errors (blue); errors beyond the orange lines are magenta. With the Hoeffding , the failure rate is always below , usually far below (it is a worst case over all distributions on ). Switch "Use n from" to CLT: for the fair coin the failure rate moves up to about .
Press "Run 50 experiments" and change . classifiers guess at random, so each has true accuracy 0.5. The blue curve is the best test accuracy among the first ; it grows with . The dashed orange curve is the bound with ; the blue curves almost never cross it. The aqua dot is the selected classifier on a fresh test set: back near 0.5. The high test score was selection, not skill.
Lesson 8 · Maximum likelihood
Flip the coin and watch the curve. Press Flip 10 a few times. The blue flips are the data. The top panel is the orange likelihood , divided by its maximum so that the peak is at 1; the bottom panel is the log-likelihood . The yellow line marks the MLE , the dashed grey line the true of the coin. Notice that the peak gets narrower as grows: more data pin down. The readout gives the curvature ; lesson 09 turns it into an error bar.
Move and to make the total cost small. The blue points are the data; the orange curve is the Gaussian model, and each stem shows the density of a point. The magenta bars below are the costs ; the readout adds them up to the negative log-likelihood. Try a tiny : the points near become cheap, the far ones very expensive. Press Jump to MLE and compare with your best guess.
Throw darts: draw samples and compare three estimators. Each press of Draw 500 simulates 500 samples of size from , so the true variance is (dashed orange line). Each blue dot is one estimate; the black tick is the average of the dots in its row. The table compares the simulated bias, variance and MSE with the exact formulas. Notice that the unbiased row is centred on 1 but has the widest spread. Then move : all three rows shrink toward 1 (consistency), and their differences vanish.
Fit a gamma by matching two averages. The blue histogram is a data set of 200 positive numbers; the orange curve is the gamma density with your shape and rate . The two readout rows compare the model's and with the data's averages of and . Move the sliders until both rows match, then press Jump to MLE: the MLE is the one point where both match, and there the average log-likelihood is largest.
Lesson 9 · Fisher information
Change and watch the peaks. Each orange curve is the log-likelihood of one simulated data set (8 data sets from the same true , dashed grey). Each blue dot is that data set's MLE. As grows the curves get sharper, and the dots crowd closer to the truth. The readout compares the spread of the MLEs with . Switch to the coin: there the curvature also depends on .
Evaluate the score at a guess . The blue histogram shows the score of the whole sample, , over 2000 simulated samples. The orange curve is , the theory at the truth. With equal to the true value, the histogram is centred at 0 and its variance matches . Move away from the truth: the histogram shifts. The sign of the score says in which direction the truth lies.
Move and compare the two curves. The orange curve (top) is the information of one flip. The bottom panel shows (orange) and the variance of in 2000 simulated experiments (blue dot, press Simulate). Where one curve is low, the other is high: they are reciprocals, up to the factor . The readout also shows the relative error , which grows near .
Simulate many data sets and look at the error of the MLE. The blue histogram shows over 4000 simulated data sets; the orange curve is the limit . For the exponential rate at small the histogram is skewed (the MLE is biased); increase and it becomes Gaussian. For Uniform() the regularity condition (R1) fails: the histogram sits on one side of 0 and collapses as grows, because the error shrinks like , not .
Check the promise "95%". The orange curve is the exact coverage of the Wald interval for every true (computed by summing the binomial probabilities); the aqua curve is the Wilson interval. The bottom panel draws 30 simulated intervals at your : magenta ones miss the truth. Move close to 0: the Wald coverage collapses, because with the interval is . Increase and the problem moves closer to the edge.
Lesson 10 · Bayesian inference
Flip the coin (or click Heads and Tails) and watch the posterior. The violet curve is the prior Beta(), the orange curve the likelihood (rescaled to area 1), and the aqua curve the posterior, with its 95% credible interval shaded. The markers show the MLE, the MAP and the posterior mean. The posterior always lies between the prior and the likelihood. Make the prior strong ( large) and see how many flips it takes to move it. Set (uniform prior): then the MAP equals the MLE.
Move the sliders and compare the three curves. Violet: the prior . Orange: the likelihood of , which has the shape . Aqua: the posterior. The bar below shows the precisions: prior plus data equals posterior. Increase : the data precision grows and the posterior moves to . Make the prior wide: it stops mattering.
Compare three estimators of a coin's at every true . The curves are exact MSEs (sums over all outcomes ): the orange MLE , the aqua MAP and the dashed aqua posterior mean . The violet line marks the prior mean. Where the shading is aqua, the MAP beats the MLE. Press Simulate to check the three MSEs at the yellow with 4000 experiments (blue dots). A strong prior wins big near its mean and loses far from it; a larger makes all curves agree.
Predict the number of successes in the next trials. You saw successes in trials; the prior is Beta(1, 1). The aqua bars are the posterior predictive (beta-binomial), the orange bars the plug-in Binomial(). With little data the predictive is much wider. Increase (with the same rate ) and the two distributions become the same; increase and the gap grows.
Run a Bayesian A/B test. Set the visitors and conversions of each variant. The top panel shows the posteriors of (blue) and (aqua) with a uniform prior; the bottom panel the histogram of from 4000 posterior draws, aqua where B wins and magenta where A wins. The readout gives by sampling (with its Monte Carlo error) and by numerical integration, and the expected loss of each choice. Multiply both sample sizes by 10 with the same rates and see the decision become clear.
Lesson 11 · Hypothesis testing
Press "Repeat 1,000 times" to flip a fair coin 100 times, again and again. This is the world where is true. The violet bars show how often each number of heads appears; the orange marks are the exact binomial probabilities. The magenta bars are the runs at least as far from 50 as the observed count (yellow line). Their share is the p-value: it approaches the exact 0.0352. Move the observed count to 55 or 70 and predict the p-value first. The second view, Many p-values, runs many tests and shows the histogram of their p-values.
Move the sliders for the effect and the sample size . The violet curve is the null distribution of , the orange curve the distribution when the effect is real. The magenta area is , the aqua area is the power, and the light orange area is . The lower chart shows the power as a function of . The start values are the coin: , . Notice that only moves the orange curve: to double you need four times as much data.
Slide the degrees of freedom and compare the t density (orange) with the normal density (violet, dashed). The solid orange lines are , the dashed violet lines . Press Simulate to draw 2,000 samples of size from a normal distribution and compute for each: the blue histogram follows , not . With , about 8.2% of the values fall beyond (magenta tails), not 5%. This is why small samples need quantiles.
Switch between the three rules and watch which p-values are rejected. Each dot is one test, sorted by its p-value (log scale). Aqua dots are real effects, violet dots are true nulls, and magenta dots are false discoveries. The orange line is the threshold of the rule: , , or the BH line ; everything left of the grey line is rejected. Press Run 500 studies: without a correction the FWER is close to 1; Bonferroni keeps it below 0.05 but finds few real effects; BH keeps the average FDP near and finds many more.
Lesson 12 · Bootstrap and A/B tests
Press "Shuffle labels once" a few times: the blue dots move to a random new split, and the orange marks show the two group means. Each shuffle adds one value to the violet histogram of the shuffled statistic . Then press All splits: the histogram shows all 20 splits, and the magenta bars beyond the observed (yellow) give the exact p-value. Switch to 20 users (time to finish an old and a new sign-up form): there are 184,756 splits, so the widget samples 1,000 of them and uses .
Press "One resample" and count: the blue dots are the 20 data points; the small dots above each point show how often it was drawn (aqua = once, yellow = twice or more), and faded points were not drawn. Then press 1,000 resamples: the aqua histogram is the bootstrap distribution, and the orange lines are the 95% percentile interval. The dashed line is the true , which we know here because we generated the data. Check coverage repeats everything on 200 new data sets. Now switch to the maximum: the interval turns magenta, because it can never contain .
Move the MDE slider and watch the users per arm. The orange curve is the power as a function of (log scale); the yellow lines mark the planned and the target power. Halve the MDE: grows about 4 times, because . Raise the baseline rate toward 50%: the variance grows, so grows too. Simulate runs 1,000 whole A/B tests at the planned ; the magenta dot is the share that reject, close to the target power.
Press "Run one A/A test" a few times. is true; the blue path is the z-statistic as the data arrive, and the yellow dots are the looks. A test that crosses the dashed ±1.96 lines at a look stops with a false positive. Then press Run 1,000 A/A tests: the lower chart shows the false-positive rate for 1 to 100 looks. With one look it is 0.05, the planned level; with 20 looks it is about 0.25.
Press "Run 500 experiments" and compare the two histograms. The scatter shows one experiment: control users (blue) and treatment users (aqua), with the common slope . The violet histogram is the plain difference in means, the aqua histogram the CUPED estimate: same centre , but narrower by about . Move to 0 and to 0.9. Then switch the covariate to in-experiment Z, a value that the treatment changes: the magenta histogram is centred at a negative effect.
Lesson 13 · Regression: the statistics view
Press "New data set" a few times, then "Add 100 data sets". The orange line is the true line. Each data set gives a fitted line: the newest is yellow, earlier ones are faint blue. The histograms collect and over all data sets; the orange curves are the theory from section 3. Make larger or smaller and watch the fan and the histograms get narrower.
Drag the yellow point along the line, then move the slider to the right. The orange band is the 95% confidence band for the mean; the violet band is the 95% prediction band for a new . Both are narrowest at . With large the orange band shrinks to the line, but the violet band stays about wide. A wider spread of makes the slope more precise (smaller SE, larger ).
Move the correlation slider from 0 to 0.99. Each blue dot is from one data set with the same features and new noise; the orange ellipse is the 95% region of around the true . With correlated features the ellipse grows along the direction and tilts: the estimates are negatively correlated. The sum (the short axis) stays precise.
Try the four presets. Blue points are data, the orange line is the least-squares fit, and magenta points have high leverage (). The right plot shows residuals against fitted values. Compare the classical and the robust standard error of the slope in each case: they agree for the good model and differ when the noise grows with .
Click in the plot to add data points; then move the prior precision . Blue points are data. In aqua: the posterior mean line (thick), 12 lines sampled from the posterior (thin), and the 95% predictive band. The dashed grey line is least squares. "Clear points" shows the prior. A large pulls the line toward 0 (strong ridge); a small makes the mean line match least squares. Far from the data the band widens.
Lesson 14 · Monte Carlo and importance sampling
Press "+1,000" a few times, then "Play". Darts inside the disk are aqua, outside magenta. The blue path is the running estimate ; the orange lines are and the band . Switch the view to "error": on log–log axes the error follows a line of slope . Try "New seed": every path stays mostly inside the band.
Try the four presets, and press "New seed" several times for each. The target is orange and the proposal is violet. The lower plot shows the normalised weight of each of the 200 draws as a blue stick; the largest is yellow, and the dashed line is the equal weight . The effective sample size (ESS) says how many equally weighted draws the weighted sample is worth. With the "too narrow" proposal, most runs look calm, and then one draw takes most of the weight.
Press "+500", then move below 1.65. The target () is orange, the envelope is violet. Proposals under are accepted (aqua), the others rejected (magenta); "Step" shows one proposal in yellow. The histogram compares the accepted samples with the target density. Below a magenta region appears where the envelope is too low, and the histogram misses mass near .
Press "Run again" several times, then move the threshold . The chart shows running estimates divided by the true value, so the target is the orange line at 1. Plain Monte Carlo (blue) is 0 until its first hit, then jumps. Importance sampling with (aqua) settles near 1 after a few hundred draws. Dashed lines are relative standard errors from the theory. At the variance ratio is about 7,000.
Move the slider to the bottom of the parabola, then switch "Antithetic pairs" on. The problem is with the control . Top: draws in blue, the line with slope in yellow, the least-squares slope dashed in orange. Bottom: the variance factor of the control-variate estimator as a function of ; its minimum is at . The aqua line is the antithetic factor . Then try : the control is useless and the antithetic pairs double the variance. "Check by simulation" measures both factors.
Lesson 15 · Markov chains and MCMC
Press Step and watch the blue bars move toward the orange marks . The arrows are the transition probabilities, and the size of each circle is . The lower chart shows the distance to on a log scale; it falls like (dashed orange line). Edit the matrix or try the presets. Flip never converges (period 2), and Cycle has a stationary distribution but fails the detailed-balance check: its mass circulates in one direction.
Press Step a few times, then Run 1000. Each proposal is aqua if it is accepted and magenta if it is rejected. The blue histogram of the chain approaches the orange target. Move the step size : a tiny step is accepted almost always but crawls (see the trace); a huge step is almost always rejected and the trace has long flat parts. With the bimodal target and a small step, the chain stays in one mode for a long time.
Press Run 200 sweeps and watch the blue staircase inside the orange ellipses of the target. Then move toward 0.99: the steps get short, and the lag-1 autocorrelation of approaches . Turn on independent draws (violet) to see how far apart independent samples are. The readout converts the autocorrelation into sweeps per effectively independent sample.
Press Step to draw a momentum and follow the violet leapfrog path. The end point is aqua if it is accepted and magenta if it is rejected. The readout shows the energy error . Increase the step size past about 0.45 on the correlated Gaussian: the path explodes (a divergence) and every proposal is rejected. Run 100 also runs random-walk Metropolis with the same number of gradient-or-density evaluations; compare the two effective sample sizes.
Choose a preset. Four random-walk Metropolis chains (four colours) start far apart. The first half of each chain is warm-up (shaded) and is dropped. Well mixed: the traces overlap like noise, , and the autocorrelations die fast. Too small step: the traces still remember their starts, and the autocorrelation decays slowly. Stuck in one mode: each chain looks fine alone, but the chains disagree, so is large. All in the same mode: the diagnostics pass, but half of the target is missing. Then make the chains longer: which problems go away?