trimmed_mean: Trimmed mean

View source: R/trimmed_mean.R

trimmed_meanR 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 x before computing the mean (defaults to 0.05).

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

mean

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)


r2spss documentation built on May 25, 2022, 5:05 p.m.