- 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 calculate population variance in R?
There is no function in R to calculate the population variance but we can use the population size and sample variance to find it. We know that the divisor in population variance is the population size and if we multiply the output of var(it calculates sample variance) function with (population size – 1)/population size then the output will be population variance.
Example
set.seed(141) x1<-1:100 Sample_Variance<-var(x1) Sample_Variance
Output
[1] 841.6667
Example
Population_Variance<-var(x1)*(99/100) Population_Variance
Output
[1] 833.25
Example
x2<-rnorm(500) Sample_Variance<-var(x2) Sample_Variance
Output
[1] 1.013514
Example
Population_Variance<-var(x2)*(499/500) Population_Variance
Output
[1] 1.011487
Example
x3<-round(rnorm(500),0) Sample_Variance<-var(x3) Sample_Variance
Output
[1] 1.088401
Example
Population_Variance<-var(x3)*(499/500) Population_Variance
Output
[1] 1.086224
Example
x4<-rpois(150,10) x4
Output
[1] 15 13 11 4 10 9 13 12 8 12 7 13 10 18 8 11 15 8 9 14 7 14 8 11 7 [26] 6 10 12 7 15 13 12 13 11 9 7 15 11 17 10 17 11 9 10 17 11 4 11 11 9 [51] 11 10 11 10 16 11 6 4 9 5 5 6 6 6 10 10 10 13 10 6 10 9 7 11 13 [76] 12 7 5 10 7 7 10 7 10 10 14 11 11 9 6 13 9 5 11 13 11 10 10 6 15 [101] 7 12 7 9 13 6 9 13 13 11 11 16 5 12 14 10 10 10 13 7 4 16 6 13 6 [126] 4 9 7 9 7 8 12 12 10 10 9 8 4 10 8 9 7 13 7 11 9 8 8 10 12
Example
Sample_Variance<-var(x4) Sample_Variance
Output
[1] 10.86694
Example
Population_Variance<-var(x4)*(149/150) Population_Variance
Output
[1] 10.79449
Example
x5<-sample(1:100,120,replace=TRUE) x5
Output
[1] 62 59 25 15 16 17 69 22 81 90 91 68 61 40 61 48 33 71 60 11 1 15 95 17 81 [26] 29 16 44 47 26 20 56 97 74 3 5 44 77 50 44 83 54 37 54 73 46 99 19 85 28 [51] 8 49 15 80 65 50 85 7 91 76 83 93 54 95 52 8 20 18 70 12 66 36 2 99 81 [76] 13 91 11 73 19 2 73 20 12 80 41 38 20 61 64 39 30 65 28 25 38 56 61 44 32 [101] 66 76 2 72 36 78 48 41 52 17 31 69 33 74 39 60 29 59 72 11
Example
Sample_Variance<-var(x5) Sample_Variance
Output
[1] 892.7361
Example
Population_Variance<-var(x5)*(119/120) Population_Variance
Output
[1] 885.2966
Example
x6<--sample(101:999,120) x6
Output
[1] -919 -502 -343 -523 -867 -405 -368 -447 -286 -578 -147 -665 -823 -598 -260 [16] -740 -569 -661 -386 -267 -185 -114 -608 -711 -638 -992 -552 -795 -291 -152 [31] -154 -211 -721 -388 -283 -234 -525 -942 -599 -176 -239 -788 -579 -875 -883 [46] -856 -143 -304 -407 -448 -717 -524 -273 -235 -167 -158 -659 -432 -803 -624 [61] -187 -312 -225 -802 -439 -453 -637 -571 -768 -664 -473 -331 -806 -265 -173 [76] -748 -623 -671 -989 -888 -950 -589 -487 -526 -668 -760 -414 -622 -248 -276 [91] -139 -951 -630 -885 -440 -191 -491 -685 -653 -132 -742 -477 -181 -505 -759 [106] -974 -741 -548 -593 -240 -527 -914 -402 -127 -860 -336 -333 -794 -891 -311
Example
Sample_Variance<-var(x6) Sample_Variance
Output
[1] 62657.78
Example
Population_Variance<-var(x6)*(119/120) Population_Variance
Output
[1] 62135.63
Example
x7<-rexp(50,3.5) x7
Output
[1] 0.205216964 0.133222130 0.488146733 0.244428905 0.833206350 0.069545948 [7] 0.195504191 0.539364253 1.099099582 1.835459402 0.170821138 0.342813864 [13] 0.108211014 0.392889843 0.069053900 0.083381383 0.282172880 1.299693448 [19] 0.033847926 0.248126373 0.537849065 0.508127648 0.148564885 0.047607303 [25] 0.247224701 0.171349073 0.089745700 0.157843010 0.870047906 0.790377494 [31] 0.285218089 0.107768506 0.806453962 0.565196530 0.283891426 0.129423319 [37] 0.116770751 0.238833628 0.379741206 0.009492331 0.343673059 0.072587659 [43] 0.076498866 0.504828741 0.313257385 0.427818704 0.372741859 0.210799536 [49] 0.155322546 0.504289020
Example
Sample_Variance<-var(x7) Sample_Variance
Output
[1] 0.03401862
Example
Population_Variance<-var(x7)*(49/50) Population_Variance
Output
[1] 0.03333825
Advertisements