Sub topic 1
Sampling Distributions and the Standard Error
Prerequisites
This chapter assumes you know the mean, variance, and standard deviation; the normal distribution and z-scores; basic probability; and the idea of drawing a sample from a population. The code uses Python with NumPy and SciPy.
Sampling distributions and the standard error
A sampling distribution is the distribution of a statistic, such as the sample mean, across all possible samples of size n from one population. The standard error (SE) is the standard deviation of that distribution. For a sample mean, SE = s / √n, where s is the sample standard deviation.
Formulating the null and alternative hypotheses
The null hypothesis (H0) is the claim you test, usually "no effect," such as mean = 0. The alternative hypothesis (Ha) is what you accept if the evidence rejects H0. A two-tailed test uses Ha: mean ≠ μ0. A one-tailed test uses Ha: mean > μ0 or mean < μ0, and you must choose its direction before you see the data.
The test statistic: how far is the sample from the null?
The test statistic measures the distance between the sample mean and the hypothesized value, in standard error units:
test statistic = (sample mean − μ0) / SE
Use z when the population standard deviation is known. Otherwise, use t with n − 1 degrees of freedom.
Type I and Type II errors, significance level, and power
A Type I error rejects a true H0. A Type II error fails to reject a false H0. The significance level α is the largest Type I error rate you accept, commonly 0.05. Power is 1 − P(Type II error), the probability of correctly rejecting a false H0.
Making the decision: critical values and p-values
A critical value is the cutoff beyond which the test statistic leads to rejection. A p-value is the probability of a result at least as extreme as the one observed, assuming H0 is true. Reject H0 when |test statistic| > critical value, or equivalently when p-value < α.
Testing a single mean with z and t
The following code runs a two-tailed t-test on monthly returns with H0: mean = 0.
import numpy as np
from scipy import stats
returns = np.array([1.2, -0.4, 0.8, 2.1, -1.0, 0.5, 1.7, 0.3, -0.2, 1.1])
n = len(returns)
t_stat = (returns.mean() - 0.0) / (returns.std(ddof=1) / np.sqrt(n))
p_value = 2 * stats.t.sf(abs(t_stat), df=n - 1)
t_crit = stats.t.ppf(1 - 0.05 / 2, df=n - 1)
print(round(t_stat, 3), round(p_value, 4), round(t_crit, 3))
print("Reject H0" if abs(t_stat) > t_crit else "Fail to reject H0")Exercise
A sample of 25 observations has a sample standard deviation of 4 and a sample mean of 10. Which distribution applies to testing H0: μ = 8 at the 5% level, and what are its degrees of freedom?
Show answer
The t-distribution applies because σ is unknown. Degrees of freedom are n − 1 = 24. The two-tailed critical value is about ±2.064.