I want know how can I calculate variance & expectation in Matlab for 10 sample
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
John D'Errico
am 27 Okt. 2022
Bearbeitet: John D'Errico
am 27 Okt. 2022
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)
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
