Skip to content

3-d kernel smooth by the "kde" function

2 messages · Gary Dong, David L Carlson

#
No you are not correct. The kde function estimates the density of 1 to 6
dimensions. To visualize, this try plotting the density of just the data
(using density() instead of kde):

plot(density(elevation$data))
rug(elevation$data)

The elevations are plotted along the x-axis and their density is plotted on
the y-axis. Where data points are close together, the plot is higher. If you
had two variables, kde2d() would plot their joint density in a 3d dimension
and you would view them with contour() or persp(). With three dimensions of
data, the kde() function plots the joint density of the three variables in a
fourth dimension which is represented in the 3d plot by shading to indicate
areas of greater point density. 

To smooth the z variable (elevation) so that you can interpolate values in
between your observations you have several options:

1. Polynomial regression using x and y to predict z, creating a regular grid
of x and y to predict z and use that with contour to show the results.

2. Use loess() to fit a smooth surface using x and y to predict z.

3. Use kriging (e.g. krig.conv in package geoR).

For more information look at the Spatial Task View:

http://cran.r-project.org/web/views/Spatial.html

The geoR package has kriging. See

http://www.leg.ufpr.br/geoR/

for examples.

Also look at the StatDA package, particularly the Vignette for that package,
"Tutorial to the package StatDA" which discusses smoothing techniques
and kriging:

http://cran.r-project.org/web/packages/StatDA/vignettes/StatDA.pdf

----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352