How to sample Multinomial Distribution
3 ビュー (過去 30 日間)
古いコメントを表示
Mike Nguyen
2017 年 12 月 16 日
コメント済み: Kaushik Lakshminarasimhan
2017 年 12 月 17 日
Suppose I have the X data with dimension(VxN), and probability rho(vkj) with k is latent variable How could I sample Matrix (Av1j,...,AvKj)follows Multinomial (Xvj,rho(vkj))
0 件のコメント
採用された回答
Kaushik Lakshminarasimhan
2017 年 12 月 17 日
It is difficult to read your question. Please use underscore to separate your variable names from subscripts. Here's a solution with nested loops. Perhaps you can find a way to vectorise it if the size of X is prohibitively large.
V = 50; N = 10; K = 5;
X = 100*ones(V,N); % assuming 100 trials (sample size)
rho = rand(V,N,K);
rho = rho./repmat(sum(rho,3),1,1,K);
for v = 1:V
for j = 1:N
A(v,:,j) = mnrnd(X(v,j),squeeze(rho(v,j,:))); % your A_vkj
end
end
2 件のコメント
Kaushik Lakshminarasimhan
2017 年 12 月 17 日
Because mnrnd expects the second argument to be a 1xK or Kx1 vector whereas rho(v,j,:) is 1x1xK. squeeze converts the 1x1xK vector to Kx1 by removing the singleton dimension.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!