Kernel Density Estimation
Study guides: Exam MAS-I, Exam ACIA-CAPSTONE
Kernel Density Estimation is a nonparametric method of estimating a density from a sample x_1, \ldots, x_n, in which each observation is replaced by a density centred on it, called a kernel, and the n kernels are averaged. If k_y(x) is the kernel centred at y, the kernel density estimate at x is
\hat{f}(x) = \frac{1}{n}\sum_{i=1}^{n} k_{x_i}(x)
The spread of each kernel is set by its bandwidth b > 0. A larger bandwidth gives a smoother estimate that can miss local features of the data, and a smaller one follows the data closely but varies more, a bias-variance tradeoff.
The rectangular kernel
The rectangular, or uniform, kernel spreads each observation evenly over the interval from y - b to y + b:
k_y(x) = \frac{1}{2b}
y - b \le x \le y + b, andk_y(x) = 0outside this interval.
An observation contributes \frac{1}{2b} to the sum when it is within b of x, including an observation exactly b from x. The estimate is therefore the number of observations within b of x, divided by 2bn.
Five losses are 300, 450, 500, 700 and 800. What is the rectangular kernel density estimate at 600 with bandwidth 200?
- The observations within 200 of 600 are 450, 500, 700 and 800, where 800 is exactly 200 away.
- The loss of 300 is 300 away and contributes 0.
- The estimate is
\hat{f}(600) = \dfrac{4}{2 \times 200 \times 5} = 0.0020.
The triangular kernel
The triangular kernel is a tent over the same interval, highest at y:
k_y(x) = \frac{b - |x - y|}{b^2}
y - b \le x \le y + b, andk_y(x) = 0outside this interval.
An observation exactly b from x contributes 0.
For the same five losses, what is the triangular kernel density estimate at 600 with bandwidth 200?
- The distances from 600 to 450, 500, 700 and 800 are 150, 100, 100 and 200, so the numerators
b - |x - x_i|are 50, 100, 100 and 0.- The loss of 300 is outside the interval and contributes 0.
- The estimate is
\hat{f}(600) = \dfrac{250}{40{,}000 \times 5} = 0.00125.
The Gaussian kernel
The Gaussian kernel is the normal density with mean y and standard deviation b:
k_y(x) = \frac{1}{b\sqrt{2\pi}}\, e^{-(x - y)^2/(2b^2)}
Unlike the other two kernels, it gives every observation some weight at every x.
For the same five losses, what is the Gaussian kernel density estimate at 600 with bandwidth 200?
- The standardized distances
(600 - x_i)/200are 1.5, 0.75, 0.5,-0.5and-1.0.- The standard normal density at these values is 0.1295, 0.3011, 0.3521, 0.3521 and 0.2420, with sum 1.3768.
- The estimate is
\hat{f}(600) = \dfrac{1.3768}{200 \times 5} = 0.00138.
The kernel-smoothed distribution function
The kernel-smoothed estimate of the cdf averages the cdfs of the kernels:
\hat{F}(x) = \frac{1}{n}\sum_{i=1}^{n} K_{x_i}(x)
K_y(x)is the cdf of the kernel centred aty.
For the rectangular kernel, K_y(x) is 0 for x < y - b, 1 for x > y + b, and in between
K_y(x) = \frac{x - (y - b)}{2b}
Claim sizes, in thousands, are 2, 5, 6, 9 and 15. What is the kernel-smoothed estimate of
F(6.5)with a rectangular kernel of bandwidth 2?
- The claim of 2 lies wholly below 6.5, so
K_2(6.5) = 1.K_5(6.5) = (6.5 - 3)/4 = 0.875andK_6(6.5) = (6.5 - 4)/4 = 0.625.- The claims of 9 and 15 lie wholly above 6.5, so they contribute 0.
- The estimate is
\hat{F}(6.5) = (1 + 0.875 + 0.625)/5 = 0.5.
Leaving out an observation exactly
baway The rectangular kernel's interval is closed, so an observation exactlybfromxcontributes\frac{1}{2b}. In the first example, leaving out the loss of 800 gives\hat{f}(600) = 0.0015instead of 0.0020.