In R, how to find the standard error of the mean?

Is there any command to look for the standard error of the mean in R?

+68
r statistics
Apr 20 '10 at 15:49
source share
8 answers

There the plotrix package has a built-in function for this: std.error

+27
Apr 20 '10 at 15:56
source share

The standard error is the standard deviation divided by the square root of the sample size. This way you can easily make your own function:

> std <- function(x) sd(x)/sqrt(length(x)) > std(c(1,2,3,4)) [1] 0.6454972 
+131
Apr 20 '10 at 16:18
source share

It is probably more efficient to use var ... since you actually sqrt twice in your code, once to get sd (the code for sd is in r and displayed by typing "sd") ...

 se <- function(x) sqrt(var(x)/length(x)) 
+79
Apr 20 '10 at 19:03
source share

John's version of the answer above that removes annoying NA:

 stderr <- function(x, na.rm=FALSE) { if (na.rm) x <- na.omit(x) sqrt(var(x)/length(x)) } 
+54
Aug 28 '11 at 9:27 a.m.
source share

The packet multiplier has a built-in se (x) function

+4
Feb 06 '13 at 5:07
source share

more generally, for standard errors for any other parameter, you can use the boot package to simulate the boot (or write them yourself)

0
Apr 21 '10 at 6:51
source share
0
Apr 18 '19 at 18:46
source share
 y <- mean(x, na.rm=TRUE) 

sd(y) for standard deviation var(y) for variance.

Both pins use n-1 in the denominator, so they are based on sample data.

-eleven
Nov 01 '13 at 17:31
source share



All Articles