Interactive demo · Statistical Methods for Modern Biology · Chapter 3

Kernel density estimation: the bandwidth decides what you see

A kernel density estimate puts a small bump of width h on every observation and adds them up: f̂(x) = (1/n) Σ Kh(x − xi). A small h follows every observation (low bias, high variance, a wiggly curve); a large h smooths real features away (high bias, low variance). Use the real expression values of four genes in 101 mouse embryo cells (Figure 3.19 of Holmes and Huber 2019), or a simulated mixture whose true density is known, so that the error can be measured. The bandwidth is the standard deviation of the kernel, as in R's density().

Data

Sample size n (simulation)

Kernel

Bandwidth h (kernel standard deviation)

Show

Read-out

Try these

Silverman's rule (R's bw.nrd0) is 0.9 min(s, IQR/1.34) n−1/5, Scott's (bw.nrd) uses 1.06 instead of 0.9. The AMISE-optimal bandwidth needs the true density, so it is offered only for the simulation: h* = [R(K) / (R(f″) n)]1/5 for a kernel with unit variance. Simulated samples use a seeded generator, so everyone sees the same samples.

In the lecture notes