Multivariate kernel density estimation: Difference between revisions

Content deleted Content added
Undid revision 676031420 by 129.94.176.178 (talk)
Removed duplication of the old diagonal bandwidth example
Line 102:
It has been established that the plug-in and smoothed cross validation selectors (given a single pilot bandwidth '''G''') both converge at a relative rate of ''O<sub>p</sub>(n<sup>−2/(d+6)</sup>)'' <ref name="DH2005"/><ref>{{Cite journal| doi=10.1016/j.jmva.2004.04.004 | author1=Duong, T. | author2=Hazelton, M.L. | title=Convergence rates for unconstrained bandwidth matrix selectors in multivariate kernel density estimation | journal=Journal of Multivariate Analysis | year=2005 | volume=93 | pages=417–433}}</ref> i.e., both these data-based selectors are consistent estimators.
 
==Density estimation in R with a full bandwidth matrix==
[[File:Old Faithful Geyser KDE with plugin bandwidth.png|thumb|250px|alt=Old Faithful Geyser data kernel density estimate with plug-in bandwidth matrix.|Old Faithful Geyser data kernel density estimate with plug-in bandwidth matrix.]]
 
Line 120:
</source>
 
==Density estimation in R with a diagonal bandwidth matrix==
 
==Density estimation in R with a diagonal bandwidth matrix==
[[File:Old faithful pdf.png|thumb|250px|alt=Old Faithful Geyser data kernel density estimate with diagonal bandwidth matrix.|Old Faithful Geyser data kernel density estimate with diagonal bandwidth matrix.]]
 
This example is again based on the Old Faithful Geyser, but this time we use the [http://cran.r-project.org/web/packages/np/index.html R np package] that employs automatic (data-driven) bandwidth selection for a diagonal bandwidth matrix; see the [http://cran.r-project.org/web/packages/np/vignettes/np.pdf np vignette] for an introduction to the np package. The figure below shows the joint density estimate using a second order Gaussian kernel.
 
'''R script for the example'''
 
The following commands of the R programming language use the
{{mono|npudens()}} function to deliver optimal smoothing and to create
the figure given above. These commands can be entered at the command
prompt by using copy and paste.
 
<source lang="rsplus" style="overflow:auto;">
library(np)
library(datasets)
data(faithful)
f <- npudens(~eruptions+waiting,data=faithful)
plot(f,view="fixed",neval=100,phi=30,main="",xtrim=-0.2)
</source>
 
Computing kernel density estimates with diagonal bandwidth selectors is also available in the {{mono|ks}} library, using the {{mono|Hpi.diag()}} function. To produce a 3D plot similar to that from {{mono|npudens()}}, the option {{mono|display="persp"}} is added.
 
<source lang="rsplus" style="overflow:auto;">
library(ks)
data(faithful)
H <- Hpi.diag(x=faithful)
fhat <- kde(x=faithful, H=H)
plot(fhat, display="persp")
</source>
 
==Density estimation in Matlab with a diagonal bandwidth matrix==
{{howto|section|date=July 2015}}
 
[[File:Bivariate example.png|thumb|250px|alt=Kernel density estimate with diagonal bandwidth for synthetic normal mixture data. |Kernel density estimate with diagonal bandwidth for synthetic normal mixture data.]]