Kernel Density
Estimation
Learn how to estimate the probability density function of a continuous random variable from observed data using smooth kernel functions.
What is Kernel Density Estimation?
Kernel Density Estimation (KDE) is a non-parametric method for estimating the probability density function of a random variable. Instead of assuming data follows a known distribution (like the normal), KDE lets the data speak for itself.
Why Not Just Use a Histogram?
Visual Intuition: Building KDE
The KDE Formula
Given observations \( x_1, x_2, \ldots, x_n \), the kernel density estimator is:
Common Kernel Functions
| Kernel | Formula \( K(u) \) | Support |
|---|---|---|
| Gaussian | \( \frac{1}{\sqrt{2\pi}} e^{-u^2/2} \) | \( (-\infty, \infty) \) |
| Epanechnikov | \( \frac{3}{4}(1 - u^2) \) | \( |u| \leq 1 \) |
| Uniform | \( \frac{1}{2} \) | \( |u| \leq 1 \) |
| Triangular | \( 1 - |u| \) | \( |u| \leq 1 \) |
The Role of Bandwidth \( h \)
Bias-Variance Trade-off
The bandwidth \( h \) controls the fundamental trade-off in KDE. The Mean Integrated Squared Error (MISE) decomposes as:
KDE vs Histogram vs Parametric
| Property | KDE | Histogram | Parametric |
|---|---|---|---|
| Smoothness | Smooth | Discontinuous | Smooth |
| Assumptions | Minimal | Minimal | Strong |
| Tuning | Bandwidth \( h \) | Bin width | Model choice |
| Convergence | \( O(n^{-4/5}) \) | \( O(n^{-2/3}) \) | \( O(n^{-1}) \) |
| Flexibility | High | Moderate | Low |
Choosing Bandwidth \( h \)
How to Apply KDE: Step by Step
Example 1: Three Data Points
Suppose we observe \( x_1 = 1,\; x_2 = 3,\; x_3 = 4 \) and use a Gaussian kernel with \( h = 1 \). What is \( \hat{f}_h(2.5) \)?
where \( \phi(\cdot) \) is the standard normal PDF.
Example 2: Silverman's Rule
Given \( n = 100 \) observations with \( \hat{\sigma} = 2.5 \) and \( \text{IQR} = 3.2 \). Find the rule-of-thumb bandwidth.
The suggested bandwidth is \( h \approx 0.856 \).
Example 3: Bandwidth Effect on Shape
Common Mistakes
Summary: Key Concepts
| Concept | Key Idea |
|---|---|
| KDE Formula | \( \hat{f}_h(x) = \frac{1}{nh}\sum K\!\left(\frac{x-x_i}{h}\right) \) |
| Kernel \( K \) | Symmetric bump; choice matters little |
| Bandwidth \( h \) | Critical: controls bias-variance trade-off |
| MISE Rate | \( O(n^{-4/5}) \) for optimal \( h \) |
| Silverman's Rule | \( h = 0.9\,A\,n^{-1/5} \), fast default |
| Best Practice | Visualize with multiple \( h \) values |
Question 1 of 5
In the KDE formula \( \hat{f}_h(x) = \frac{1}{nh}\sum_{i=1}^{n} K\!\left(\frac{x - x_i}{h}\right) \), what does \( h \) control?
Question 2 of 5
If the bandwidth \( h \) is too large, the KDE estimate will be:
Question 3 of 5
Which kernel is theoretically optimal in the sense of minimizing the Mean Integrated Squared Error (MISE)?
Question 4 of 5
Silverman's rule of thumb for bandwidth is \( h = 0.9 \cdot A \cdot n^{-1/5} \). What is \( A \)?
Question 5 of 5
The optimal MISE convergence rate for KDE with a second-order kernel is: