Calculate variance:
v=c(1,2,3)
print(var(v))
#Result:1
#Calculate manually:2/3
Calculate variance:
v=c(1,2,3)
print(var(v))
#Result:1
#Calculate manually:2/3
There are typically two ways to estimate variance. One is 1/n * sum( (x-mean(x))^2 )
and another is 1/(n-1) * sum( (x - mean(x))^2 )
. The second is an unbiased estimator for the variance, which R uses.
The comments about sample variance versus population variance seem a bit misleading to me. The population variance is usually thought of as the fixed, unknown variance of a population. We want to estimate that variance, and we do so with a sample of the data, hence a sample variance (which can be estimated in more than one way, as mentioned above).
var
in R computes sample variance. The other way of doing it is for population variance. http://www.r-tutor.com/elementary-statistics/numerical-measures/variance