computing Variance between vectors

조회 수: 36 (최근 30일)
mahmood hassan
mahmood hassan 2019년 7월 21일
답변: mahmood hassan 2019년 7월 21일
I want to compute the variance between vectors, it's result should be a scalar number but matlab command "var" giving me a vector result. let suppose I have two vector x1= [ 2 2 2]' , x2= [4 4 4]' and X= [x1; x2]. The command "var" giving the result of a vector as var(X(1:3,1:2),0,2) = [2 2 2]. but by varriance sample formula
because the square of a vector does not mean square of all its elements. I think the square of the vector is equal to the dot product of a vector with its self which is scalar
Am I right?

답변 (2개)

Bruno Luong
Bruno Luong 2019년 7월 21일
편집: Bruno Luong 2019년 7월 21일
No you are not right, the variance computes the square of the "dispersion" of the random variable. In case of random vector variable the variance formula applies on component by component independently and the result is the vector of the same length than the input.
The variance is actually the vector of diagonal terms of the covariance matrix, which computes also the cross correlation of the components of the variable.
For
x1= [2; 2; 2];
x2= [4; 4; 4];
X = [x1,x2]
the command
var(X,0,2)
works along the 2nd dimension for three identical row-vectors [2,4]. For all component
N = 2;
The expectation (mean) is
mu = (2+4)/N = 3
variance is
1/(N-1) * ((2-mu)^2 + (4-mu)^2)) =
1/1 * ((2-3)^2 + (4-3)^2) = 2
The result is [2,2,2].
The quantity 6 in this example you pretend to be variance is actually the trace of the covariance matrix, which is some time called "total variance".
  댓글 수: 3
mahmood hassan
mahmood hassan 2019년 7월 21일
If we take mean of two vectors it would be a vector not a scalar as mean(X). if suppose the vectors are not identical, how you justify your computation for means as a scalar.
Thnaks
Bruno Luong
Bruno Luong 2019년 7월 21일
편집: Bruno Luong 2019년 7월 21일
"so X contains two column vectors "
So does mine. And your example has an error since you cocatenate vertically the vector [x1; x2].
"your computation for means as a scalar"
The mean is a scalar but for each individual row of X. The three rows is the same vector [2,4]. I started my explanation with "For all component..."
If you want a formula, the variance var(X,0,2) is simply a row vector v where
v(i) = std(X(i,:))^2

댓글을 달려면 로그인하십시오.


mahmood hassan
mahmood hassan 2019년 7월 21일
Thanks so much for your time and cooperation.
I don't think there is any difference between std(X(i,:))^2 and var(X(i,:)).
Standard deviation is the square root of variance.
Is there any difference between these two commands.

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by