Skip to contents

Calculates the standard error of the (trimmed) mean.

Usage

meanSE(x, sd = NULL, trim = 0, na.rm = FALSE)

Arguments

x

a non-empty numeric vector of data values

sd

the standard deviation of x. If supplied, it is interpreted as the population standard deviation. If NULL (default), the sample standard deviation sd(x) is used. Cannot be combined with trim.

trim

the fraction (0 to < 0.5) of observations trimmed from each end for the trimmed mean whose standard error is wanted. Default 0.

na.rm

logical. Should missing values be removed? Defaults to FALSE.

Value

the standard error as a numeric scalar

Details

meanSE() calculates the standard error of the mean defined as: $$\frac{\sigma}{\sqrt{n}}$$ \(\sigma\) being standard deviation of x and n the length of x.

With trim > 0 the standard error of the trimmed mean meanX(x, trim = trim) is returned (Tukey & McLaughlin 1963): $$\frac{s_w}{(1 - 2\gamma)\sqrt{n}}$$ where \(s_w\) is the winsorized standard deviation sdX(x, trim = trim) and \(\gamma\) = trim. This is the standard error used by lumen::meanCI() with trim and by Wilcox (2022).

References

Tukey, J. W. and McLaughlin, D. H. (1963) Less vulnerable confidence and significance procedures for location based on a single sample: Trimming/Winsorization 1. Sankhya A, 25, 331-352.

Wilcox, R. R. (2022) Introduction to Robust Estimation and Hypothesis Testing, 5th ed. Academic Press.

See also

Examples


meanSE(Pizza$price, na.rm=TRUE)
#> [1] 0.6252242

# evaluate data.frame
sapply(Pizza[, 1:4], meanSE, na.rm=TRUE)
#>       index        date        week     weekday 
#> 10.04158022  0.26218843  0.03873807  0.05886462 

# standard error of the 20% trimmed mean
meanSE(Pizza$price, trim = 0.2, na.rm=TRUE)
#> [1] 0.6980921