Learn R Programming

sm (version 2.0-14)

sm.density: Nonparametric density estimation in one, two or three dimensions.

Description

This function creates a density estimate from data in one, two or three dimensions. In one dimension, an interactive panel can be activated to control the smoothing parameter, in two dimensions a variety of graphical displays can be selected, and in three dimensions a contour surface can be plotted. A number of other features of the construction of the estimate, and of its display, can be controlled.

Usage

sm.density(x, h, model = "none", weights = rep(1,nobs), ...)

Arguments

x
a vector, or a matrix with two or three columns, containing the data.
h
a vector of length one, two or three, defining the smoothing parameter. A normal kernel function is used and h is its standard deviation. If this parameter is omitted, a normal optimal smoothing parameter is used.
model
This argument applies only with one-dimensional data. Its default value is "none". If it is set to "Normal" (or indeed any value other than "none") then a reference band, indicating where a density estimate is lik
weights
a vector which allows the kernel functions over the observations to take different weights when they are averaged to produce a density estimate. Use of this parameter is incompatible with binning; hence nbins must then be set to 0 or left at
...
other optional parameters are passed to the sm.options function, through a mechanism which limits their effect only to this call of the function; those relevant for this function are the following:
  • hmult
{ a factor which can

Value

  • a list containing the values of the density estimate at the evaluation points, the standard error of the estimate, the upper and lower ends of a variability band, the smoothing parameter, the smoothing parameter weights and the kernel weights. Less information is supplied when the smoothing parameter weights or kernel weights are not all 1, or when positive is set to TRUE.

Side Effects

a plot on the current graphical device is produced, unless display="none".

Details

see Chapters 1, 2 and 6 of the reference below. The code for drawing contours of a three-dimensional density estimate has been amended from an original function written by Stuart Young.

References

Bowman, A.W. and Azzalini, A. (1997). Applied Smoothing Techniques for Data Analysis: the Kernel Approach with S-Plus Illustrations. Oxford University Press, Oxford.

See Also

hnorm, hsj, hcv, nise, nmise, sm, sm.sphere, sm.regression, sm.options

Examples

Run this code
#  A one-dimensional example
y <- rnorm(50)
sm.density(y, model = "Normal")


#  A two-dimensional example
y <- cbind(rnorm(50), rnorm(50))
sm.density(y, display = "image")


#  A three-dimensional example
y <- cbind(rnorm(50), rnorm(50), rnorm(50))
sm.density(y)

Run the code above in your browser using DataLab