This function allows a set of univariate density estimates to be compared, both graphically and formally in a permutation test of equality.
sm.density.compare(x, group, h, model = "none", ...)
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.
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.
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
, 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.
a plot on the current graphical device is produced, unless
display="none"
.
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.
Bowman, A.W. and Azzalini, A. (1997). Applied Smoothing Techniques for Data Analysis: the Kernel Approach with S-Plus Illustrations. Oxford University Press, Oxford.
sm.density
, sm.ancova
, sm.options
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)
Run the code above in your browser using DataLab