Vector.var() is not bugged BUT surprising

The basics of how to develop, test, and use models.
guillaume

Vector.var() is not bugged BUT surprising

Edit: It's not bugged: it just doesn't compute what I thought it would

Hello,

while calculating some variances, I found that the built-in function var() has a very surprising behaviour:

Code: Select all

``````objref T
T = new Vector(2)
T.x[1] = 1
T.var()
``````
returns 0.5 (which is wrong: it should be: (0.5²+0.5²)/2 = 0.25)

more surprising

Code: Select all

``````objref T
T = new Vector(4)
T.x[0] = 1
T.x[1] = 1
T.var()
``````
returns 0.33

This likely means that this function thinks the number of elements in T is { T.size()-1 }

##### EDIT #####
Vector.var() actually computes the best estimator of the variance for the vect. Meaning
if, for i in 1, N, X(i) are independent realisations of the law X
then sig² =[ X(1)² + .... + X(N)² - ( X(1) + .... + X(N) )² ] / N
is NOT a good estimator of Var(X) because E(sig²) = Var(X) * (N-1)/N
N/(N-1) * sig² is a better estimator

So, Vector.var() is not bugged, it's just surprising