|
>I allready tried to get an answer to this number generating question
>regarding multivariate normal distribution, but did not get any final
>answer. I believe I was unlcear so I will try to ask all you guys about
>this in more direct way.
>
> Let's say I had 'build' multivariate normal distribution from my dataset
> and is characterized like this:
...
> Now I have to generate new record for my dataset and I have x1 given
> (let's say it's x1=0.5). How can I get the corresponding distribution for
> x2 (given that x1=0.5) and then generate (sample) new values for it?
> Thanks for your help, this is really important for me.
This problem can be worked out analytically. Doing it that way doesn't
really have anything to do with MATLAB.
However, if you want to play around with MATLAB, here are some things you
could do.
1. You could evaluate a slice of the multivariate pdf at x1=0.5:
f = @(x2) mvnpdf([repmat(.5,size(x2(:))),x2(:)],mu,Sigma);
xx = linspace(-3,3);
plot(xx,f(xx))
2. You could note that this isn't really a probability density, because it
doesn't integrate to 1. But you could make a new function that is
approximately a density.
quad(f,-5,5)
g = @(x) f(x)/.4839;
line(xx,g(xx),'color','r')
3. Forgetting for the moment that this function could be worked out
analytically, you could use the slicesample function to generate random
numbers from it. It turns that the f function that doesn't integrate to 1
would be adquate for this purpose. You can see that the numbers look
reasonably like a sample from the distribution with density g.
newx = slicesample(0,2000,'pdf',f);
[yks,xks] = ksdensity(newx);
line(xks,yks,'color','g')
-- Tom
|