Computing Variance manually problem
3 次查看(过去 30 天)
显示 更早的评论
HI all I am facing a problem in computing variance manualy.As
I have a A= magic(3) matrix of 9 elements
when I calculate it directly by using var it gives me
var(var(A)) ans is 27 but when I campute manually it does not match with above answer
As
variance=(A-mean(mean(A))).^2/8 variance=sum(sum(variance)) answer is 0. why is this situation occurring is there any problem in my formula?
0 个评论
采纳的回答
Shashank Prasanna
2013-1-23
Your formula is wrong. when you say var(var(A)) you are actually computing the variances of each column and then variances of these variances. Is there a reason you are doing this? However if you are interested in reproducing the result, then you have to follow the same steps manually as follows:
A = magic(3);
B = sum((A-repmat(mean(A),3,1)).^2)/2; % Variance of each column
var_magic = sum((B-mean(B)).^2)/2 % Variance of the variance computed above.
var_magic =
27
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!