Calculate Standard Error in R

  1. Use the std.error() Function to Calculate the Standard Error of Mean in R
  2. Use Your Own Function to Calculate the Standard Error of Mean in R

In the world of statistics, the standard error of mean is a very useful and important term. It tells us how the sample deviates from the actual mean, unlike standard deviation, which is a measure of the amount of dispersion in the data.

The formula for standard error of mean is the standard deviation divided by the square root of the length of the data.

It is relatively simple in R to calculate the standard error of the mean. We can either use the std.error() function provided by the plotrix package, or we can easily create a function for the same.

Use the std.error() Function to Calculate the Standard Error of Mean in R

The std.error() directly computes the Standard Error of Mean of the value passed. For example:

x <- c(5,6,8,9,7,5,7,8)
std.error(x)
[1] 0.5153882

Remember to import the plotrix package before using this function.

Use Your Own Function to Calculate the Standard Error of Mean in R

To create our own function to calculate the standard error of the mean, we simply use the sd() function to find the standard deviation of the observations and the length() function to find the total observations and putting them in the formula appropriately.

The following example shows how:

x <- c(5,6,8,9,7,5,7,8)
std_mean <- function(x) sd(x)/sqrt(length(x))
std_mean(x)
[1] 0.5153882