I want know how can I calculate variance & expectation in Matlab for 10 sample
조회 수: 6 (최근 30일)
이전 댓글 표시
how can I calculate variance & expectation in Matlab for 10 sample for random variable (x)
pmf of X is :
s=(-1:0.5:1);
p=[0.5*ones(1,1);0.25*ones(1,1);1/8*ones(1,1);1/16*ones(2,1)];
댓글 수: 0
채택된 답변
John D'Errico
2022년 10월 27일
편집: John D'Errico
2022년 10월 27일
It would seem your question defines a discrete random variable on the set s, where you have given the probability at each point.
Now you want to compute the mean and variance of what? Are you asking to compute the population mean and variance? (That is implied when you use the word EXPECTATION.
Or are you asking how to compute the mean and variance of a sample, of size 10? These are subtly different things, but are often confused. But you seem to be mixing up your question in a way that says you are not aware of the difference.
s=(-1:0.5:1);
p=[0.5*ones(1,1);0.25*ones(1,1);1/8*ones(1,1);1/16*ones(2,1)];
bar(s,p)
Given that set of weights for a discrete random sample, you could now use randsample to generate a random set of 10 deviates from that distribution. And then you could compute the mean and variance, OF THAT SAMPLE.
X = randsample(s,10,true,p)
mean(X)
var(X)
Of course, that is not the same thing as the population mean and variance, since the sampel mean and variance will checnge every time you create a new sample. Since your weights are already unit normalized (checking that claim)
sum(p)
Then the population mean is simply
PopMean = dot(s,p)
And the population variance is as easily written as:
PopVar = dot((s - PopMean).^2,p)
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
