Computes the standard error of the mean (i.e., standard deviation divided by the square root of the sample size).
Details
The standard error of the value in vector x
is simply the standard deviation of x
divided by the square root of the number of valid items in x
Author
Derek H. Ogle, DerekOgle51@gmail.com
Examples
# example vector
x <- 1:20
se(x)
#> [1] 1.322876
sd(x)/sqrt(length(x)) ## matches
#> [1] 1.322876
# all return NA if missing values are not removed
x2 <- c(x,NA)
sd(x2)/sqrt(length(x2))
#> [1] NA
# Better if missing values are removed
se(x2) ## Default behavior
#> [1] 1.322876
sd(x2,na.rm=TRUE)/sqrt(length(x2[complete.cases(x2)])) ## Matches
#> [1] 1.322876
se(x2,na.rm=FALSE) ## Result from not removing NAs
#> [1] NA