<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265340</link>
    <title>MATLAB Central Newsreader - Random sampling from mulvairate distribution</title>
    <description>Feed for thread: Random sampling from mulvairate distribution</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Mon, 09 Nov 2009 10:51:03 -0500</pubDate>
      <title>Random sampling from mulvairate distribution</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265340#693175</link>
      <author>Tomaz </author>
      <description>Hello!&lt;br&gt;
&lt;br&gt;
I realize this is basic question for experienced users/ statistics, but I just cant find a solution to my problem in documentation of Matlab or on Internet.&lt;br&gt;
&lt;br&gt;
Here is what I want to do: I need to get a single randomly generated value of one of independent variables out of multivariate normal distribution. I know how to get whole random vector&lt;br&gt;
r = mvnrnd(mu,SIGMA,1);&lt;br&gt;
&lt;br&gt;
, but what I have to really do, is basically fix all variables but one. I want to basically say: if you know multivariate distribution and I give you let's say 3 out of 4 independent variables, return me a randomly generated value for the 4th variable (of course taking into account values of other 3 variables). I supposethis is sampling from uniform distribution? But how to fix other 3 variables to get to this distribution? Please, do help me... </description>
    </item>
    <item>
      <pubDate>Mon, 09 Nov 2009 14:35:02 -0500</pubDate>
      <title>Re: Random sampling from mulvairate distribution</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265340#693220</link>
      <author>Greg Heath</author>
      <description>On Nov 9, 5:51&#160;am, &quot;Tomaz &quot; &amp;lt;tomaz.bart...@gmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; Hello!&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I realize this is basic question for experienced users/ statistics, but I just cant find a solution to my problem in documentation of Matlab or on Internet.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Here is what I want to do: I need to get a single randomly generated value of one of independent variables out of multivariate normal distribution. I know how to get whole random vector&lt;br&gt;
&amp;gt; r = mvnrnd(mu,SIGMA,1);&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; , but what I have to really do, is basically fix all variables but one. I want to basically say: if you know multivariate distribution and I give you let's say 3 out of 4 independent variables, return me a randomly generated value for the 4th variable (of course taking into account values of other 3 variables). I supposethis is sampling from uniform distribution? But how to fix other 3 variables to get to this distribution? Please, do help me...&lt;br&gt;
&lt;br&gt;
You want a 4-dimensional multivariate distribution.&lt;br&gt;
The variables are correlated and each of the&lt;br&gt;
variables has a different marginal probability&lt;br&gt;
distribution.&lt;br&gt;
&lt;br&gt;
You have a sample containing 3 variables and&lt;br&gt;
wish to randomly generate a 4th that satisfies a&lt;br&gt;
specified marginal distribution and correlation&lt;br&gt;
relationship.&lt;br&gt;
&lt;br&gt;
There are no spectral constraints.&lt;br&gt;
&lt;br&gt;
Is that correct?&lt;br&gt;
&lt;br&gt;
If so, the difficulty lies in how the correlation&lt;br&gt;
relationship is specified. If the multivariate distribution&lt;br&gt;
is not Gaussian, not much can be done directly&lt;br&gt;
unless rank (NOT moment) correlation coefficients&lt;br&gt;
are specified.&lt;br&gt;
&lt;br&gt;
Please give more details.&lt;br&gt;
&lt;br&gt;
Greg</description>
    </item>
    <item>
      <pubDate>Mon, 09 Nov 2009 15:21:02 -0500</pubDate>
      <title>Re: Random sampling from mulvairate distribution</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265340#693236</link>
      <author>Tomaz </author>
      <description>Greg, firstly thank you for your help.&lt;br&gt;
To tell you the truth my knowledge of statistics is not good enough to quite understand your hints. But let me rephrase my question.&lt;br&gt;
&lt;br&gt;
I have a data set with 4 independent normally distributed variables. I put this dataset in matrix A. From this it is easy to calculate average vector (MU): &lt;br&gt;
MU = mean(A);&lt;br&gt;
&lt;br&gt;
It is also trivial to obtain variance-covariance matrix (SIGMA).&lt;br&gt;
SIGMA = cov(A);&lt;br&gt;
&lt;br&gt;
So, given MU and SIGMA I can 'build' and plot normal (Gaussian) multi variate distribution.&lt;br&gt;
&lt;br&gt;
Now, what I need to do is to generate a value for x4, when I have x1, x2 and x3 given. &lt;br&gt;
&lt;br&gt;
I will be basicaly performing a simulation, where I will generate values for column x4 every time. I suppose I just need a normal (univariable) distribution of x4 and then sample from it. However, in my understanding this normal distribution is different (has other mean and stdDev) for every combination of x1, x2, x3. So, how an I get the right distribution function for some particular values of x1, x2 and x3? And how can I then sample values for x4 out of it? &lt;br&gt;
&lt;br&gt;
I hope I was more clear now? </description>
    </item>
    <item>
      <pubDate>Wed, 11 Nov 2009 01:33:10 -0500</pubDate>
      <title>Re: Random sampling from mulvairate distribution</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265340#693692</link>
      <author>Greg Heath</author>
      <description>On Nov 9, 10:21&#160;am, &quot;Tomaz &quot; &amp;lt;tomaz.bart...@gmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; Greg, firstly thank you for your help.&lt;br&gt;
&amp;gt; To tell you the truth my knowledge of statistics is not good enough to quite understand your hints. But let me rephrase my question.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I have a data set with 4 independent normally distributed variables. I put this dataset in matrix A. From this it is easy to calculate average vector (MU):&lt;br&gt;
&amp;gt; MU = mean(A);&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; It is also trivial to obtain variance-covariance matrix (SIGMA).&lt;br&gt;
&amp;gt; SIGMA = cov(A);&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; So, given MU and SIGMA I can 'build' and plot normal (Gaussian) multi variate distribution.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Now, what I need to do is to generate a value for x4, when I have x1, x2 and x3 given.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I will be basicaly performing a simulation, where I will generate values for column x4 every time. I suppose I just need a normal (univariable) distribution of x4 and then sample from it. However, in my understanding this normal distribution is different (has other mean and stdDev) for every combination of x1, x2, x3. So, how an I get the right distribution function for some particular values of x1, x2 and x3? And how can I then sample values for x4 out of it?&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I hope I was more clear now?&lt;br&gt;
On Nov 9, 10:21 am, &quot;Tomaz &quot; &amp;lt;tomaz.bart...@gmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; Greg, firstly thank you for your help.&lt;br&gt;
&amp;gt; To tell you the truth my knowledge of statistics is not good enough to quite understand your hints. But let me rephrase my question.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I have a data set with 4 independent normally distributed variables. I put this dataset in matrix A. From this it is easy to calculate average vector (MU):&lt;br&gt;
&amp;gt; MU = mean(A);&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; It is also trivial to obtain variance-covariance matrix (SIGMA).&lt;br&gt;
&amp;gt; SIGMA = cov(A);&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; So, given MU and SIGMA I can 'build' and plot normal (Gaussian) multi variate distribution.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Now, what I need to do is to generate a value for x4, when I have x1, x2 and x3 given.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I will be basicaly performing a simulation, where I will generate values for column x4 every time. I suppose I just need a normal (univariable) distribution of x4 and then sample from it. However, in my understanding this normal distribution is different (has other mean and stdDev) for every combination of x1, x2, x3. So, how an I get the right distribution function for some particular values of x1, x2 and x3? And how can I then sample values for x4 out of it?&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I hope I was more clear now?&lt;br&gt;
&lt;br&gt;
Yes. Since all of the variables are normal, the solution is&lt;br&gt;
relatively&lt;br&gt;
simple.&lt;br&gt;
&lt;br&gt;
Given: The sequence of random variables zi (i = 1,2,..) with the&lt;br&gt;
properties&lt;br&gt;
1. Zero mean, &amp;lt;zi&amp;gt; = 0&lt;br&gt;
2. Unit variance &amp;lt;zi*zi&amp;gt; = 1&lt;br&gt;
3. Independent &amp;lt;zi*zj&amp;gt; = 0 , |i-j|&amp;gt;0&lt;br&gt;
&lt;br&gt;
Now consider the following sequence of random variables xi (i=1,2,...)&lt;br&gt;
&lt;br&gt;
x1 = z1, &amp;lt;x1&amp;gt; = 0, &amp;lt;x1*x1&amp;gt; = 1&lt;br&gt;
&lt;br&gt;
x2 = sqrt(1-C21^2)*z2 + C21*x1&lt;br&gt;
&amp;lt;x2&amp;gt; = 0,  &amp;lt;x2*x1&amp;gt; = C21, &amp;lt;x2*x2&amp;gt; = 1&lt;br&gt;
&lt;br&gt;
x3 = sqrt(1-C32^2-C31^2)*z3+ C32*x2+C31*x1&lt;br&gt;
&amp;lt;x3&amp;gt; = 0,  &amp;lt;x3*x2&amp;gt; = C32 , &amp;lt;x3*x1&amp;gt; = C31, &amp;lt;x3*x3&amp;gt; = 1&lt;br&gt;
&lt;br&gt;
Now, if the zi are N(0,1) distributed, the xi will be N(0,1)&lt;br&gt;
(NOTE: NOT true with other distributions)&lt;br&gt;
&lt;br&gt;
Furthermore, if x1 and x2 were obtained by any other means&lt;br&gt;
but are still known to be N(0,1) distributed, the formula for x3&lt;br&gt;
is still valid.&lt;br&gt;
&lt;br&gt;
End of hints.&lt;br&gt;
&lt;br&gt;
Good luck with solving your problem!&lt;br&gt;
&lt;br&gt;
Greg</description>
    </item>
  </channel>
</rss>

