এই বইটি এখনো বাংলা ভাষায় পাওয়া যায় না। সংস্করণ: English।
University Economics — Year 1 · স্নাতক প্রথম বর্ষ
30Random Variables for Econometrics
Draw five men at random from the 2,490 of the PSID sample and average their 1978 earnings; draw five more and average again. Repeated 10,000 times, the averages spread with a standard deviation of 6,979 dollars around the population mean of 21,554 (dollars of 1982, as everywhere in this chapter’s earnings). With thirty men the spread falls to 2,840; with two hundred, to 1,093.
Each figure is close to the population’s standard deviation divided by the square root of the sample size. This chapter gives the probability behind that rule — conditional expectations, the distributions that tests use, the law of large numbers and the central limit theorem — and the cases in which it fails.
The earnings themselves are skewed to the right (Chapter 29); the means of five are less skewed, and the means of two hundred look like a bell curve centred on the population mean.
You already know
Random variables, expectation, variance, independence, the binomial and normal laws and the law of large numbers were met in the mathematics series at school; the central limit theorem is proved in its third university volume. Describing data is Chapter 29.
30.1 Expectation, variance, covariance
For random variables , and numbers , : , and .
Notation 30.1
The covariance of two random variables is , defined in the mathematics series (second university volume). Then , and for independent with variance , .
30.2 Joint and conditional distributions
Definition 30.2 (Joint and conditional distributions)
The joint distribution of two discrete random variables gives for every pair; the marginal distributions are its row and column sums. The conditional distribution of given is .
"""A joint distribution: schooling and earnings bracket, PSID sample, 1978."""
import pandas as pd
from econdata import nsw
d = nsw("psid_controls")
school = pd.cut(d.education, [0, 11, 12, 20], labels=["<12", "12", ">12"])
bracket = pd.cut(d.re78, [-1, 10_000, 30_000, 1e9], labels=["<10k", "10-30k", ">30k"])
joint = pd.crosstab(school, bracket, normalize=True, margins=True).round(3)
print("joint distribution, with marginals:")
print(joint)
cond = pd.crosstab(school, bracket, normalize="index").round(3) # rows sum to 1
print("earnings bracket given schooling:")
print(cond)
$ python joint_table.py
joint distribution, with marginals:
re78 <10k 10-30k >30k All
education
<12 0.112 0.161 0.031 0.304
12 0.058 0.223 0.062 0.343
>12 0.055 0.159 0.138 0.353
All 0.226 0.543 0.231 1.000
earnings bracket given schooling:
re78 <10k 10-30k >30k
education
<12 0.367 0.530 0.103
12 0.170 0.651 0.179
>12 0.157 0.450 0.392
30.3 Conditional expectation
Definition 30.3 (Conditional expectation)
The conditional expectation of given is . As a function of it is the conditional expectation function; is that function applied to , a random variable.
Theorem 30.4 (Law of iterated expectations)
.
Proof. In the discrete case, . ∎
"""The law of iterated expectations, checked on the PSID sample."""
from econdata import nsw
d = nsw("psid_controls")
cond = d.groupby("education").re78.mean() # E[Y | X = x] for each x
weight = d.education.value_counts(normalize=True) # P(X = x)
print(f"E[E[Y|X]] = {(cond * weight).sum():.6f}")
print(f"E[Y] = {d.re78.mean():.6f}")
$ python iterated.py
E[E[Y|X]] = 21553.920778
E[Y] = 21553.920778
Proposition 30.5 (The best predictor)
Among all functions , is smallest for .
Proof. Write . Then . Conditionally on , is a number and , so the last term is zero by the law of iterated expectations. The middle term is at least zero, and zero for . ∎
"""Three predictors of earnings from schooling: mean squared errors."""
import numpy as np
from econdata import nsw
d = nsw("psid_controls")
x, y = d.education, d.re78
pred = {
"overall mean": np.full(len(y), y.mean()),
"a line": np.polyval(np.polyfit(x, y, 1), x),
"conditional mean": d.groupby("education").re78.transform("mean"),
}
for name, p in pred.items():
print(f"{name:17s} MSE {((y - p) ** 2).mean() / 1e6:8.2f} million")
$ python best_predictor.py
overall mean MSE 241.87 million
a line MSE 211.61 million
conditional mean MSE 208.73 million
Definition 30.6 (Mean independence)
is mean independent of when does not depend on . Independence implies mean independence, which implies ; neither converse holds (Exercise 30.11).
30.4 The tools
Definition 30.7 (Chi-square, Student’s and distributions)
Let be independent standard normal variables. has the chi-square distribution with degrees of freedom, . If is independent of , has Student’s distribution with degrees of freedom. If and are independent, has the distribution with and degrees of freedom.
The constants are the exact normalising factors: for , and , which is for and for .
"""Critical values the next chapters use (upper tails)."""
from scipy import stats
print(" 5% 2.5%")
print(f"N(0,1) {stats.norm.ppf(0.95):7.3f} {stats.norm.ppf(0.975):7.3f}")
for k in (1, 5, 30):
print(
f"chi2({k:2d}) {stats.chi2.ppf(0.95, k):6.3f} {stats.chi2.ppf(0.975, k):7.3f}"
)
for k in (5, 30, 100):
print(f"t({k:3d}) {stats.t.ppf(0.95, k):7.3f} {stats.t.ppf(0.975, k):7.3f}")
for k, m in ((2, 30), (5, 100)):
print(
f"F({k},{m:3d}) {stats.f.ppf(0.95, k, m):6.3f} {stats.f.ppf(0.975, k, m):7.3f}"
)
$ python distributions.py
5% 2.5%
N(0,1) 1.645 1.960
chi2( 1) 3.841 5.024
chi2( 5) 11.070 12.833
chi2(30) 43.773 46.979
t( 5) 2.015 2.571
t( 30) 1.697 2.042
t(100) 1.660 1.984
F(2, 30) 3.316 4.182
F(5,100) 2.305 2.696
"""Student's t built from normal variables, against scipy's."""
import numpy as np
from scipy import stats
rng = np.random.default_rng(2026)
k, draws = 5, 200_000
z = rng.standard_normal(draws)
v = (rng.standard_normal((draws, k)) ** 2).sum(axis=1) # chi-square with k degrees
t = z / np.sqrt(v / k)
for p in (0.9, 0.95, 0.975, 0.99):
print(
f"{p:5.3f} simulated {np.quantile(t, p):6.3f} exact {stats.t.ppf(p, k):6.3f}"
)
$ python build_t.py
0.900 simulated 1.477 exact 1.476
0.950 simulated 2.018 exact 2.015
0.975 simulated 2.551 exact 2.571
0.990 simulated 3.339 exact 3.365
How it is measured — Drawing a sample in a computer
A computer draws “random” numbers from a deterministic sequence that starts from a seed. The same seed gives the same draws, so a simulation can be rerun and give the same digits, which is why every simulation in this book fixes its seed. A different seed gives different digits and, if the simulation is large enough, the same conclusions.
30.5 The law of large numbers and the central limit theorem
Definition 30.8 (Sampling distribution)
The sampling distribution of a statistic is its distribution over repeated samples of the same size from the same population.
By the law of large numbers, the mean of independent draws converges to the population mean as grows.
"""The law of large numbers: a running mean of earnings drawn at random."""
import numpy as np
from econdata import nsw
y = nsw("psid_controls").re78.to_numpy()
rng = np.random.default_rng(2026)
draws = rng.choice(y, size=100_000) # with replacement
running = draws.cumsum() / np.arange(1, len(draws) + 1)
for n in (10, 100, 1_000, 10_000, 100_000):
print(f"n = {n:>7,}: mean {running[n - 1]:9,.0f}")
print(f"population mean {y.mean():9,.0f}")
$ python lln.py
n = 10: mean 25,148
n = 100: mean 22,006
n = 1,000: mean 21,651
n = 10,000: mean 21,919
n = 100,000: mean 21,584
population mean 21,554
Theorem 30.9 (Central limit theorem)
If are independent with the same distribution, mean and finite variance , then for every , as , where is the standard normal distribution function.
Proof. Admitted at this level. ∎
Proved in the mathematics series, third university volume.
"""Sample means of earnings for n = 5, 30, 200: spread and shape."""
import numpy as np
from econdata import nsw
from scipy.stats import skew
y = nsw("psid_controls").re78.to_numpy()
sigma = y.std() # the population is the sample of 2,490: divide by N
rng = np.random.default_rng(2026)
print(f"population: mean {y.mean():,.0f} sd {sigma:,.0f} skewness {skew(y):.2f}")
for n in (5, 30, 200):
means = rng.choice(y, size=(10_000, n)).mean(axis=1)
se = sigma / np.sqrt(n)
print(
f"n = {n:3d}: sd of means {means.std():6,.0f} sigma/sqrt(n) {se:6,.0f}", end=""
)
print(f" skewness {skew(means):.2f}")
$ python clt.py
population: mean 21,554 sd 15,552 skewness 1.24
n = 5: sd of means 6,979 sigma/sqrt(n) 6,955 skewness 0.51
n = 30: sd of means 2,840 sigma/sqrt(n) 2,839 skewness 0.23
n = 200: sd of means 1,093 sigma/sqrt(n) 1,100 skewness 0.12
Definition 30.10 (Random sample)
A random sample of size is a set of observations drawn independently from one population, each with the population’s distribution; drawing one is random sampling.
Model — Random sampling
Assumes. Observations drawn independently from one population with a finite variance.
Predicts. Sample means centred on the population mean, with standard deviation , and approximately normal for large .
Tested. Checked, not tested, by simulation from a real, skewed population (opening chart): the standard deviations of the means are within of for 5, 30 and 200 men, but the draws are independent by construction. Whether a real survey’s observations are independent is a property of how it was drawn; a test compares its estimates with a known total, or the spread of its estimates with the spread its design implies (Chapter 31).
Breaks. Dependent draws — months of one time series, members of one family, pupils of one class — make the spread larger than (the second university year treats them); populations so heavy-tailed that the variance does not exist make the means settle far more slowly.
"""Means of a Pareto population with alpha = 1.5: the variance does not exist."""
import numpy as np
rng = np.random.default_rng(2026)
alpha = 1.5 # mean alpha / (alpha - 1) = 3, variance infinite
for n in (100, 10_000, 1_000_000):
x = rng.pareto(alpha, size=(20, n)) + 1 # Pareto with minimum 1
means = x.mean(axis=1)
print(f"n = {n:>9,}: means from {means.min():.2f} to {means.max():.2f}")
$ python heavy_tails.py
n = 100: means from 2.00 to 12.12
n = 10,000: means from 2.76 to 3.55
n = 1,000,000: means from 2.94 to 3.22
With a finite variance, ten thousand times more data would narrow the range a hundredfold. Here, from samples of 100 to samples of a million, the range shrinks from to , a factor of 36.
Exercises
Exercise 30.1 ★
and . Find and .
Solution
Solution of Exercise 30.1.
; .
Exercise 30.2 ★
From the rounded joint table of Output 30.1, compute .
Solution
Solution of Exercise 30.2.
with the rounded table ( unrounded, as the conditional table prints).
Exercise 30.3 ★
From Output 30.7, give the standard deviation of the means for and compare it with .
Solution
Solution of Exercise 30.3.
2,840 dollars, against : within one dollar.
Exercise 30.4 ★
Predict the standard deviation of the means for .
Solution
Solution of Exercise 30.4.
dollars, half the value for , since 120 is four times 30.
Exercise 30.5 ★★
of a population is in group A, with mean earnings 10, and in group B, with mean 20. Find mean earnings.
Solution
Solution of Exercise 30.5.
By the law of iterated expectations, .
Exercise 30.6 ★★
, , . Find .
Solution
Solution of Exercise 30.6.
.
Exercise 30.7 ★★
Using the central limit theorem and the population values of Output 30.7, give the interval that contains of the means of 200 men.
Solution
Solution of Exercise 30.7.
, so of the means lie within dollars of (2,155 unrounded): from about 19,400 to 23,710 dollars.
Exercise 30.8 ★★
Find the mean and the variance of , using and .
Solution
Solution of Exercise 30.8.
. , and the terms are independent, so .
Exercise 30.9 ★★
A survey of men samples pairs of brothers, whose earnings have a correlation within each pair. Predict the variance of the mean.
Solution
Solution of Exercise 30.9.
With variance for each man, the sum of a pair has variance . The mean of independent pairs, divided by , has variance : larger than by the factor .
Exercise 30.10 ★★★
Prove Proposition 30.5 by writing as a function of the number , for each .
Solution
Solution of Exercise 30.10.
For a given , , smallest at . Choosing this way for every minimises each term of , hence the sum.
Exercise 30.11 ★★★
Show that mean independence implies zero covariance, and give an example of zero covariance without mean independence.
Solution
Solution of Exercise 30.11.
If , then by the law of iterated expectations, so . Counterexample to the converse: equal to , 0 or 1 with probability each and . Then , but and .
Exercise 30.12 ★★★
What simulation result would show that the normal approximation fails for means of 30 draws from a given population?
Solution
Solution of Exercise 30.12.
Many simulated samples of 30 from that population, with the share of means outside far from , or a histogram of the means that is clearly skewed, or simulated quantiles of the standardised mean far from the normal ones. A population with a very heavy tail, such as the Pareto one of the chapter, would show it.
30.6 Problem: The Brenland Lottery of Surveys
Problem 30.1
Weekend problem — a population, and 10,000 surveys of it
Treat the 2,000 households of Brenland’s survey (invented) as the whole population. Survey firms draw 100 households with replacement; a script simulates 10,000 such surveys with a fixed seed.
Part I — A joint distribution. Classify households by size (1 to 5) and by disposable income (under 20,000, 20,000 to 30,000, 30,000 or more dalens).
- Give the marginal distribution of size.
- Give .
- Give and .
- Are size and income independent?
- Why might larger households have higher income?
Part II — Conditional expectations.
- Give mean income by household size.
- Check the law of iterated expectations.
- Is income mean independent of size?
- Which predictor of income from size has the smallest mean squared error?
- Would mean income per person behave the same way?
Part III — The sampling distribution.
- Give the population mean and standard deviation.
- Predict the standard deviation of the survey means.
- Give the simulated standard deviation.
- Within what distance of the true mean do of survey means fall, by simulation?
- And by the central limit theorem?
- How would the distance change with 400 households?
- Why draw with replacement?
Part IV — A statistic. In each survey, compute with the survey’s standard deviation.
- What distribution would have if incomes were normal?
- Give the upper quantile of .
- What share of the surveys has above it?
- Give the standard deviation of the 10,000 values of .
- Why is the share close to although incomes are skewed?
- What would make it far from ?
- What does a survey firm learn from one survey’s , when is unknown?
- State the result: within what distance of the truth is the mean income of 100 households in of surveys?
Solution
Solution of Problem 30.1.
1. Sizes 1 to 5: , , , , .
2. .
3. for size 1; for size 4, with the rounded table ( unrounded).
4. No: the conditional distribution of income changes with size.
5. Larger households more often have two earners.
6. 23,326; 24,004; 26,678; 26,834; 26,249 dalens for sizes 1 to 5.
7. The weighted mean of the conditional means is 24,919.72, equal to the population mean.
8. No: mean income changes with size, from 23,326 to 26,834.
9. The conditional mean by size (Proposition 30.5).
10. No: income per person falls with size, from 23,326 for one person to about 5,250 for five.
11. and dalens (dividing by 2,000, the population).
12. .
13. 1,061.2.
14. 2,061 dalens.
15. .
16. It would halve, to about 1,040.
17. Draws with replacement are independent and from the same population, so exactly.
18. Student’s with 99 degrees of freedom.
19. .
20. .
21. .
22. With 100 households the mean is close to normal by the central limit theorem, and is close to .
23. Small samples from very skewed or heavy-tailed populations, or dependent draws.
24. Alone, nothing; but the share of item 20 means that the interval contains in about of surveys (Chapter 31).
25. With 100 households, the mean income is within 2,061 dalens of the truth in of surveys, close to the 2,078 that the central limit theorem predicts.