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
source share