trimmed_mean {r2spss} | R Documentation |
Trimmed mean
Description
Compute the trimmed mean. This function differs from the implementation of
the trimmed mean in the base R function mean
in the following
ways. While mean
always rounds down the number of observations to
be trimmed, this function rounds to the nearest integer. In addition,
mean
implements proper NA
handling, whereas this function
assumes that there are no missing values and may fail in their presence.
Usage
trimmed_mean(x, trim = 0.05)
Arguments
x |
a numeric vector. |
trim |
numeric; the fraction of observations to be trimmed from each
tail of |
Details
The main purpose of this function is to reproduce SPSS results for Levene's
test on homogeneity of the variances based on the trimmed mean (see
ANOVA
), which are slightly too far off when using the base
R function mean
. Rounding the number of observations to be
trimmed to the nearest integer brings the results closer to those of SPSS,
but they are still not identical.
Value
The trimmed mean of the values in x
as a single numeric value.
Author(s)
Andreas Alfons
See Also
Examples
x <- c(0:10, 50)
# trimmed_mean() rounds number of observations
# to be trimmed to the nearest integer
trimmed_mean(x, trim = 0.05)
# base R function mean() rounds down number of
# observations to be trimmed
mean(x, trim = 0.05)
mean(x)