Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: Generating random numbers for correlated variables Date: Thu, 29 Jan 2009 02:30:04 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 16 Message-ID: <glr4bc$lev$1@fred.mathworks.com> References: <glnafp$9ef$1@fred.mathworks.com> <glnaml$ndp$1@fred.mathworks.com> <glnire$h33$1@fred.mathworks.com> <glnpdj$297$1@fred.mathworks.com> <glpuca$dsc$1@fred.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: webapp-05-blr.mathworks.com Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1233196204 21983 172.30.248.35 (29 Jan 2009 02:30:04 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Thu, 29 Jan 2009 02:30:04 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 1187260 Xref: news.mathworks.com comp.soft-sys.matlab:514615 "Kirk" <kwythers.nospam@umn.edu> wrote in message <glpuca$dsc$1@fred.mathworks.com>... > ....... > I would like to apply a similar approach with the 'mvnrnd' function. It seems to me that I would still have to use 'normrnd' for the first variable "tmax", then use 'mvnrnd' to build the succeeding variables "tmin", "par", "prec", based on the covariances with tmax. Correct? > ........ No Kirk, it is not valid to simply use the covariances of the three variables "tmin", "par", "prec", based on their individual covariances with 'tmax'. You need the covariances between each possible pairing of the four, including pairings of the variables with respect to themselves, i.e. variances, if you expect to generate a valid set of four random variables that truly reflect the statistical properties of your data. Otherwise the covariances that hold between the latter three will not be reflected properly in the output statistics. Using 'normrnd' will most definitely not do the job, at least not as you are carrying it out here. There is no reason not to use 'mvnrnd' which is expressly designed for this kind of computation. Its documentation states "MU is an n-by-d matrix, and mvnrnd generates each row of R using the corresponding row of mu. SIGMA is a d-by-d symmetric positive semi-definite matrix, or a d-by-d-by-n array." For you with d = 4 you will need twelve different 4 x 4 covariance matrices, one for each month, combined in a 4 x 4 x 12 multi-dimensional array, and these need to have a 'repmat' applied to them to achieve the desired 4 x 4 x 12000 size. Your MU needs to be 12000 x 4. The result will be a 12000 x 4 array containing the 12000 sets of the four random variables. I believe a frequent practice in using 'mvnrnd' is to have a non-varying set of means and covariances which is used to generate a random set of variables having constant statistical properties. This does not require the immense number of repetitions that you have here. That is why I originally recommended the use of 'mvnrnd' with the 'cases' option, performed twelve different times, once for each month, with no repetitions necessary. One thing strikes me as strange here. Why have you chosen to make the number of random sets generated (12000) the same as the number of observations? You could just as easily generate 120000 or 1200 random samples from this same set of statistics by altering the number of repetitions in 'repmat'. Once you have computed the means and covariances for each month from the 12 sets of 1000 yearly observations, you are not restricted to just generating 12000 random variables. The number should depend on what your needs are in the use of these random variables. Roger Stafford