How can I calculate the population variance of my data using R?
I read there is a package called popvar but I have the Version 0.99.892 and I don't find the package
The var()
function in base R calculate the sample variance, and the population variance differs with the sample variance by a factor of n / n - 1
. So an alternative to calculate population variance will 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