The one-sample t test of H0: μ = μ0 is derived for normal data: then t = √n(ybar − μ0)/s follows Student's curve with n − 1 degrees of freedom and the 5% test rejects in exactly 5% of samples. Here the data come from the population you choose (top panel, in standard units). Many samples of size n are drawn with the null hypothesis true and each gives a t ratio (middle panel, against the t curve); the pink tails are the nominal rejection region, and the table gives the true proportion of samples that land in each tail. In the bottom panel the same samples are shifted by d standard deviations, so the rejection rate is the power and one minus it the Type II error. Skewed populations and small samples are where the test slips.
Every sample is drawn with a seeded generator, so a preset always shows the same values; 20 000 samples give each rate to about ±0.003. The right-hand panels clip t ratios beyond ±6 (the count is shown); they are included in the tail rates. For normal data the power in the last row of the table is exact (noncentral t); for other populations it is the simulated rate and the exact normal-data value is shown for comparison. Samples with s = 0 (possible for Poisson data with small n) are skipped.
code/ch07_normal_inference.py (t_ratios, true_size, t_power, type2_probability).