Comparison of univariate density estimates

Description Usage Arguments Details Value Side Effects References See Also Examples


This function allows a set of univariate density estimates to be compared, both graphically and formally in a permutation test of equality.


1, group, h, model = "none",  ...)



a vector of data.


a vector of group labels. If this is not already a factor it will be converted to a factor.


the smoothing parameter to be used in the construction of each density estimate. Notice that the same smoothing parameter is used for each group. If this value is omitted, the mean of the normal optimal values for the different groups is used.


the default value is "none" which restricts comparison to plotting only. The alternative value "equal" can produce a bootstrap hypothesis test of equality and the display of an appropriate reference band.


other optional parameters are passed to the sm.options function, through a mechanism which limits their effect only to this call of the function. Relevant parameters for this function are: method, df, band, test, nboot, plus those controlling graphical display (unless display = "none" is set) such as col,, lty and lwd; see the documentation of sm.options for their description. The parameter nboot controls the number of permutations used in the permutation test.


For a general description of the methods involved, see Section 6.2 of the reference below.

The colours and linetypes of the density estimates are set by col and lty which can be passed as additional arguments. By default these are set to 1 + 1:ngroup, where ngroup is the number of groups represented in the group variable.


A list is returned containing:


a matrix whose rows contain the estimates for each group.


the grid of common evaluation points for the estimates.


the common smoothing parameter used in the construction of the estimates.


the levels of the group factor.

col, lty, lwd

plotting details which can be useful in constructing a legend for the plot; see the examples below.

When "model" is set to "equal", the output list also contains the p-value (p) of the test.

When band = TRUE, and there are only two groups to compare, the output list also contains the upper (upper) and lower (lower) edges of the reference band for equality.

Side Effects

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


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

sm.density, sm.ancova, sm.options


y <- rnorm(100)
g <- rep(1:2, rep(50,2)), g)

comp <-, g, model = "equal")
legend("topleft", comp$levels, col = comp$col, lty = comp$lty, lwd = comp$lwd)

sm documentation built on Sept. 13, 2021, 5:07 p.m.

Related to in sm...