3.2 Non-parametric estimation
We start by defining the empirical distribution function.In the example below, we draw a sample of size 100 from the \(\mathsf{N}(0,1)\) distribution and plot the empirical distribution function of the sample. This can be done easily using gg-plot.
## Warning: package 'ggplot2' was built under R version 4.6.1
cbp1 <- c("#999999", "#E69F00", "#56B4E9", "#009E73",
"#F0E442", "#0072B2", "#D55E00", "#CC79A7")
ggplot(data.df, aes(x)) +
stat_function(fun = pnorm, color = cbp1[2], size = 1) +
stat_ecdf(geom = "step", size = 1) +
labs( y = "F(x)", x = "x") +
theme_minimal()## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once per session.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
Figure 3.1: Empirical and true distribution function
Now we may estimate any parameter that is a functional of \(F\) by simply replacing \(F\) by \(\hat F_n\).
Let us consider functionals that can be written as \[ T(F) = \int r(x) dF(x), \] for some function \(r\). Clearly the mean and the variance are examples of this. Then the plug-in estimator is \[ T(\hat F_n) = \int r(x)d\hat F_n(x). \] Since the empirical distribution is a discrete distribution that puts mass \(1/n\) at each point \(x_i\), the corresponding empirical probability function is, \[ \hat p_n(x) = \begin{cases} 1/n & \text{if } x = x_i \text{ some } i \\ 0 & otherwise \end{cases} \] The function can then be written: \[ T(\hat F_n) = \int r(x) d\hat F_n(x) = \sum_{i=1}^n r(x_i) \hat p_n(x_i) = \frac{1}{n} \sum_{i=1}^n r(x_i). \] The plug-in estimates of such functionals is therefore simple to calculate. For example, \[\begin{align} \hat \mu &= \mu(\hat F_n) =\int x d\hat F_n(x) = \frac{1}{n} \sum_{i=1}^n x_i,\\ \hat \sigma^2 &= \sigma^2(\hat F_n) = \int x^2 d\hat F_n(x) - \left(\int xd\hat F_n(x) \right)^2 = \frac{1}{n}\sum_{i=1}^n x_i^2 + \left( \frac{1}{n}\sum_{i=1}^n x_i\right)^2 = \frac{1}{n}\sum_{i=1}^n (x_i -\bar x)^2. \end{align}\]
The plug in estimator of the \(p\)th quantile becomes the \(p\)th sample quantile: \[ \hat F_n^{-1}(p) = \inf \left\{ x \mid \hat F_n(x)\geq p \right\}. \] That is, it is the smallest \(x\) such that \(\hat F_n(x)\geq p\). Looking at the picture it seems as in our sample, for example, \(\hat F_n^{-1}(0.75)\approx 0.7\). Calculating precisely:
## 75%
## 0.6556479