Message Boards Message Boards

0
|
4180 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Generate random covariance matrices?

I am interested in generating data from a multivariate normal distribution, in which I have some control over the relation between variables. I have tried the following:

nvars = 11;
nobs = 70;
k = 15;

W = RandomVariate[NormalDistribution[], {nvars, k}];

MD = DiagonalMatrix@RandomVariate[NormalDistribution[], nvars];

K = W.Transpose@W + MD;

datasim = RandomVariate[MultinormalDistribution@K, nobs]

However, I am not satisfied with my approach, because if I set a higher number for nvars and nobs, it usually fails because the covariance matrix R generated is not always positive semi-definite.

Does anyone know a better aproach to generate large covariance matrices in which I have some control over the relation between variables?

Thanks in advance for any help!

2 Replies
Posted 3 years ago

Using WishartMatrixDistribution will get you "random" covariance matrices. (You might need to be more specific about what you mean by "random" if there are some parameters of a specific distribution that you're trying to estimate.) Here is (essentially) the example from the documentation:

SeedRandom[12345];
RandomVariate[WishartMatrixDistribution[10, {{1, 1/3}, {1/3, 1}}]]
(* {{4.09159, -1.84851}, {-1.84851, 7.91313}} *)

SymmetricMatrixQ[%] \[And] PositiveSemidefiniteMatrixQ[%]
(* True *)
POSTED BY: Jim Baldwin

Thanks for your reply Jim. I was aware of the Wishart distribution. However, I am not sure how can I generate a scale matrix to use that distribution. It needs to be also positive definite, and in my real case I will need around 100 variables.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract