Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The standard error (SE) of a statistic is the standard deviation of its sampling distribution or an estimate of that standard deviation. The standard error is calculated by dividing the standard deviation by the square root of the number of sample data.

The formula for calculating Standard Deviation in the Mathematics world is

standard error= standard deviation/squareroot(n)
• SE = standard error of the sample
• σ = sample standard deviation
• n = number of samples

In this tutorial, we will look at how to Calculate Standard Error in R with examples.

## How to Calculate Standard Error in R?

We can calculate Standard Error in three ways in the R language, as shown below.

### Using sd() method

The sd() method takes a numeric vector as input and computes the standard deviation.

> std <- function(x) sd(x)/sqrt(length(x))
> std(c(1,2,3,4))
[1] 0.6454972

### Using the standard error formula

We can use the standard error formula and calculate the standard error manually as shown below.

Syntax: sqrt(sum((a-mean(a))^2/(length(a)-1)))/sqrt(length(a))

where

• data is the input data
• sqrt function is to find the square root
• sum is used to find the sum of elements in the data
• mean is the function used to find the mean of the data
• length is the function used to return the length of the data
# consider a vector with 10 elements
a <- c(1,2,3,4)

# calculate standard error
print(sqrt(sum((a - mean(a)) ^ 2/(length(a) - 1)))
/sqrt(length(a)))

[1] 0.6454972

### Using std.error() method from plotrix

We can import the plotrix library and use the std.error() method to calculate the standard error.

# import plotrix package
library("plotrix")

# vector data
a <- c(1,2,3,4)

# calculate standard error using builtin function
print(std.error(a))

[1] 0.6454972