How do I generate numbers from discrete bivariate distribution?
3 views (last 30 days)
Show older comments
I would like to know how I can generate sample numbers from discrete bivariate distribution assuming that I have vectors x and y and a discrete probability matrix P to describe the two variables.
Accepted Answer
MathWorks Support Team
on 27 Jun 2009
If P is an unconditional probability matrix and sum of all entries equal to '1', where P(i, j) describe the probability choice (xi, yj), then the RANDSAMPLE function can be used to choose the pair (x,y) using probability matrix P. For example,
P = [0.083333 0.05 0.033333
0.1 0.16667 0.066667
0.1 0.1 0.3];
sum_P = sum(P(:))
x = [1 2 3]';
y = [1 2 3]';
xy = [x repmat(y(1), length(x),1); x repmat(y(2), length(x),1); x repmat(y(3), length(x),1)];
%%generate random row number of (x,y) pair
row = randsample(9,10,true, P(:) );
xy_sample = xy(rows,:);
sum_P =
1
xy_sample =
2 2
3 2
3 1
3 2
1 1
3 2
3 3
3 3
3 3
3 3
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!