Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Random sampling from mulvairate distribution

Subject: Random sampling from mulvairate distribution

From: Tomaz

Date: 9 Nov, 2009 10:51:03

Message: 1 of 4

Hello!

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.

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
r = mvnrnd(mu,SIGMA,1);

, 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...

Subject: Random sampling from mulvairate distribution

From: Greg Heath

Date: 9 Nov, 2009 14:35:02

Message: 2 of 4

On Nov 9, 5:51 am, "Tomaz " <tomaz.bart...@gmail.com> wrote:
> Hello!
>
> 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.
>
> 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
> r = mvnrnd(mu,SIGMA,1);
>
> , 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...

You want a 4-dimensional multivariate distribution.
The variables are correlated and each of the
variables has a different marginal probability
distribution.

You have a sample containing 3 variables and
wish to randomly generate a 4th that satisfies a
specified marginal distribution and correlation
relationship.

There are no spectral constraints.

Is that correct?

If so, the difficulty lies in how the correlation
relationship is specified. If the multivariate distribution
is not Gaussian, not much can be done directly
unless rank (NOT moment) correlation coefficients
are specified.

Please give more details.

Greg

Subject: Random sampling from mulvairate distribution

From: Tomaz

Date: 9 Nov, 2009 15:21:02

Message: 3 of 4

Greg, firstly thank you for your help.
To tell you the truth my knowledge of statistics is not good enough to quite understand your hints. But let me rephrase my question.

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):
MU = mean(A);

It is also trivial to obtain variance-covariance matrix (SIGMA).
SIGMA = cov(A);

So, given MU and SIGMA I can 'build' and plot normal (Gaussian) multi variate distribution.

Now, what I need to do is to generate a value for x4, when I have x1, x2 and x3 given.

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?

I hope I was more clear now?

Subject: Random sampling from mulvairate distribution

From: Greg Heath

Date: 11 Nov, 2009 01:33:10

Message: 4 of 4

On Nov 9, 10:21 am, "Tomaz " <tomaz.bart...@gmail.com> wrote:
> Greg, firstly thank you for your help.
> To tell you the truth my knowledge of statistics is not good enough to quite understand your hints. But let me rephrase my question.
>
> 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):
> MU = mean(A);
>
> It is also trivial to obtain variance-covariance matrix (SIGMA).
> SIGMA = cov(A);
>
> So, given MU and SIGMA I can 'build' and plot normal (Gaussian) multi variate distribution.
>
> Now, what I need to do is to generate a value for x4, when I have x1, x2 and x3 given.
>
> 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?
>
> I hope I was more clear now?
On Nov 9, 10:21 am, "Tomaz " <tomaz.bart...@gmail.com> wrote:
> Greg, firstly thank you for your help.
> To tell you the truth my knowledge of statistics is not good enough to quite understand your hints. But let me rephrase my question.
>
> 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):
> MU = mean(A);
>
> It is also trivial to obtain variance-covariance matrix (SIGMA).
> SIGMA = cov(A);
>
> So, given MU and SIGMA I can 'build' and plot normal (Gaussian) multi variate distribution.
>
> Now, what I need to do is to generate a value for x4, when I have x1, x2 and x3 given.
>
> 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?
>
> I hope I was more clear now?

Yes. Since all of the variables are normal, the solution is
relatively
simple.

Given: The sequence of random variables zi (i = 1,2,..) with the
properties
1. Zero mean, <zi> = 0
2. Unit variance <zi*zi> = 1
3. Independent <zi*zj> = 0 , |i-j|>0

Now consider the following sequence of random variables xi (i=1,2,...)

x1 = z1, <x1> = 0, <x1*x1> = 1

x2 = sqrt(1-C21^2)*z2 + C21*x1
<x2> = 0, <x2*x1> = C21, <x2*x2> = 1

x3 = sqrt(1-C32^2-C31^2)*z3+ C32*x2+C31*x1
<x3> = 0, <x3*x2> = C32 , <x3*x1> = C31, <x3*x3> = 1

Now, if the zi are N(0,1) distributed, the xi will be N(0,1)
(NOTE: NOT true with other distributions)

Furthermore, if x1 and x2 were obtained by any other means
but are still known to be N(0,1) distributed, the formula for x3
is still valid.

End of hints.

Good luck with solving your problem!

Greg

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us