sm.density.compare: Comparison of univariate density estimates

Description Usage Arguments Details Value Side Effects References See Also Examples

Description

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

Usage

1
sm.density.compare(x, group, h, model = "none",  ...)

Arguments

x

a vector of data.

group

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

h

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.

model

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, col.band, 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.

Details

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.

Value

A list is returned containing:

estimate

a matrix whose rows contain the estimates for each group.

eval.points

the grid of common evaluation points for the estimates.

h

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

levels

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".

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

sm.density, sm.ancova, sm.options

Examples

1
2
3
4
5
6
y <- rnorm(100)
g <- rep(1:2, rep(50,2))
sm.density.compare(y, g)

comp <- sm.density.compare(y, 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 sm.density.compare in sm...