# Drawing efficiently from independent Normal Inverse Wishart distributions [duplicate]

I need to take independent draws from Normal Inverse Wishart distributions with different parameters. In practise I want to draw:

$$x_i|\Sigma_i \sim \mathcal{N}(\mu_i, \Sigma_i \otimes \Psi_i )$$ $$\Sigma_i \sim IW(S_i, v)$$,

for $$i = 1 , \ldots, T$$

where $$\Sigma_i$$ is $$N \times N$$ and $$x_i$$ is $$k \times 1$$. The parameter of the degrees of freedom of the Inverse Wishart is the same for all the distributions.

Right now, I am doing the draws from the Normal Inverse Wishart distributions one by one, and looping over T. I am using this Matlab code:

    for i = 1:T
z = chol(inv(S{i})'*randn(N,v);
sig_sim = inv(z*z');
vc = kron(sig_sim,Psi{i});
[cf,pp] =chol(vc);
x_sim  = mu{i} + cf'*randn(N*k,1);
end


Is there a way to avoid the loop over T and draw all the T Normal Inverse Wishart jointly (in a sigle step), since they are independent?

I am not asking how to take the draw from the marginal distribution of $$x$$. The question is not related in any way to that. I want to understand how to take a draw for $$\Sigma_{1:T}$$ and $$x_{1:T}$$ without looping over i.

• you should read carefully the questions before closing them! Nov 1, 2022 at 18:15
• If you are still interested, you can edit the post to explain why the proposed dup do not answer your Q. It will then enter a queue for reopening! Sep 10 at 20:37