How do I generate numbers from discrete bivariate distribution?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
Respuesta aceptada
MathWorks Support Team
el 27 de Jun. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Random Number Generation en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!