Multivariate kernel density estimation: Difference between revisions

Content deleted Content added
Drleft (talk | contribs)
No edit summary
Drleft (talk | contribs)
No edit summary
Line 10:
We take a illustrative synthetic [[bivariate]] data set of 50 points to illustrate the construction of histograms. This requires the choice of an anchor point (the lower left corner of the histogram grid). For the histogram on the left, we choose (-1.5, -1.5): for the one on the right, we shift the anchor point by 0.125 in both directions to (-1.625, -1.625). Both histograms have a binwidth of 0.5, so any differences are due to the change in the anchor point only. The colour coding indicates the number of data points which fall into a bin: 0=white, 1=pale yellow, 2=bright yellow, 3=orange, 4=red. The left histogram appears to indicate that the upper half has a higher density than the lower half, whereas it is the reverse is the case for the right-hand histogram, confirming that histograms are highly sensitive the placement of the anchor point.<ref>{{cite book | author=Silverman, B.W. | title=Density Estimation for Statistics and Data Analysis | publisher=Chapman & Hall/CRC | date=1986 | isbn=0412246201 | pages=7-11}}</ref>
 
[[Image:Synthetic data 2D histograms.png|center|600px500px|alt=Left. Histogram with anchor point at (-1.5, 1.5). (Right) Histogram with anchor point at (-1.625, -1.625). Both histograms have a bin width of 0.5, so differences in appearances of the two histograms are due to the placement of the anchor point.|Left. Histogram with anchor point at (-1.5, 1.5). (Right) Histogram with anchor point at (-1.625, -1.625). Both histograms have a bin width of 0.5, so differences in appearances of the two histograms are due to the placement of the anchor point.]]
 
One possible solution to this anchor point placement problem to remove the histogram binning grid completely. In the left figure below, a kernel (represented by the dashed grey lines) is centred at each of the 50 data points above. The result of summing these kernels is given on the right figure, which is a kernel density estimate. The most striking difference between kernel density estimates and histograms is that the former are easier to interpret since they do not contain artifices induced by a binning grid.
The coloured contours correspond to the smallest regions which contains that corresponding probability mass: red = 25%, orange + red = 50%, yellow + orange + red = 75%, thus indicating that a single central region contains the highest density.
 
 
[[Image:Synthetic data 2D KDE.png|center|600px500px|alt=Left. Individual kernels. Right. Kernel density estimate.|Left. Individual kernels. Right. Kernel density estimate.]]
 
 
== Definition ==
Line 82 ⟶ 84:
 
== Computer implementation==
 
[[Image:Old Faithful Geyser KDE with plugin bandwidth.png|centerthumb|300px250px|alt=Old Faith Geyser data kernel density estimate with plug0inplug-in bandwidth matrix.|Old Faith Geyser data kernel density estimate with plug-in bandwidth matrix.]]
 
The [http://cran.r-project.org/web/packages/ks/index.html ks package]<ref>{{cite journal | author1=Duong, T. | title=ks: Kernel density estimation and kernel discriminant analysis in R | journal=Journal of Statistical Software | year=2007 | volume=21(7) | url=http://www.jstatsoft.org/v21/i07}}</ref> in [[R programming language|R]] implements the plug-in and smoothed cross validation selectors (amongst others). This dataset (included in the base distribution of R) contains
272 records with two measurements each: the duration time of an eruprion (minutes) and the
Line 88 ⟶ 93:
The code fragment computes the kernel density estimate with the plug-in bandwidth matrix <math>\hat{\bold{H}}_\operatorname{PI} = \begin{bmatrix}0.052 & 0.510 \\ 0.510 & 8.882\end{bmatrix}.</math> Again, the coloured contours correspond to the smallest regions which contains that corresponding probability mass: red = 25%, orange + red = 50%, yellow + orange + red = 75%. To compute the SCV selector, <code>Hpi</code> is replaced with <code>Hscv</code>. This is not displayed here since it is mostly similar to the plug-in estimate for this example.
<pre style="overflow:auto;">
<pre>
library(ks)
data(faithful)
Line 97 ⟶ 102:
</pre>
 
 
[[Image:Old Faithful Geyser KDE with plugin bandwidth.png|center|300px|alt=Old Faith Geyser data kernel density estimate with plug0in bandwidth matrix.]]