# How to Calculate the Standard Error of the Mean in R

Standard Error of the Mean in R, A method for calculating the standard deviation of a sampling distribution is the standard error of the mean. The standard deviation of the mean (SEM) is another name for it.

In another way, the standard error of the mean is a metric for determining how widely values in a dataset are spread out.

The ratio of the standard deviation to the root of the sample size is the formula for the standard error of the mean.

SD/sqrt(N) = SEM

The standard deviation is SD, and the number of observations is N.

In this lesson, you’ll learn how to compute the standard error of a dataset in R using two different methods. It’s worth noting that both strategies get identical outcomes.

## Method 1: Plotrix Library

The first method is to utilize the Plotrix library’s built-in std.error() function to determine the standard error of the mean.

The code below demonstrates how to use this function:

First, we need to load plotrix library in the R console

library(plotrix)

Now we can create dummy data set for the SEM calculation

data <- c(5,8,9,12,13)

Now we can calculate the standard error of the mean

std.error(data)

[1] 1.43527

It turns out that the standard error of the mean is 1.43527.

## Method 2: Own Function

Another option is to create your own function to determine the standard error of the mean for a dataset.

The code below demonstrates how to do so:

First, we need to create a standard error function

stderror <- function(x) sd(x)/sqrt(length(x))

Now we can use the same data set for illustration.

data <- c(5,8,9,12,13)

Yes, it’s ready to calculate the standard error of the mean

stderror(data)

1.43527

The standard error of the mean comes out to be 1.43527 once more.

Okay, now that we have the standard error of the mean, how do we interpret it?

## Interpretation

The standard error of the mean (SEM) is a measure of how widely values are distributed around the mean. When analyzing the standard error of the mean, keep the following three points in mind:

1. In a dataset, the bigger the standard error of the mean, the more values in the dataset are spread out around the mean.

2. Check any outliers that exist in the data set.

3. The standard error of the mean tends to decrease as the sample size grows.

Let’s take an example the above example the first value is 5, suppose if we entered wrongly into 50.

data <- c(50,8,9,12,13)

Let’s calculate the standard error of the mean

stderror(data)

7.953616

The standard error increases from 1.43527 to 7.953616. When compared to the previous dataset, this indicates that the values in this dataset are more spread out around the mean.

Consider the standard error of the mean for the following two datasets to see what happens in our third point.

set1 <- c(5,8,9,12,13,6,8,9,11,7,8,7,2,3,6) stderror(set1)

0.7855844

Let’s duplicate the same set of values then see the SEM.

set2 <- c(5,8,9,12,13,6,8,9,11,7,8,7,2,3,6, 5,8,9,12,13,6,8,9,11,7,8,7,2,3,6) stderror(set2)

0.5458306

The first dataset is simply repeated twice in the second dataset. As a result, the two datasets have the same mean, but the second dataset has a higher sample size, therefore the standard error is reduced.

Hope now you cleared with Standard Error of the Mean in R.

Cluster Analysis in R » Unsupervised Approach »

The formula should be SD/SQRT(N) = SEM

Thank You…It was a typo…