• Descriptive
    • Moments
    • Concentration
    • Central Tendency
    • Variability
    • Stem-and-Leaf Plot
    • Histogram & Frequency Table
    • Data Quality Forensics
    • Conditional EDA
    • Quantiles
    • Kernel Density Estimation
    • Normal QQ Plot
    • Bootstrap Plot

    • Multivariate Descriptive Statistics
  • Distributions
    • Binomial Probabilities
    • Geometric Probabilities
    • Negative Binomial Probabilities
    • Hypergeometric Probabilities
    • Multinomial Probabilities
    • Poisson Probabilities

    • Exponential
    • Gamma
    • Erlang
    • Weibull
    • Rayleigh
    • Lognormal
    • Pareto
    • Inverse Gamma

    • Beta
    • Power
    • Beta Prime (Inv. Beta)
    • Triangular

    • Normal (area)
    • Logistic
    • Laplace
    • Cauchy (standard)
    • Cauchy (location-scale)
    • Gumbel

    • Normal RNG
    • ML Fitting
    • Tukey Lambda PPCC
    • Box-Cox Normality Plot
    • Sample Correlation r

    • Empirical Tests
  • Hypotheses
    • Theoretical Aspects of Hypothesis Testing
    • Bayesian Inference
    • Minimum Sample Size

    • Empirical Tests
    • Multivariate (pair-wise) Testing
  • Models
    • Manual Model Building
  • Time Series
    • Time Series Plot
    • Decomposition
    • Exponential Smoothing

    • Blocked Bootstrap Plot
    • Mean Plot
    • (P)ACF
    • VRM
    • Standard Deviation-Mean Plot
    • Spectral Analysis
    • ARIMA

    • Cross Correlation Function
    • Granger Causality
  1. Descriptive Statistics & Exploratory Data Analysis
  2. 72  Kernel Density Estimation
  • Preface
  • Getting Started
    • 1  Introduction
    • 2  Why Do We Need Innovative Technology?
    • 3  Basic Definitions
    • 4  The Big Picture: Why We Analyze Data
  • Introduction to Probability
    • 5  Definitions of Probability
    • 6  Jeffreys’ axiom system
    • 7  Bayes’ Theorem
    • 8  Sensitivity and Specificity
    • 9  Naive Bayes Classifier
    • 10  Law of Large Numbers

    • 11  Problems
  • Probability Distributions
    • 12  Bernoulli Distribution
    • 13  Binomial Distribution
    • 14  Geometric Distribution
    • 15  Negative Binomial Distribution
    • 16  Hypergeometric Distribution
    • 17  Multinomial Distribution
    • 18  Poisson Distribution

    • 19  Uniform Distribution (Rectangular Distribution)
    • 20  Normal Distribution (Gaussian Distribution)
    • 21  Gaussian Naive Bayes Classifier
    • 22  Chi Distribution
    • 23  Chi-squared Distribution (1 parameter)
    • 24  Chi-squared Distribution (2 parameters)
    • 25  Student t-Distribution
    • 26  Fisher F-Distribution
    • 27  Exponential Distribution
    • 28  Lognormal Distribution
    • 29  Gamma Distribution
    • 30  Beta Distribution
    • 31  Weibull Distribution
    • 32  Pareto Distribution
    • 33  Inverse Gamma Distribution
    • 34  Rayleigh Distribution
    • 35  Erlang Distribution
    • 36  Logistic Distribution
    • 37  Laplace Distribution
    • 38  Gumbel Distribution
    • 39  Cauchy Distribution
    • 40  Triangular Distribution
    • 41  Power Distribution
    • 42  Beta Prime Distribution
    • 43  Sample Correlation Distribution

    • 44  Problems
  • Descriptive Statistics & Exploratory Data Analysis
    • 45  Types of Data
    • 46  Datasheets

    • 47  Frequency Plot (Bar Plot)
    • 48  Frequency Table
    • 49  Contingency Table
    • 50  Binomial Classification Metrics
    • 51  Confusion Matrix
    • 52  ROC Analysis

    • 53  Stem-and-Leaf Plot
    • 54  Histogram
    • 55  Data Quality Forensics
    • 56  Quantiles
    • 57  Central Tendency
    • 58  Variability
    • 59  Skewness & Kurtosis
    • 60  Concentration
    • 61  Notched Boxplot
    • 62  Scatterplot
    • 63  Pearson Correlation
    • 64  Rank Correlation
    • 65  Partial Pearson Correlation
    • 66  Simple Linear Regression
    • 67  Moments
    • 68  Quantile-Quantile Plot (QQ Plot)
    • 69  Normal Probability Plot
    • 70  Probability Plot Correlation Coefficient Plot (PPCC Plot)
    • 71  Box-Cox Normality Plot
    • 72  Kernel Density Estimation
    • 73  Bivariate Kernel Density Plot
    • 74  Conditional EDA: Panel Diagnostics
    • 75  Bootstrap Plot (Central Tendency)
    • 76  Survey Scores Rank Order Comparison
    • 77  Cronbach Alpha

    • 78  Equi-distant Time Series
    • 79  Time Series Plot (Run Sequence Plot)
    • 80  Mean Plot
    • 81  Blocked Bootstrap Plot (Central Tendency)
    • 82  Standard Deviation-Mean Plot
    • 83  Variance Reduction Matrix
    • 84  (Partial) Autocorrelation Function
    • 85  Periodogram & Cumulative Periodogram

    • 86  Problems
  • Hypothesis Testing
    • 87  Normal Distributions revisited
    • 88  The Population
    • 89  The Sample
    • 90  The One-Sided Hypothesis Test
    • 91  The Two-Sided Hypothesis Test
    • 92  When to use a one-sided or two-sided test?
    • 93  What if \(\sigma\) is unknown?
    • 94  The Central Limit Theorem (revisited)
    • 95  Statistical Test of the Population Mean with known Variance
    • 96  Statistical Test of the Population Mean with unknown Variance
    • 97  Statistical Test of the Variance
    • 98  Statistical Test of the Population Proportion
    • 99  Statistical Test of the Standard Deviation \(\sigma\)
    • 100  Statistical Test of the difference between Means -- Independent/Unpaired Samples
    • 101  Statistical Test of the difference between Means -- Dependent/Paired Samples
    • 102  Statistical Test of the difference between Variances -- Independent/Unpaired Samples

    • 103  Hypothesis Testing for Research Purposes
    • 104  Decision Thresholds, Alpha, and Confidence Levels
    • 105  Bayesian Inference for Decision-Making
    • 106  One Sample t-Test
    • 107  Skewness & Kurtosis Tests
    • 108  Paired Two Sample t-Test
    • 109  Wilcoxon Signed-Rank Test
    • 110  Unpaired Two Sample t-Test
    • 111  Unpaired Two Sample Welch Test
    • 112  Two One-Sided Tests (TOST) for Equivalence
    • 113  Mann-Whitney U test (Wilcoxon Rank-Sum Test)
    • 114  Bayesian Two Sample Test
    • 115  Median Test based on Notched Boxplots
    • 116  Chi-Squared Tests for Count Data
    • 117  Kolmogorov-Smirnov Test
    • 118  One Way Analysis of Variance (1-way ANOVA)
    • 119  Kruskal-Wallis Test
    • 120  Two Way Analysis of Variance (2-way ANOVA)
    • 121  Repeated Measures ANOVA
    • 122  Friedman Test
    • 123  Testing Correlations
    • 124  A Note on Causality

    • 125  Problems
  • Regression Models
    • 126  Simple Linear Regression Model (SLRM)
    • 127  Multiple Linear Regression Model (MLRM)
    • 128  Logistic Regression
    • 129  Generalized Linear Models
    • 130  Multinomial and Ordinal Logistic Regression
    • 131  Cox Proportional Hazards Regression
    • 132  Conditional Inference Trees
    • 133  Leaf Diagnostics for Conditional Inference Trees
    • 134  Hypothesis Testing with Linear Regression Models (from a Practical Point of View)

    • 135  Problems
  • Introduction to Time Series Analysis
    • 136  Case: the Market of Health and Personal Care Products
    • 137  Decomposition of Time Series
    • 138  Ad hoc Forecasting of Time Series
  • Box-Jenkins Analysis
    • 139  Introduction to Box-Jenkins Analysis
    • 140  Theoretical Concepts
    • 141  Stationarity
    • 142  Identifying ARMA parameters
    • 143  Estimating ARMA Parameters and Residual Diagnostics
    • 144  Forecasting with ARIMA models
    • 145  Intervention Analysis
    • 146  Cross-Correlation Function
    • 147  Transfer Function Noise Models
    • 148  General-to-Specific Modeling
  • References
  • Appendices
    • Appendices
    • A  Method Selection Guide
    • B  Presentations and Teaching Materials
    • C  R Language Concepts for Statistical Computing
    • D  Matrix Algebra
    • E  Standard Normal Table (Gaussian Table)
    • F  Critical values of Student’s \(t\) distribution with \(\nu\) degrees of freedom
    • G  Upper-tail critical values of the \(\chi^2\)-distribution with \(\nu\) degrees of freedom
    • H  Lower-tail critical values of the \(\chi^2\)-distribution with \(\nu\) degrees of freedom

Table of contents

  • 72.1 General Definition
    • 72.1.1 Horizontal axis of the Kernel Density Plot
    • 72.1.2 Vertical axis of the Kernel Density Plot
  • 72.2 Evaluation Distance
    • 72.2.1 Definition
  • 72.3 Local Density
    • 72.3.1 Definition
  • 72.4 Rectangular Kernel
    • 72.4.1 Definition
  • 72.5 Triangular Kernel
    • 72.5.1 Definition
  • 72.6 Gaussian Kernel
    • 72.6.1 Definition
  • 72.7 Epanechnikov Kernel (Epanechnikov 1969)
    • 72.7.1 Definition
  • 72.8 R Module
    • 72.8.1 Public website
    • 72.8.2 RFC
  • 72.9 Purpose
  • 72.10 Bandwidth Selection
  • 72.11 Pros & Cons
    • 72.11.1 Pros
    • 72.11.2 Cons
  • 72.12 Example
  • 72.13 Task
DRAFT This draft is under development — DO NOT CITE OR SHARE.
  1. Descriptive Statistics & Exploratory Data Analysis
  2. 72  Kernel Density Estimation

72  Kernel Density Estimation

72.1 General Definition

Kernel Density Estimation (Rosenblatt 1956; Parzen 1962) is a non-parametric method for estimating the probability density function of a random variable. If \((x_1, x_2, …, x_n)\) is an independently and identically distributed sample from any density function \(f\) then the Kernel Density Estimator is

\[ \hat{f}_h(x) = \frac{1}{n} \sum_{i=1}^{n} K_h \left( x - x_i \right) = \frac{1}{n h} \sum_{i=1}^{n} K \left( \frac{x - x_i}{h} \right) \]

where \(K_h()\) is the Kernel function with bandwidth \(h > 0\). The function \(K_h(z) \geq 0\) and has a unit integral \(\left( \int_\mathbb{R} K_h(z)\text{d}z = 1 \right)\) and a mean of 0. In other words, each sample point \(x_i\) is replaced by a Kernel function and the estimated Kernel Density is equal to the sum of all the Kernel functions.

72.1.1 Horizontal axis of the Kernel Density Plot

The horizontal axis represents the values of the variable under investigation.

72.1.2 Vertical axis of the Kernel Density Plot

The vertical axis represents the estimated density.

72.2 Evaluation Distance

72.2.1 Definition

\[ z_{ij} = \frac{1}{h} \left( v_j - x_i \right) \]

This is the distance of observation \(x_i\) from the point \(v_j\) at which the density will be evaluated.

72.3 Local Density

72.3.1 Definition

\[ \hat{f}\left( v_j \right) = \frac{1}{nh} \sum_{i=1}^{n} K \left[ z_{ij} \right] \]

for \(j=1, 2, …, m\) where

  • \(n\) is the number of observations in the sample
  • \(m\) is the number of equally spaced evaluation points
  • \(h\) is the bandwidth of the sliding window
  • \(z_{ij}\) is the evaluation distance
  • \(K\) is the weight function or Kernel

72.4 Rectangular Kernel

72.4.1 Definition

\[ \begin{aligned}\left| z_{ij} \right| \leq 1 &\Rightarrow K_{h,R} \left[ z_{ij} \right] = 0.5 \\\left| z_{ij} \right| > 1 &\Rightarrow K_{h,R} \left[ z_{ij} \right] = 0\end{aligned} \]

where

\[ z_{ij} = \frac{1}{h} \left( v_j - x_i \right) \]

and \(h\) is the bandwidth of the sliding window.

72.5 Triangular Kernel

72.5.1 Definition

\[ \begin{aligned}\left| z_{ij} \right| \leq 1 &\Rightarrow K_{h,T} \left[ z_{ij} \right] = 1 - \left| z_{ij} \right| \\\left| z_{ij} \right| > 1 &\Rightarrow K_{h,T} \left[ z_{ij} \right] = 0\end{aligned} \]

where

\[ z_{ij} = \frac{1}{h} \left( v_j - x_i \right) \]

and \(h\) is the bandwidth of the sliding window.

72.6 Gaussian Kernel

72.6.1 Definition

\[ K_{h,G} \left[ z_{ij} \right] = \frac{1}{\sqrt{2 \pi}} e^{-\frac{z_{ij}^2}{2} } \]

where

\[ z_{ij} = \frac{1}{h} \left( v_j - x_i \right) \]

and \(h\) is the bandwidth of the sliding window.

72.7 Epanechnikov Kernel (Epanechnikov 1969)

72.7.1 Definition

\[ \begin{aligned}\left| z_{ij} \right| \leq \sqrt{5} &\Rightarrow K_{h,E} \left[ z_{ij} \right] = \frac{3}{4 \sqrt{5}} \left( 1 - \frac{z_{ij}^2}{5} \right) \\\left| z_{ij} \right| > \sqrt{5} &\Rightarrow K_{h,E} \left[ z_{ij} \right] = 0\end{aligned} \]

where

\[ z_{ij} = \frac{1}{h} \left( v_j - x_i \right) \]

and \(h\) is the bandwidth of the sliding window.

72.8 R Module

72.8.1 Public website

The Kernel Density Plot is available on the public website:

  • https://compute.wessa.net/rwasp_density.wasp

72.8.2 RFC

The Kernel Density Plot is also available in RFC under the “Descriptive / Kernel Density Estimation”.

To compute the Kernel Density Plot on your local machine, the following script can be used in the R console:

x <- runif(400)
par1 = 0
par2 = 'no'
par3 = 512
ylab = 'Density'
xlab = 'Value'
if (par1 == 0) bw <- 'nrd0'
plot(density(x, bw=bw, kernel='gaussian', na.rm=TRUE), main='Gaussian Kernel', xlab=xlab, ylab=ylab)
grid()

plot(density(x, bw=bw, kernel='epanechnikov', na.rm=TRUE), main='Epanechnikov Kernel', xlab=xlab, ylab=ylab)
grid()

plot(density(x, bw=bw, kernel='rectangular', na.rm=TRUE), main='Rectangular Kernel', xlab=xlab, ylab=ylab)
grid()

plot(density(x, bw=bw, kernel='triangular', na.rm=TRUE), main='Triangular Kernel', xlab=xlab, ylab=ylab)
grid()

plot(density(x, bw=bw, kernel='biweight', na.rm=TRUE), main='Biweight Kernel', xlab=xlab, ylab=ylab)
grid()

plot(density(x, bw=bw, kernel='cosine', na.rm=TRUE), main='Cosine Kernel', xlab=xlab, ylab=ylab)
grid()

plot(density(x, bw=bw, kernel='optcosine', na.rm=TRUE), main='Optcosine Kernel', xlab=xlab, ylab=ylab)
grid()

To compute the Kernel Density Plot, the R code uses the density function with a parameter that defines the bandwidth and another parameter for the kernel.

72.9 Purpose

The Kernel Density Plot is used to visualize the empirical density of the variable under investigation. Sometimes the Kernel Densities are used to transform the data before computing some statistic which is used in subsequent analysis. The transformation which is induced can be interpreted as having a smoothing effect.

72.10 Bandwidth Selection

The bandwidth \(h\) controls the smoothness of the estimated density:

  • small \(h\): more detail, but noisier estimates (higher variance)
  • large \(h\): smoother estimates, but potentially oversmoothed (higher bias)

In practice, software often uses a default rule such as Silverman’s rule of thumb (Silverman 1986) or similar plug-in rules. These defaults are usually reasonable as a starting point, but it is good practice to inspect how conclusions change under slightly smaller and larger bandwidths.

72.11 Pros & Cons

72.11.1 Pros

The Kernel Density Plot has the following advantages:

  • Unlike the Histogram, it does not require to specify the number of bins.
  • It is easily interpreted and provides a lot of (detailed) information about the empirical density function.

72.11.2 Cons

The Kernel Density Plot has the following disadvantages:

  • It requires a bandwidth parameter to be specified. In most cases, however, the software will use a fairly appropriate bandwidth.
  • Not all software packages allow the computation of the Kernel Density Plot.

72.12 Example

Interactive Shiny app (click to load).
Open in new tab

The analysis shows the Gaussian Kernel Density Plot for the monthly marriages time series. It can be concluded that the time series exhibits a “camel shape” which indicates a bimodal density (there are two local maxima). The left hump of the camel shape is higher than the right one -- this implies that the left hump is displayed in the Table as a “global” maximum.

72.13 Task

Try to explain why the marriages time series is bimodal. Also, compare this result with the Kernel Density Plot for the monthly divorces time series (same country, same period). Why do both time series seem to have different distributions?

Epanechnikov, V. A. 1969. “Non-Parametric Estimation of a Multivariate Probability Density.” Theory of Probability and Its Applications 14 (1): 153–58. https://doi.org/10.1137/1114019.
Parzen, Emanuel. 1962. “On Estimation of a Probability Density Function and Mode.” The Annals of Mathematical Statistics 33 (3): 1065–76. https://doi.org/10.1214/aoms/1177704472.
Rosenblatt, Murray. 1956. “Remarks on Some Nonparametric Estimates of a Density Function.” The Annals of Mathematical Statistics 27 (3): 832–37. https://doi.org/10.1214/aoms/1177728190.
Silverman, B. W. 1986. Density Estimation for Statistics and Data Analysis. London: Chapman; Hall.
71  Box-Cox Normality Plot
73  Bivariate Kernel Density Plot

© 2026 Patrick Wessa. Provided as-is, without warranty.

Feedback: e-mail | Anonymous contributions: click to copy (Sats) | click to copy (XMR)

Cookie Preferences