Skip to content
Related Articles

Related Articles

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

Improve Article
Save Article
Like Article
  • Last Updated : 19 Dec, 2021

In this article, we will discuss how to calculate the standard error of the mean in the R programming language.

StandardError Of Mean is the standard deviation divided by the square root of the sample size.

Formula:

Standard Error: (Sample Standard Deviation of Sample)/(Square Root of the sample size)

Method 1: Using the std.error() function of the Plotrix package

In this method to calculate the standard error of the mean, the user first needs to install and import the plotrix package, here the plotrix package is responsible to provide various functionalities to the user, then the user simply needs to call the std.error() function with the data passed as its parameters for which the standard error is to be calculated of the provided data in the R programming language.

Syntax to install and import the plotrix package in the R console:

install.package('plotrix')
library('plotrix')

std.error() function is used to calculate the standard error of the mean.

Syntax:

std.error(x,na.rm)

Parameters:

  • x: A vector of numerical observations.
  • na.rm: Dummy argument to match other functions.

Example: Calculate standard error of mean

R




library(plotrix)
  
# Create data
gfg <- c(1:100)
  
# calculate standard error of the mean 
std.error(gfg)

Output:

[1] 2.901149

Method 2: Using the formula

In the method, the user has to simply use the standard error of the mean formula to calculate the standard error of the mean of the given data which is the sample standard deviation of the data which will be calculated using the sd() function divided by the square root of the length of the data which will be calculating using the sqrt() and the length() function in the R programming language.

Formula:

Standard Error: (Sample Standard Deviation of Sample)/(Square Root of the sample size)

Example: Calculate standard error of mean 

R




# Create data
gfg <- c(1:100)
  
# calculate standard error of the mean 
std_error<-sd(gfg)/sqrt(length(gfg))
std_error

Output:

[1] 2.901149
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!