Mathematical Foundations

V.3 · Statistics

Does a larger sample repair selection?

Draw repeatable samples from a known finite population and compare uniform selection with a rule that excludes its lower half.

Sample from a fixed finite population

Actual repeated estimates
Actual repeated estimatesPopulation: 0, 1, 2, 3, 6, 7, 8, 9. Sample one: 2, 0, 6, 1. Every displayed estimate uses its actual sample. Fixed population mean = 4.5. Uniform sampling with replacement: samples vary without selection bias. Theoretical estimator bias = 0; finite-run bias = 0.42.25: approximately 21.5: approximately 17: approximately 25.25: approximately 13.75: approximately 26.5: approximately 36.75: approximately 13.25: approximately 24.5: approximately 13.5: approximately 36: approximately 15: approximately 13: approximately 18: approximately 12.75: approximately 20.54.759

Estimate values · frequency counts · dashed marker is the fixed population mean

Fixed population: 0, 1, 2, 3, 6, 7, 8, 9. Sampling is with replacement.

Actual samples and estimates from this seed
RunObservationsMeanEstimate
12, 0, 6, 12.252.25
23, 0, 3, 01.51.5
38, 9, 8, 377
47, 8, 6, 05.255.25
51, 9, 9, 977
66, 1, 6, 23.753.75
79, 8, 1, 86.56.5
83, 0, 0, 62.252.25
98, 8, 7, 36.56.5
106, 7, 7, 76.756.75
119, 3, 0, 13.253.25
123, 1, 8, 64.54.5
138, 3, 1, 23.53.5
140, 2, 2, 93.253.25
159, 1, 8, 666
162, 2, 1, 93.53.5
170, 9, 8, 355
187, 2, 0, 63.753.75
190, 1, 6, 73.53.5
203, 1, 1, 733
219, 8, 7, 888
223, 1, 1, 62.752.75
237, 9, 3, 76.56.5
243, 0, 0, 82.752.75

Population: 0, 1, 2, 3, 6, 7, 8, 9. Sample one: 2, 0, 6, 1. Every displayed estimate uses its actual sample. Fixed population mean = 4.5. Uniform sampling with replacement: samples vary without selection bias. Theoretical estimator bias = 0; finite-run bias = 0.

Fixed population mean
4.5
Theoretical estimator bias
0
Theoretical sampling variance
2.5625
Finite-run mean of estimates
4.5
Finite-run signed bias
0
Finite-run variance (divide by R)
637/1923.317708…
Finite-run MSE
637/1923.317708…

= exact finite-data/model quantity · ≈ binary64 approximation; empirical results describe this run

from 0 to 4294967295, whole numbers only

from 1 to 32, whole numbers only

from 1 to 64, whole numbers only

Fixed population mean = 4.5. Uniform sampling with replacement: samples vary without selection bias. Theoretical estimator bias = 0; finite-run bias = 0.

μ=4.5,E[T]=4.5,Var⁡(T)=2.5625\mu=4.5,\quad E[T]=4.5,\quad\operatorname{Var}(T)=2.5625
MSE⁡^=Var⁡^+b^,2=637192\widehat{\operatorname{MSE}}=\widehat{\operatorname{Var}}+\widehat{b}^{,2}=\frac{637}{192}

Fix the target and selection rule

Fixed population mean = 4.5. Uniform sampling with replacement: samples vary without selection bias. Theoretical estimator bias = 0; finite-run bias = 0.

μ=4.5,E[T]=4.5,Var⁡(T)=2.5625\mu=4.5,\quad E[T]=4.5,\quad\operatorname{Var}(T)=2.5625

Draw repeatable samples from a known finite population and compare uniform selection with a rule that excludes its lower half.

Intuition

A statistic changes when a new sample arrives even though the population stays fixed. Random variation concerns which eligible members happen to be selected. Selection bias changes eligibility itself. Repeating a biased procedure can make its wrong center increasingly stable.

Definition

The population is the fixed multiset [0,1,2,3,6,7,8,9][0,1,2,3,6,7,8,9], with mean μ=9/2\mu=9/2 and variance 41/441/4. Uniform sampling here means iid draws with replacement, each member having probability 1/81/8. The biased rule draws uniformly only from [6,7,8,9][6,7,8,9], whose mean is 15/215/2.

Mechanics

Choose the selection rule, sample size, repetition count and uint32 seed. Every table row shows the actual drawn observations and their computed mean. The frequency plot counts those actual estimates, while its target marker is derived independently from all eight population values. Replay regenerates exactly the same run.

Derivation

Under uniform iid selection, E[Xˉ]=μE[\bar X]=\mu and Var⁡(Xˉ)=σ2/n=41/(4n)\operatorname{Var}(\bar X)=\sigma^2/n=41/(4n). Under the biased rule, E[Xˉ]=15/2E[\bar X]=15/2, so bias relative to the population mean is 3 at every sample size. Its selected-source variance is 5/45/4, giving mean variance 5/(4n)5/(4n).

Worked examples

Seed 42 with four uniform draws produces [2,0,6,1][2,0,6,1], whose mean is 9/49/4. This estimate differs from the true finite-population mean 9/29/2 without implying selection bias. A sample consisting only of upper-half values instead comes from a procedure with theoretical center 15/215/2.

Worked example: Sample from a fixed finite population

Actual repeated estimates
Actual repeated estimatesPopulation: 0, 1, 2, 3, 6, 7, 8, 9. Sample one: 2, 0, 6, 1. Every displayed estimate uses its actual sample. Fixed population mean = 4.5. Uniform sampling with replacement: samples vary without selection bias. Theoretical estimator bias = 0; finite-run bias = 0.42.25: approximately 21.5: approximately 17: approximately 25.25: approximately 13.75: approximately 26.5: approximately 36.75: approximately 13.25: approximately 24.5: approximately 13.5: approximately 36: approximately 15: approximately 13: approximately 18: approximately 12.75: approximately 20.54.759

Estimate values · frequency counts · dashed marker is the fixed population mean

Fixed population: 0, 1, 2, 3, 6, 7, 8, 9. Sampling is with replacement.

Actual samples and estimates from this seed
RunObservationsMeanEstimate
12, 0, 6, 12.252.25
23, 0, 3, 01.51.5
38, 9, 8, 377
47, 8, 6, 05.255.25
51, 9, 9, 977
66, 1, 6, 23.753.75
79, 8, 1, 86.56.5
83, 0, 0, 62.252.25
98, 8, 7, 36.56.5
106, 7, 7, 76.756.75
119, 3, 0, 13.253.25
123, 1, 8, 64.54.5
138, 3, 1, 23.53.5
140, 2, 2, 93.253.25
159, 1, 8, 666
162, 2, 1, 93.53.5
170, 9, 8, 355
187, 2, 0, 63.753.75
190, 1, 6, 73.53.5
203, 1, 1, 733
219, 8, 7, 888
223, 1, 1, 62.752.75
237, 9, 3, 76.56.5
243, 0, 0, 82.752.75

Population: 0, 1, 2, 3, 6, 7, 8, 9. Sample one: 2, 0, 6, 1. Every displayed estimate uses its actual sample. Fixed population mean = 4.5. Uniform sampling with replacement: samples vary without selection bias. Theoretical estimator bias = 0; finite-run bias = 0.

Fixed population mean
4.5
Theoretical estimator bias
0
Theoretical sampling variance
2.5625
Finite-run mean of estimates
4.5
Finite-run signed bias
0
Finite-run variance (divide by R)
637/1923.317708…
Finite-run MSE
637/1923.317708…

= exact finite-data/model quantity · ≈ binary64 approximation; empirical results describe this run

from 0 to 4294967295, whole numbers only

from 1 to 32, whole numbers only

from 1 to 64, whole numbers only

Fixed population mean = 4.5. Uniform sampling with replacement: samples vary without selection bias. Theoretical estimator bias = 0; finite-run bias = 0.

μ=4.5,E[T]=4.5,Var⁡(T)=2.5625\mu=4.5,\quad E[T]=4.5,\quad\operatorname{Var}(T)=2.5625
MSE⁡^=Var⁡^+b^,2=637192\widehat{\operatorname{MSE}}=\widehat{\operatorname{Var}}+\widehat{b}^{,2}=\frac{637}{192}

Fix the target and selection rule

Fixed population mean = 4.5. Uniform sampling with replacement: samples vary without selection bias. Theoretical estimator bias = 0; finite-run bias = 0.

μ=4.5,E[T]=4.5,Var⁡(T)=2.5625\mu=4.5,\quad E[T]=4.5,\quad\operatorname{Var}(T)=2.5625

Replay the worked mathematical steps using the same canonical state and actual derived quantities.

Executable reference code

Run both files. The pedagogical program exposes the arithmetic; the NumPy companion uses array operations. Literal assertions check the worked example rather than testing a simulation against a desired statistical outcome.

code/python/statistics_sampling.py
"""Runnable sampling reference; exact mechanics / NumPy companion."""
from fractions import Fraction as F
state=42
population=[0,1,2,3,6,7,8,9]
sample=[]
for _ in range(4):
    state=(1664525*state+1013904223)%2**32
    sample.append(population[state*len(population)//2**32])
assert sample==[2,0,6,1]
assert F(sum(sample),len(sample))==F(9,4)
print(sample,F(sum(sample),len(sample)))
code/python/statistics_sampling_numpy.py
"""Runnable sampling reference; exact mechanics / NumPy companion."""
import numpy as np
state=42
population=np.array([0,1,2,3,6,7,8,9])
indices=[]
for _ in range(4):
    state=(1664525*state+1013904223)%2**32
    indices.append(state*len(population)//2**32)
sample=population[indices]
assert sample.tolist()==[2,0,6,1] and sample.mean()==2.25
print(sample,sample.mean())

Explore

Replay a seed, change it and compare the actual rows. Hold a seed while increasing repetitions: earlier rows remain a shared prefix. Increase sample size under each selection rule and explain the difference between tighter concentration and a better target.

Common mistakes and counterexamples

An unlucky representative procedure can produce an unrepresentative realized sample. A very large biased sample can still miss a whole subgroup. Sample size alone does not repair exclusion, missingness or dependence. Sampling without replacement has a finite-population correction; this iid explorer does not silently apply that different model.

Numerical considerations

The bounded LCG uses exact uint32 transitions; integer indexing selects population members without floating accumulation. Sizes are 1–32 and repetitions 1–64. Sample means and empirical summaries are exact fractions. Seeded pseudo-randomness supports reproducibility; it is not evidence that a real collection procedure meets iid assumptions.

Engineering and ML connections

A monitoring dashboard that records only successful requests misses failures; collecting more successes cannot repair that exclusion. A training dataset assembled from one customer segment can concentrate around a segment-specific distribution. Evaluate the sampling frame as carefully as the number of rows.

Exercises

Predict, calculate and explain before checking the corrective feedback. Each solution states the relevant rule and its conditions.

calculation

Known target

For the fixed population [0,1,2,3,6,7,8,9], give its mean and population variance.

calculation

Actual estimate

Observed sample [2,0,6,1] is drawn with replacement. Give its mean.

calculation

Sampling variance

For uniform iid draws from that population, give Var(sample mean) at n=4.

explanation

Selection bias

Only [6,7,8,9] can be selected. What does increasing n do?

Choose one answer

explanation

Replay

What does an explicit seed promise in this bounded experiment?

Choose one answer

Summary and checkpoints

Separate the known target, actual sample and sampling rule. Explain random variation, calculate an actual mean, and identify why the upper-half rule remains biased as sample size grows.

The map of the book

97 of 97 chapters written · eight Parts

demo Foundation demo Try the live vector example Open as a page

Part I

Mathematical Language

The notation and mental objects everything else uses.

9 of 9 chapters written

  1. I.1 Scalars, quantities, units, powers and roots available
  2. I.2 Coordinates and points available
  3. I.3 Vectors: components, magnitude, and direction reference chapter available
  4. I.4 Algebraic expressions, equations and inequalities available
  5. I.5 Functions as input → transformation → output available
  6. I.6 Essential function families available
  7. I.7 Sets, intervals, and relations available
  8. I.8 Indexed quantities and summation available
  9. I.9 The notation map for ML available

Part II

Linear Algebra

Matrices as transformations: the strongest foundation in the book.

19 of 19 chapters written

  1. II.1 Vector addition and subtraction available
  2. II.2 Scalar multiplication and vector scaling available
  3. II.3 Norms, magnitude, and normalization available
  4. II.4 Dot product, angle, and orthogonality available
  5. II.5 Projection and distance to a direction available
  6. II.6 Linear combinations and span available
  7. II.7 Linear independence, basis, and coordinates available
  8. II.8 Matrices as linear transformations available
  9. II.9 Matrix × vector available
  10. II.10 Matrix × matrix as composition available
  11. II.11 Transpose and orthogonality available
  12. II.12 Determinant: orientation and area/volume scaling available
  13. II.13 Linear systems as intersecting constraints available
  14. II.14 Gaussian elimination and row operations available
  15. II.15 Rank and invertibility available
  16. II.16 Inverse matrices available
  17. II.17 Eigenvalues and eigenvectors available
  18. II.18 Orthogonal bases and least-squares geometry available
  19. II.19 Singular Value Decomposition available

Part III

Calculus

Change, local approximation, and sensitivity made visible.

15 of 15 chapters written

  1. III.1 Limits through approach available
  2. III.2 Continuity and local behavior available
  3. III.3 Derivative as secant → tangent available
  4. III.4 Derivative as rate of change and local linear model available
  5. III.5 Derivative rules available
  6. III.6 Chain rule available
  7. III.7 Multivariable functions and partial derivatives available
  8. III.8 Gradient and directional derivatives available
  9. III.9 Jacobian available
  10. III.10 Computational graphs and automatic differentiation available
  11. III.11 Hessian and curvature available
  12. III.12 Integrals as accumulation available
  13. III.13 Fundamental derivative/integral connection available
  14. III.14 Numerical differentiation available
  15. III.15 Numerical integration available

Part IV

Probability

Uncertainty through sample spaces, evidence, and repetition.

16 of 16 chapters written

  1. IV.1 Random experiments, outcomes, and sample spaces available
  2. IV.2 Events and probability mass available
  3. IV.3 Counting and finite probability where needed available
  4. IV.4 Conditional probability as restricted sample space available
  5. IV.5 Independence available
  6. IV.6 Bayes' theorem as probability-mass update available
  7. IV.7 Random variables available
  8. IV.8 PMF, PDF, and CDF available
  9. IV.9 Bernoulli and Binomial distributions available
  10. IV.10 Uniform and Gaussian distributions available
  11. IV.11 Expectation available
  12. IV.12 Variance and standard deviation available
  13. IV.13 Joint, marginal, and conditional distributions available
  14. IV.14 Covariance and correlation available
  15. IV.15 Law of Large Numbers available
  16. IV.16 Central Limit Theorem available

Part V

Statistics

From observed data to estimates, intervals, and likelihood.

10 of 10 chapters written

  1. V.1 Data summaries: mean, median, mode available
  2. V.2 Spread: variance, standard deviation, robust interpretation available
  3. V.3 Population, sample, and sampling variability available
  4. V.4 Estimators and estimation available
  5. V.5 Confidence intervals through repeated sampling available
  6. V.6 Covariance matrices and multivariate spread available
  7. V.7 Regression fundamentals available
  8. V.8 Likelihood available
  9. V.9 Maximum Likelihood Estimation available
  10. V.10 Maximum A Posteriori estimation available

Part VI

Optimization

Learning as repeated parameter updates governed by an objective.

10 of 10 chapters written

  1. VI.1 Objective functions and optimization landscapes available
  2. VI.2 Local vs global optima and stationary points available
  3. VI.3 Convexity available
  4. VI.4 Gradient descent flagship chapter available
  5. VI.5 Learning rate and convergence behavior available
  6. VI.6 Momentum available
  7. VI.7 Stochastic and mini-batch gradient descent available
  8. VI.8 Adam intuition available
  9. VI.9 Constraints and projected/penalized intuition available
  10. VI.10 Numerical stopping and optimization diagnostics available

Part VII

Information Theory

Logarithms, entropy, and the loss behind token prediction.

8 of 8 chapters written

  1. VII.1 Logarithms and log probabilities in computation available
  2. VII.2 Self-information available
  3. VII.3 Entropy available
  4. VII.4 Cross entropy and negative log-likelihood available
  5. VII.5 KL divergence available
  6. VII.6 Logits and softmax available
  7. VII.7 Numerical stability: log-sum-exp and stable softmax available
  8. VII.8 From token logits to language-model loss available

Part VIII

Numerical Computing

Why equivalent expressions behave differently on real machines.

10 of 10 chapters written

  1. VIII.1 Floating-point representation available
  2. VIII.2 Rounding and representation error available
  3. VIII.3 Error propagation and conditioning available
  4. VIII.4 Catastrophic cancellation available
  5. VIII.5 Overflow and underflow available
  6. VIII.6 Stable algorithms available
  7. VIII.7 Numerical linear algebra realities available
  8. VIII.8 Sparse matrices and sparse structure available
  9. VIII.9 Vectorized computation available
  10. VIII.10 Reproducibility, random seeds, and nondeterminism available