trimmed_mean | R Documentation |
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.
trimmed_mean(x, trim = 0.05)
x |
a numeric vector. |
trim |
numeric; the fraction of observations to be trimmed from each
tail of |
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.
The trimmed mean of the values in x
as a single numeric value.
Andreas Alfons
mean
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.