The sections follow the chapters of Part I of the textbook. Every file is a standalone script that prints the theoretical values next to the simulated ones. Most scripts need only base MATLAB; the few optional toolbox calls are noted in the file headers.
Discrete Random Variable
- Empirical PDF of a fair die (code)
- Rolling a pair of dice (code)
- Sum of Bernoulli variables is binomial (code)
Continuous Random Variable
- Moments of \(Y=X^2+1\), \(X\sim\mathrm{Exp}(\lambda)\), as a function of the number of experiments (code)
- Number of Bernoulli draws until the first “1” is geometric (code)
- \(\Pr\left(X^{1/4}<1/2\right)=1/16\) for \(X\sim\mathrm{U}[0,1]\) (code)
- Estimating a PDF value from a single histogram bin (code)
- The Q-function by simulation (code)
- Central limit theorem: a sum of many \(\pm1\) variables (code)
Two Random Variables
- Sum of two fair dice, empirical vs exact distribution (code)
- \(\Pr\left(X^{1/3}>Y/2\right)=31/32\) for two independent uniform variables (code)
- Joint CDF of a bivariate Gaussian (code)
- Gaussian marginals without a jointly Gaussian pair (code)
Linear Prediction
- Optimal linear predictor for a correlated pair (code)
- Linear prediction for a bivariate Gaussian pair (code)
- Dependent but uncorrelated: \(Y\approx X^2\Rightarrow\rho_{XY}=0\) (code)
- Quadratic vs linear predictor (code)
Descriptive Statistics
- Biased vs unbiased variance estimators (code)
- Monte-Carlo error vs the number of experiments (code)
- Sample skewness and excess kurtosis (code)
Statistical Plots
- The bin-width trade-off (code)
- Fluctuation of histogram bin counts (code)
- Boxplot vs violin plot of bimodal data (code)
- Fitting a distribution to a pdf histogram (code)
Uni-Variate Linear Least-Squares
- A complete uni-variate fit by hand (code)
- How large a correlation coefficient pure noise can produce (code)
- Training MSE against the sample size (code)
- Reading \(\vert r_{xy}\vert\) off a scatter plot (code)