Multivariate kernel density estimation: Difference between revisions

Content deleted Content added
CanaDanjl (talk | contribs)
m syntax highlighting
Line 114:
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 region which contains the respective 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.
 
<presource lang="rsplus" style="overflow:auto;">
library(ks)
data(faithful)
Line 121:
plot(fhat, display="filled.contour2")
points(faithful, cex=0.5, pch=16)
</presource>
 
==Density estimation in R with a diagonal bandwidth matrix==
Line 136:
prompt by using copy and paste.
 
<presource lang="rsplus" style="overflow:auto;">
library(np)
library(datasets)
Line 142:
f <- npudens(~eruptions+waiting,data=faithful)
plot(f,view="fixed",neval=100,phi=30,main="",xtrim=-0.2)
</presource>
 
Computing kernel density estimates with diagonal bandwidth selectors is also available in the <tt>ks</tt> library, using the <tt>Hpi.diag()</tt> function. To produce a 3D plot similar to that from <tt>npudens()</tt>, the option <tt>display="persp"<tt> is added.
 
<presource lang="rsplus" style="overflow:auto;">
library(ks)
data(faithful)
Line 151 ⟶ 152:
fhat <- kde(x=faithful, H=H)
plot(fhat, display="persp")
</presource>
 
==Density estimation in Matlab with a diagonal bandwidth matrix==
Line 185 ⟶ 186:
in the current directory.
 
<presource lang="matlab" style="overflow:auto;">
clear all
% generate synthetic data
Line 195 ⟶ 196:
contour3(X,Y,density,50), hold on
plot(data(:,1),data(:,2),'r.','MarkerSize',5)
</presource>
 
===Alternative optimality criteria===