All about totalvar

The official docs of totalvar(X) says if X is a matrix, then the totalvar(X) == sum(Diagonal(X)) but clearly in the testsit is showing a different value. You can check line 146.

The documentation says that it is the sum of the diagonal of the covariance matrix. Hence

julia> using StatsBase
julia> X = [1 2 5
            4 1 6
            4 0 4];
julia> cov(X)
3×3 Matrix{Float64}:
  3.0  -1.5  0.0
 -1.5   1.0  0.5
  0.0   0.5  1.0

So, the test looks correct to me.

1 Like

Totalvar is " is equivalent to the sum of the diagonal elements of the covariance matrix of X ", not of matrix X itself:

totalvar(X) == sum(Diagonal(cov(X)))   # true

NB: you should add using StatsBase

1 Like