The UNIVARIATE Procedure

Kernel Density Estimates

You can use the KERNEL option to superimpose kernel density estimates on histograms. Smoothing the data distribution with a kernel density estimate can be more effective than using a histogram to identify features that might be obscured by the choice of histogram bins or sampling variation. A kernel density estimate can also be more effective than a parametric curve fit when the process distribution is multi-modal. See Example 3.23.

The general form of the kernel density estimator is

ModifyingAbove f With caret Subscript lamda Baseline left-parenthesis x right-parenthesis equals StartFraction h v Over n lamda EndFraction sigma-summation Underscript i equals 1 Overscript n Endscripts upper K 0 left-parenthesis StartFraction x minus x Subscript i Baseline Over lamda EndFraction right-parenthesis

where

  • upper K 0 left-parenthesis dot right-parenthesis is the kernel function

  • lamda is the bandwidth

  • n is the sample size

  • x Subscript i is the ith observation

  • v equals vertical scaling factor

and

v equals StartLayout Enlarged left-brace 1st Row 1st Column n 2nd Column for VSCALE equals COUNT 2nd Row 1st Column 100 2nd Column for VSCALE equals PERCENT 3rd Row 1st Column 1 2nd Column for VSCALE equals PROPORTION EndLayout

The KERNEL option provides three kernel functions (upper K 0): normal, quadratic, and triangular. You can specify the function with the K= kernel-option in parentheses after the KERNEL option. Values for the K= option are NORMAL, QUADRATIC, and TRIANGULAR (with aliases of N, Q, and T, respectively). By default, a normal kernel is used. The formulas for the kernel functions are

StartLayout 1st Row 1st Column Normal 2nd Column upper K 0 left-parenthesis t right-parenthesis equals StartFraction 1 Over StartRoot 2 pi EndRoot EndFraction exp left-parenthesis minus one-half t squared right-parenthesis 3rd Column for negative normal infinity less-than t less-than normal infinity 2nd Row 1st Column Quadratic 2nd Column upper K 0 left-parenthesis t right-parenthesis equals three-fourths left-parenthesis 1 minus t squared right-parenthesis 3rd Column for StartAbsoluteValue t EndAbsoluteValue less-than-or-equal-to 1 3rd Row 1st Column Triangular 2nd Column upper K 0 left-parenthesis t right-parenthesis equals 1 minus StartAbsoluteValue t EndAbsoluteValue 3rd Column for StartAbsoluteValue t EndAbsoluteValue less-than-or-equal-to 1 EndLayout

The value of lamda, referred to as the bandwidth parameter, determines the degree of smoothness in the estimated density function. You specify lamda indirectly by specifying a standardized bandwidth c with the C= kernel-option. If Q is the interquartile range and n is the sample size, then c is related to lamda by the formula

lamda equals normal c normal upper Q normal n Superscript negative one-fifth

For a specific kernel function, the discrepancy between the density estimator ModifyingAbove f With caret Subscript lamda Baseline left-parenthesis x right-parenthesis and the true density f left-parenthesis x right-parenthesis is measured by the mean integrated square error (MISE):

MISE left-parenthesis lamda right-parenthesis equals integral Underscript x Endscripts StartSet upper E left-parenthesis ModifyingAbove f With caret Subscript lamda Baseline left-parenthesis x right-parenthesis right-parenthesis minus f left-parenthesis x right-parenthesis EndSet squared d x plus integral Underscript x Endscripts normal v normal a normal r left-parenthesis ModifyingAbove f With caret Subscript lamda Baseline left-parenthesis x right-parenthesis right-parenthesis d x

The MISE is the sum of the integrated squared bias and the variance. An approximate mean integrated square error (AMISE) is:

AMISE left-parenthesis lamda right-parenthesis equals one-fourth lamda Superscript 4 Baseline left-parenthesis integral Underscript t Endscripts t squared upper K left-parenthesis t right-parenthesis d t right-parenthesis squared integral Underscript x Endscripts left-parenthesis f double-prime left-parenthesis x right-parenthesis right-parenthesis squared d x plus StartFraction 1 Over n lamda EndFraction integral Underscript t Endscripts upper K left-parenthesis t right-parenthesis squared d t

A bandwidth that minimizes AMISE can be derived by treating f left-parenthesis x right-parenthesis as the normal density that has parameters mu and sigma estimated by the sample mean and standard deviation. If you do not specify a bandwidth parameter or if you specify C=MISE, the bandwidth that minimizes AMISE is used. The value of AMISE can be used to compare different density estimates. You can also specify C=SJPI to select the bandwidth by using a plug-in formula of Sheather and Jones (Jones, Marron, and Sheather 1996). For each estimate, the bandwidth parameter c, the kernel function type, and the value of AMISE are reported in the SAS log.

The general kernel density estimates assume that the domain of the density to estimate can take on all values on a real line. However, sometimes the domain of a density is an interval bounded on one or both sides. For example, if a variable Y is a measurement of only positive values, then the kernel density curve should be bounded so that is zero for negative Y values. You can use the LOWER= and UPPER= kernel-options to specify the bounds.

The UNIVARIATE procedure uses a reflection technique to create the bounded kernel density curve, as described in Silverman (1986, pp. 30-31). It adds the reflections of the kernel density that are outside the boundary to the bounded kernel estimates. The general form of the bounded kernel density estimator is computed by replacing upper K 0 left-parenthesis StartFraction x minus x Subscript i Baseline Over lamda EndFraction right-parenthesis in the original equation with

StartSet upper K 0 left-parenthesis StartFraction x minus x Subscript i Baseline Over lamda EndFraction right-parenthesis plus upper K 0 left-parenthesis StartFraction left-parenthesis x minus x Subscript l Baseline right-parenthesis plus left-parenthesis x Subscript i Baseline minus x Subscript l Baseline right-parenthesis Over lamda EndFraction right-parenthesis plus upper K 0 left-parenthesis StartFraction left-parenthesis x Subscript u Baseline minus x right-parenthesis plus left-parenthesis x Subscript u Baseline minus x Subscript i Baseline right-parenthesis Over lamda EndFraction right-parenthesis EndSet

where x Subscript l is the lower bound and x Subscript u is the upper bound.

Without a lower bound, x Subscript l Baseline equals negative normal infinity and upper K 0 left-parenthesis StartFraction left-parenthesis x minus x Subscript l Baseline right-parenthesis plus left-parenthesis x Subscript i Baseline minus x Subscript l Baseline right-parenthesis Over lamda EndFraction right-parenthesis equals 0. Similarly, without an upper bound, x Subscript u Baseline equals normal infinity and upper K 0 left-parenthesis StartFraction left-parenthesis x Subscript u Baseline minus x right-parenthesis plus left-parenthesis x Subscript u Baseline minus x Subscript i Baseline right-parenthesis Over lamda EndFraction right-parenthesis equals 0.

When C=MISE is used with a bounded kernel density, the UNIVARIATE procedure uses a bandwidth that minimizes the AMISE for its corresponding unbounded kernel.

Last updated: April 10, 2023