t-Distribution — When σ is Unknown
This is a comprehensive guide covering all key concepts, formulas, examples, and Python code.
Core Concepts
Understanding t-Distribution — When σ is Unknown is fundamental to statistical practice. This topic builds directly on prerequisite knowledge and prepares you for more advanced methods.
Formula and Theory
The mathematical foundation provides rigor and precision:
import numpy as np
import pandas as pd
from scipy import stats
import matplotlib.pyplot as plt
np.random.seed(42)
# Demonstration code
n = 100
data = np.random.normal(0, 1, n)
result = stats.describe(data)
print(f"n={result.nobs}, mean={result.mean:.4f}, var={result.variance:.4f}")
print(f"skewness={result.skewness:.4f}, kurtosis={result.kurtosis:.4f}")
Step-by-Step Example
Walk through a concrete example with real numbers:
# Practical example
sample = np.array([23, 28, 31, 19, 35, 27, 22, 30, 25, 28])
mean = sample.mean()
std = sample.std(ddof=1)
se = stats.sem(sample)
ci = stats.t.interval(0.95, df=len(sample)-1, loc=mean, scale=se)
print(f"Mean: {mean:.2f}")
print(f"Std: {std:.2f}")
print(f"SE: {se:.4f}")
print(f"95% CI: ({ci[0]:.2f}, {ci[1]:.2f})")
Visualization
fig, ax = plt.subplots(figsize=(8, 4))
ax.hist(sample, bins=8, edgecolor='black', color='steelblue', alpha=0.7)
ax.axvline(mean, color='red', lw=2, linestyle='--', label=f'Mean={mean:.1f}')
ax.set_title('t-Distribution — When σ is Unknown')
ax.legend()
plt.tight_layout()
plt.savefig('t-distribution.png', dpi=150)
plt.show()
Common Applications
- Scientific Research — hypothesis testing and effect estimation
- Business Analytics — A/B testing and performance metrics
- Machine Learning — model evaluation and cross-validation
- Quality Control — process monitoring and acceptance sampling
Assumptions and When It Applies
| Assumption | Check | Consequence if Violated |
|---|---|---|
| Random sampling | Study design | Biased estimates |
| Independence | Correlation check | Inflated precision |
| Appropriate scale | Data type review | Invalid inference |
Key Takeaways
- Master the core formula — understand what every symbol means
- Check assumptions before applying the method
- Visualize results — graphs reveal what formulas miss
- Python makes it practical — SciPy and NumPy implement all standard methods
- Interpret in context — a number without context is meaningless
- Connect to adjacent topics — statistics is a web of interconnected ideas