Parameters and Statistics
A number that describes a population is called a parameter. A number that describes a sample is called a statistic. The easy way to remember it: Parameter ↔ Population, Statistic ↔ Sample.
| Parameter | Statistic | |
|---|---|---|
| Describes | the whole population | a sample |
| Usually known? | No, that is why we study samples | Yes, we compute it from the data |
| Fixed or random? | Fixed (one true value) | Varies from sample to sample |
| Mean | μ |
x̄ |
| Standard deviation | σ |
s |
| Proportion | p |
p̂ |
The core idea of inferential statistics is to use a statistic to estimate an unknown parameter, and to say how far off the estimate might be.
Example: a vending machine
A company owns 4,000 vending machines. The proportion of machines that have a jammed coin slot right now is a parameter p. Nobody knows it exactly. A technician inspects 120 randomly chosen machines and finds 9 jammed ones. The sample proportion is a statistic:
p̂ = 9 / 120 = 0.075p̂ = 0.075 is our best single guess (a point estimate) for p. A different technician inspecting a different 120 machines would get a different p̂, but p itself would not change.
Seeing the difference in code
In a simulation we can know the parameter, which lets us watch statistics scatter around it:
import numpy as np
rng = np.random.default_rng(8)
# population: 4,000 machines, True = jammed (we secretly set the jam rate to about 6%)
machines = rng.random(4000) < 0.06
p = machines.mean()
print(f"parameter p (whole population): {p:.4f}")
for inspection in range(1, 6):
sample = rng.choice(machines, size=120, replace=False)
print(f"inspection {inspection}: {sample.sum():2d} jammed -> p-hat = {sample.mean():.4f}")parameter p (whole population): 0.0548
inspection 1: 10 jammed -> p-hat = 0.0833
inspection 2: 4 jammed -> p-hat = 0.0333
inspection 3: 8 jammed -> p-hat = 0.0667
inspection 4: 2 jammed -> p-hat = 0.0167
inspection 5: 8 jammed -> p-hat = 0.0667
Every inspection produced a different statistic, while the parameter stayed put. Some estimates were above p, some below. On average they are right, but any single one can miss.
Unbiased statistics
A statistic is unbiased if, averaged over all possible samples, it equals the parameter it estimates. The sample mean x̄ is unbiased for μ, and p̂ is unbiased for p.
The sample variance is a famous subtle case. If you divide the squared deviations by n, the result is on average too small. Dividing by n − 1 instead fixes this. That is why there are two versions of variance and standard deviation (see Standard Deviation):
import numpy as np
rng = np.random.default_rng(1)
population = rng.normal(100, 15, size=100_000)
sigma2 = population.var() # the parameter, variance of the population
print(f"population variance: {sigma2:.1f}")
divide_by_n, divide_by_n_minus_1 = [], []
for _ in range(20_000):
s = rng.choice(population, size=5)
divide_by_n.append(s.var(ddof=0))
divide_by_n_minus_1.append(s.var(ddof=1))
print(f"average of var with /n : {np.mean(divide_by_n):.1f}")
print(f"average of var with /(n-1) : {np.mean(divide_by_n_minus_1):.1f}")population variance: 223.4
average of var with /n : 179.5
average of var with /(n-1) : 224.3
With samples of only 5 values, dividing by n underestimates the variance by about 20% (a factor of (n−1)/n = 4/5), while dividing by n − 1 is right on target on average. ddof means "delta degrees of freedom": the divisor is n − ddof.
Parameters in Python's statistics module
The statistics module offers both versions explicitly:
import statistics
scores = [72, 85, 90, 66, 78, 88]
print("sample stdev s =", round(statistics.stdev(scores), 3))
print("population stdev σ =", round(statistics.pstdev(scores), 3))
print("sample variance s² =", round(statistics.variance(scores), 3))
print("population var σ² =", round(statistics.pvariance(scores), 3))sample stdev s = 9.517
population stdev σ = 8.687
sample variance s² = 90.567
population var σ² = 75.472
Use the p… functions only when your data really is the entire population. If it is a sample (the usual case), use stdev and variance.
Test yourself
The average age of *all* 312 employees of a firm is 41.2 years. Is 41.2 a parameter or a statistic?
- A parameter, because it describes the whole population of employees
- A statistic, because it is a number
- A statistic, because it was computed
- Neither
Which of these changes from one sample to the next?
- μ
- p
- x̄
- σ
Which statistics function should you use for the standard deviation of a *sample*?
statistics.pstdevstatistics.stdevstatistics.pvariancestatistics.mean