The function var() computes the variance and for the vektor<-c(0,1,1,2) the var(vektor) returns the result 0.666 instead of the expected value 0.5.
Variance as I know it is calculated as the sum of the squared deviations from mean devided by the number of items. In this case the mean(vektor)=1. The variance would be the squared values for (-1,0,0,1) devided by 4. This would be 1 0 0 1 devided by 4. This would be 2/4=0.5
Who knows the reason why r calculates a value different from 0.5? Which formula is used? I did not find an explanation in the help for ?var.
Any suggestions are appreciated!
CodePudding user response:
R computes the unbiased variance (https://en.wikipedia.org/wiki/Variance#Unbiased_sample_variance), which is the same but divided by n-1 = 3
instead of n = 4
.