Thanks all. I am not if I have stated the question correctly. I tried var(x./y) that was suggested by John. However, this is not exactly what I want. For example, x=[1 1 2], y=[2 4 5], var(x./y) actually gives var(1/2 1/4 2/5). I meant to obtain the variance of [1/2 1/4 1/5 1/2 1/4 1/5 2/2 2/4 2/5]
find the variance of x/y
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am new to Matlab. My question sounds to be very simple, however, I cannot make it work in Matlab. Basically, I would like to find the variance of x/y. Each x and y group has 500 single numbers. Please help to make it happen in Matlab. Thanks in advance.
2 Commenti
John D'Errico
il 5 Nov 2015
Modificato: John D'Errico
il 5 Nov 2015
Please don't add an answer every time you have a comment. Use the comment link, which lets you add comments.
I've moved your answer into a comment.
"Thanks all. I am not if I have stated the question correctly. I tried var(x./y). However, this is not exactly what I want. For example, x=[1 1 2], y=[2 4 5], var(x./y) actually gives var(1/2 1/4 2/5). I meant to obtain the variance of [½ ¼ 1/5 1/2 1/4 1/5 2/2 2/4 2/5]"
Of course, if this what you meant, then you should have said it in the first place, as it is very different from your original statement.
Risposta accettata
John D'Errico
il 5 Nov 2015
Modificato: John D'Errico
il 5 Nov 2015
I've added this as a second answer, since it answers the question as modified by the OP.
Essentially, you have two discrete sets of values. You are asking to compute the POPULATION variance of the ratio of the members of those discrete sets, thus all possible combinations, assuming they are equally likely to arise. I emphasized the word "population" for a reason, since you need to be careful in how you compute a population variance. The difference is in the divisor inside the variance code. That difference can be quite significant for small sizes.
x=[1 1 2];
y=[2 4 5];
[xx,yy] = meshgrid(x,y);
var(xx(:)./yy(:),1)
ans =
0.056728
So note the 1 as the second argument to var there. That indicates to var to divide by N, not N-1 in the variance computation. We divide by N when this is a complete population, N-1 when it is a sample variance.
0 Commenti
Più risposte (1)
John D'Errico
il 5 Nov 2015
Modificato: John D'Errico
il 5 Nov 2015
I don't see the problem.
var(x./y)
I will point out the use of ./ as the divide operator. Do some reading to see what is the difference.
help slash
doc slash
Note that this is just a sample variance, since we do not know the distribution of x and y. Since all you have are sample sets of data, you cannot infer a population variance.
Finally, be careful, as the variance of the ratio of two random variables may be rather nasty. This may be why you have had some problems. For example, if there is some probability that the denominator random variable may be near zero, then that singularity will cause serious problems.
0 Commenti
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!