# Selecting kernel bandwidth in practice

I am writing a blogpost on mapping in R, and a topic I incidentally touch on is optimal selection of bandwidth in kernel density estimation.

Below is a map of Charlotte (NC, USA), the colors indicate a kernel density estimate of crime. I am using a Gaussian kernel (which seems reasonable).

The question is which bandwidth to use.

Below bandwidth (0.01) looks reasonable:

This bandwidth (0.1) looks too large:

This bandwidth looks too small:

I came up with the following rule of thumb for kernel bandwidth selection (bearing in mind that most readers may not be very technically inclined):

Pick an arbitrary bandwidth.

• If it seems too low, multiply it by 3. If it still seems too low, multiply it by three again, and so on, until it becomes too high.

• Conversely, if the bandwidth seems too high, divide it by three again and again until it seems too low.

Pick the diagram which best represents the picture you want to convey (you may wish to do further adjustment of the bandwidth before coming to your final choice, e.g. experiment by increasing and decreasing the chosen value a little).

Does anyone have a better suggestion?

• Bandwidth selection is really a statistical issue rather than a programming specific problem. I believe your question belongs on Cross Validated where statistical topics are discussed. – MrFlick Jun 13 '15 at 2:49
• Many people work with the idea that you bracket a "good" bandwidth with a larger one that evidently smooths too much and a smaller one that doesn't remove enough noise. But it is important to remember that a bandwidth is not just a number but here, if I understand what you are doing correctly, a number with distance units. So, there should be substantive knowledge that should help with this: What is the spatial resolution of the data? Are they really point data or data for lots of small areas? Also, on what scales do you expect to see patterns? Is there no subject-matter expertise to guide? – Nick Cox Jun 13 '15 at 9:17
• Thanks! I've updated my blog post based on your comment. It really helps. – wwl Jun 13 '15 at 11:51
• If you wanna go for something simple use a plug in value, for instance Silverman's rule of thumb. Also the choice of kernel doesn't really matter for practically any "real" application, however choosing the right bandwidth is infinitely important. There are fully data driven ways to do this, but I think they are far beyond the scope of your (neat) blog entry. – Repmat Jul 8 '16 at 20:56