Population change in r

How can I calculate the variance of my data set with R?

I read that there is a package called popvar, but I have version 0.99.892 and I did not find the package

+5
source share
3 answers

The var() function in the R base calculates the variance of the sample, and the variance of the population differs in the variance of the sample in n / n - 1 . Thus, an alternative to calculating population variance would be var(myVector) * (n - 1) / n , where n is the length of the vector, here is an example:

 x <- 1:10 var(x) * 9 /10 [1] 8.25 

From the definition of population variance:

 sum((x - mean(x))^2) / 10 [1] 8.25 
+12
source

You can find information about the popvar package here: https://cran.r-project.org/web/packages/PopVar/index.html - You can install it using the install.packages("PopVar"); Please note that the name is case sensitive (capital P, capital V).

+1
source

You already have a great answer, but I would like to show that you can easily make your own handy functions. Surprisingly, the variance / standard deviation distribution function is not available in the R database. It is available in Excel / Calc and other software. There is no such function. It can be called sd.p or sd.p or called using sd(x, pop = TRUE)

Here is the basic version of population variance without type checking:

  x <- 1:10 varp <- function(x) mean((x-mean(x))^2) varp(x) ## [1] 8.25 

To zoom in if speed is a problem, colSums and / or colMeans can be used (see https://rdrr.io/r/base/colSums.html )

0
source

All Articles