+2 votes
in Programming Languages by (29.7k points)
Is there any function in R to compute the standard error of the mean (SEM)?

1 Answer

+1 vote
by (51.1k points)

You can use std.error() function of plotrix library or se() function of sciplot library to calculate the standard error of the mean in R.

Here is an example:

> a<-runif(20)
> a
 [1] 0.77540313 0.22338489 0.93450655 0.42343861 0.84989759 0.06896429 0.28866681 0.79730126 0.71743547 0.22640911 0.69567960 0.68597593 0.04677569 0.90157480 0.57804623 0.21837233 0.33654928
[18] 0.11710434 0.64092480 0.28355924


> library(plotrix)
> std.error(a)
[1] 0.0663643


> library(sciplot)
> se(a)
[1] 0.0663643

If you do not want to use any of these libraries. You can calculate the SEM using the following formula:

SEM = standard deviation/sqrt(length(vector))

Here is an example:

> sd(a)/sqrt(length(a))
[1] 0.0663643


...