Content deleted Content added
m Journal cites, using AWB (11335) |
No edit summary |
||
Line 120:
</source>
==Density estimation in R with a diagonal bandwidth matrix==▼
==Density estimation 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.]]
Line 194 ⟶ 164:
contour3(X,Y,density,50), hold on
plot(data(:,1),data(:,2),'r.','MarkerSize',5)
▲</source>
▲==Density estimation in R with a diagonal bandwidth matrix==
▲{{howto|section|date=July 2015}}
▲[[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>
|