This function calculates the standard error of the mean for a set of numeric values.

sem(x, na.rm = TRUE)

Arguments

x

A numeric vector.

na.rm

Logical; if TRUE, removes NA values first.

Value

The standard error of the mean.

Details

Given the standard deviation \(s_x\) and sample size \(n\) of a sample \(x\), the standard error of the mean is:

$$ \frac{s_x}{\sqrt{n}}. $$

Examples

# Simulate 100 values from a normal distribution
set.seed(2)
x <- rnorm(100)
# Standard error of the mean should be ~0.1
sem(x)
#> [1] 0.1160189