- Introduced by
- Hjort & Glad (1995); extended by various authors in Bayesian nonparametrics
- Year
- 1995
- Type
- Nonparametric density estimation
- Family
- GIS / spatial
What does it do?
Bayesian Kernel Density Estimation (BKDE) is a nonparametric method for estimating the probability density function of a spatial or attribute variable by combining a kernel smoother with a Bayesian prior over the bandwidth parameter.
The posterior distribution of the bandwidth propagates uncertainty into the final density estimate rather than treating the bandwidth as a fixed tuning constant.
The intuition behind the method
Standard kernel density estimation places a small smooth bump around each data point and sums them to form a density surface, but the result is very sensitive to the bandwidth h — the width of each bump. A Bayesian approach treats h as an unknown quantity and assigns it a prior distribution reflecting plausible smoothing levels. After observing the data, Bayes' theorem updates that prior to a posterior distribution over h. The final density estimate is then a weighted average of density surfaces over the range of plausible bandwidths, yielding fuller uncertainty representation than choosing a single optimal h.
History
Hjort and Glad (1995) developed semiparametric density estimators that multiply an initial parametric density by a kernel-type correction factor. Their paper also discusses procedures for choosing the smoothing parameter. It is a related kernel-based method rather than the origin of the Bayesian bandwidth approach described on this page.
When to use it
Choose Bayesian KDE when you need a smooth density surface for continuous data, such as spatial point locations or a univariate continuous attribute, and you want uncertainty about the density itself rather than a single surface. It is most useful when cross-validated bandwidths are unstable, for example when the sample is small or only weakly informative about the appropriate smoothing scale, or when substantive knowledge about the spatial scale of the phenomenon can be expressed as a prior on the bandwidth. Avoid it when the dataset is very large and computation time matters, because the bandwidth posterior must be approximated numerically. Avoid it also when a simple density map without uncertainty is sufficient; classical KDE with a cross-validated or rule-of-thumb bandwidth is then simpler to compute and explain. If the spatial data are strongly dependent or are areal counts, a model that represents the dependence directly, such as spatial regression or kriging, is usually more appropriate.
Limitations and considerations
- Computationally more demanding than classical KDE, because the bandwidth posterior must be evaluated on a grid or sampled with MCMC.
- The posterior density depends on the prior placed on h, and this dependence is strongest when the sample is small.
- The averaged density surface is a mixture over bandwidths, which can be harder to explain to readers who expect a single fixed-bandwidth map.
- The method does not model spatial dependence explicitly. For spatially correlated measurements rather than event locations, kriging or spatial regression is usually more appropriate.
- The likelihood is a pseudo-likelihood built from kernel density values, not a generative model of the data, so credible intervals describe uncertainty in the bandwidth and are not calibrated probabilities for the spatial process.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Bandwidth uncertainty is carried into the density estimate, so the output includes credible intervals rather than only one point estimate.
- A prior on the bandwidth lets domain knowledge about the spatial scale of the phenomenon enter the analysis explicitly, which can help when the data alone say little about smoothing.
- Averaging over a posterior of bandwidths can reduce dependence on any single bandwidth value. The result still depends on the prior, so prior sensitivity should be checked.
- The density is estimated from the observations without assuming a parametric distributional form.
Applications
- Spatial point-pattern analysis: mapping hotspots of crime incidents, disease cases, or ecological sightings with credible-interval maps.
- Environmental science: estimating the density of pollution measurements or species observations across a landscape.
- Urban analytics: visualising the spatial distribution of urban events such as accidents or service requests with uncertainty bands.
- Epidemiology: producing smooth disease-risk surfaces from case locations while quantifying estimation uncertainty.
How it works
How it works
A prior distribution p(h) is placed on the bandwidth parameter h, encoding beliefs about reasonable smoothing levels before any data are seen. Common choices include log-normal or half-normal priors.
Formula
p(h) \propto \pi(h)
For each candidate bandwidth h, the likelihood is formed from the kernel density values at the observed data points, which scores how well that bandwidth fits the data. It is a pseudo-likelihood: it is built from density evaluations rather than from a generative model of how the data arose, so it works as a tuning-oriented criterion for h.
Formula
L(h \mid x_1,\ldots,x_n) = \prod_{i=1}^{n} \hat{f}_h(x_i)Bayes' theorem combines the prior and the likelihood to obtain the posterior distribution of h given the data. This posterior concentrates around bandwidths that balance fidelity to the data against the prior's smoothness preference. Because the likelihood is a pseudo-likelihood, the posterior summarises bandwidth uncertainty for smoothing purposes and should not be read as a calibrated probability model of the spatial process.
Formula
p(h \mid \mathbf{x}) \propto L(h \mid \mathbf{x})\,\pi(h)The Bayesian density estimate integrates the standard kernel density estimator over the posterior of h, so the final surface is a mixture of density curves with different bandwidths weighted by their posterior probability.
Formula
\hat{f}(x) = \int \frac{1}{nh}\sum_{i=1}^{n} K\!\left(\frac{x-x_i}{h}\right) p(h \mid \mathbf{x})\,dhCredible intervals for the density at any point x can be obtained by sampling bandwidth values from the posterior, for example with MCMC or on a grid, computing the density surface for each sample, and summarising across samples by pointwise quantiles. These intervals inherit the pseudo-likelihood caveat above and reflect uncertainty in the bandwidth only, given the chosen kernel and prior.
Common pitfalls
- Using a vague or improper prior on h without a prior sensitivity analysis. Compare the density surfaces under several reasonable prior specifications before reporting results.
- Reading the Bayesian density estimate as a probabilistic model of the spatial process. It estimates the density of the observed locations or values; it does not describe how those locations were generated.
- Applying the method to counts aggregated into zones without accounting for the modifiable areal unit problem. Kernel-based density estimators assume individual point observations, so aggregated areal data need a different treatment.
- Reporting MCMC-based bandwidth posteriors without checking convergence. Inspect trace plots of the sampled chains, check that independent chains agree, and report effective sample sizes before summarising the posterior.
Frequently asked questions
How is Bayesian KDE different from ordinary KDE?
Ordinary KDE uses one bandwidth, chosen by a rule such as cross-validation or Silverman's rule of thumb, throughout the estimate. Bayesian KDE treats the bandwidth as a random quantity with a prior, and averages the density over the posterior distribution of the bandwidth. The result is a density with uncertainty information rather than a single surface.
What prior should I use for the bandwidth?
A log-normal or half-normal prior on h is a common choice because a bandwidth must be positive, and a log scale reflects multiplicative uncertainty in smoothing. Centring the prior near a reference bandwidth, such as the value given by Silverman's rule of thumb, with a moderate spread is a reasonable starting point. Prior sensitivity should then be checked.
Can Bayesian KDE be used for spatial data in two dimensions?
Yes. The kernel and bandwidth can be extended to two dimensions. The general form uses a bandwidth matrix H in place of a scalar h, with a prior placed on H. Computation becomes more expensive as the number of bandwidth parameters grows. A scalar bandwidth with an isotropic kernel is a simpler special case.
When should I use kriging instead of Bayesian KDE for spatial density?
Use kriging when the variable is a continuous measurement taken at sample locations and you need to predict its value at unsampled locations. Use Bayesian KDE when your data are event locations, or point observations, and you want to estimate their spatial density.
How is the bandwidth posterior computed in practice?
The bandwidth posterior is often approximated numerically, for example by evaluating the likelihood on a grid of h values, multiplying by the prior and normalising. For higher-dimensional bandwidth matrices, MCMC methods such as Metropolis-Hastings are used to draw posterior samples.
Related methods
Sources
Hjort, N. L., & Glad, I. K. (1995). Nonparametric density estimation with a parametric start. The Annals of Statistics, 23(3), 882–904.
Open DOI referenceKernel density estimation. Wikipedia.
Open publication reference