Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Questionnable computation of Variance in R

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Any suggestions are appreciated!

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading