About this simulation

This simulator generates random samples with a seeded PRNG (splitmix32 + Box-Muller), then computes a real t-statistic for three designs — one-sample, two-sample (pooled or Welch), and paired. It draws the t-distribution's PDF via a log-gamma/incomplete-beta approximation, shades the rejection regions at your chosen α, and reports p-value, 95% confidence interval, Cohen's d effect size, and statistical power live as you move any slider.

🔬 What it shows

The top canvas plots your simulated data points (with jitter) against the null hypothesis or the other group's mean; the bottom canvas draws the t(df) sampling distribution with the two-tailed critical regions and your observed t-statistic marked on it.

🎮 How to use

Pick a tab — One-Sample, Two-Sample, or Paired — then drag sample size n, means μ, standard deviation σ, or mean difference δ, and choose a significance level α. Try the preset buttons (Drug trial, Learning, Null true, Small n) to jump to instructive scenarios, or toggle Equal variances to switch between the pooled Student's t and Welch's t formulas.

💡 Did you know?

The Welch two-sample formula computes degrees of freedom with the Welch-Satterthwaite equation, which is why df can come out as a non-integer estimate rather than the tidy n₁+n₂−2 of the pooled version — it's the standard fix when the two groups don't share the same variance.

Frequently asked questions

What's the difference between the one-sample, two-sample, and paired t-tests here?

The one-sample test compares a single simulated sample's mean against a fixed null value μ₀ using t = (x̄ − μ₀)/(s/√n). The two-sample test compares two independently generated groups A and B, using either the pooled formula (equal variances assumed) or Welch's formula (unequal variances). The paired test generates matched before/after values and tests whether their mean difference d̄ differs from zero.

How is the p-value actually calculated?

The simulator computes the two-tailed p-value from the t-distribution CDF, which is evaluated via a regularized incomplete beta function using a continued-fraction (Lentz) approximation and a Stirling log-gamma routine — the same numerical machinery statistics libraries use, implemented directly in the page's JavaScript.

What does Cohen's d tell you that the p-value doesn't?

The p-value only tells you whether a difference is statistically detectable given your sample size; Cohen's d measures how large that difference is in standardized units (mean difference divided by pooled or sample standard deviation). The simulator labels d as negligible, small, medium, or large so you can see effect size and significance can disagree, especially at very large or very small n.

Why does toggling "Equal variances" change the result?

With Equal variances checked, the two-sample test pools both groups' variances into one estimate and uses df = n₁+n₂−2 (Student's t). Unchecked, it switches to Welch's t, which weights each group's variance separately and computes df via the Welch-Satterthwaite approximation — more robust when group sizes or spreads differ.

Why do the sample points change slightly every time I drag a slider?

Each control redraws the plot by regenerating a fresh random sample from a seeded PRNG (splitmix32) combined with a Box-Muller normal transform. The seed is reset before each update so results stay reproducible for a given preset, while still feeling like fresh random data compared to the underlying true population parameters you set.