- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to find the standard error of mean in R?
The standard error of mean is the standard deviation divided by the square root of the sample size. The easiest way to find the standard error of mean is using the formula to find its value.
Example
> set.seed(1)
We will find the standard errors for a normal random variable, sequence of numbers from one to hundred, a random sample, a binomial random variable, and uniform random variable using the same formula. And at the end, I will confirm whether we used the correct method or not for all types of variables we have considered here.
> x<-rnorm(10) > x [1] -0.6264538 0.1836433 -0.8356286 1.5952808 0.3295078 -0.8204684 [7] 0.4874291 0.7383247 0.5757814 -0.3053884 > SE_x<-sd(x)/sqrt(10) > SE_x [1] 0.246843 > y<-1:100 > y [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 [19] 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 [37] 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 [55] 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 [73] 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 [91] 91 92 93 94 95 96 97 98 99 100 > SE_y<-sd(y)/sqrt(100) > SE_y [1] 2.901149 > z<-sample(1:100,20,replace=TRUE) > z [1] 73 79 85 37 89 37 34 89 44 79 33 84 35 70 74 42 38 20 28 20 > SE_z<-sd(z)/sqrt(20) > SE_z [1] 5.582161 > a<-rbinom(20,100,0.6) > a [1] 63 66 59 58 48 66 59 65 60 56 55 55 56 57 56 66 53 62 61 51 > SE_a<-sd(a)/sqrt(20) > SE_a [1] 1.141098 > b<-runif(30,2,5) > b [1] 4.928512 4.195378 3.070181 3.294421 2.444635 2.039233 4.146698 2.309553 [9] 3.338853 3.920303 4.975516 3.486781 3.453049 2.520327 4.264463 3.361686 [17] 3.533509 2.622635 2.685974 3.787136 3.724617 2.231193 2.106622 3.928386 [25] 4.785846 3.794277 3.682702 3.578083 4.955286 3.522925 > SE_b<-sd(b)/sqrt(30) > SE_b [1] 0.1552736 > c<-sample(20) > c [1] 19 4 2 16 1 12 7 9 15 10 11 18 13 3 17 8 14 20 6 5 > SE_c<-sd(c)/sqrt(20) > SE_c [1] 1.322876
If we don’t know the sample size then we can use length function as follows −
> SE_c<-sd(c)/sqrt(length(c)) > SE_c [1] 1.322876
Here, the standard error for uniform random variable and binomial random variable are not correct because their standard deviations are not calculated by sd function.
- Related Articles
- How to calculate standard error of the mean in Excel?
- C++ Program to implement standard error of mean
- How to find the mean squared error for linear model in R?
- How to find mean and standard deviation from frequency table in R?
- How to create boxplot using mean and standard deviation in R?
- How to calculate root mean square error for linear model in R?
- How to find the mean of list elements in R?
- How to create bar plot of means with error bars of standard deviations using ggplot2 in R?
- How to find the groupwise cumulative mean in R?
- How to find the mean of three-dimensional array in R?
- How to find the moving standard deviation in an R matrix?
- How to create a line chart with mean and standard deviation using ggplot2 in R?
- How to find the root mean square of a vector in R?
- How to find the mean of all columns by group in R?
- How to find the moving standard deviation in an R data frame?
