Generate random numbers from a mixture distribution
Show older comments
Hi, I would like to generate random numbers from a mixture distribution defined as:
pdf_mix = p*burrpdf(x,alpha,c,k) + (1-p)*wblpdf(x,a,b);
The aim is to compute a kstest2 between the observed data and the mixture distribution.
Is this possible? Can I get some help on this?
T PLOCOSTE
Accepted Answer
More Answers (3)
David Goodmanson
on 3 Aug 2019
Edited: David Goodmanson
on 3 Aug 2019
Hi Thomas.
I presume you mean something like the following. A uniform random variable is used to create an index that picks from the first distribution with probability p, and from the second one with probability 1-p. Here I just arbitrarily made two different distributions from the standard normal distribution. You don't say if p = 2253/3849 in your case, but that's not necessary and p could be anything.
% normal distribution parameters
s1 = 1; mu1 = 1;
s2 = 2; mu2 = 5;
p = .2;
n = 1000;
R = zeros(1,n); % will be the final result
r = rand(1,n);
ind = r<p; % index for first distribution
np = sum(ind);
R( ind) = s1*randn(1,np ) + mu1; % np instances
R(~ind) = s2*randn(1,n-np) + mu2; % n-np instances
Jeff Miller
on 3 Aug 2019
1 vote
> With this formula I obtain a concatenation from 2 distribtutions but not a mixture.
Well, a mixture is just a concatenation from 2 distributions in random order. So you could just randomize the order of R and have your mixture.
As far as kstest2 goes, the order is not important, so you could in fact just use R and get the same kstest2 output.
But if your goal is to test whether the data come from a known distribution, you would really be better to treat that distribution as known and use a one-sample kstest. (I am not sure whether you can build the mixture distribution that you want as a MATLAB distribution object, however, so you might have to code up the kstest yourself if you want to go that route.)
cynthia thing
on 24 Jan 2021
0 votes
Hi Thomas, thank you for this post.
I am currently finding out about this too.
Hopefully you could help me if you are able to obtain.
Thank you
2 Comments
Thomas PLOCOSTE
on 25 Jan 2021
cynthia thing
on 26 Jan 2021
HI Thomas,
You were so helpful.
However I am wondering if I have a random data, which I would like to try to fit the dato into the function, will there be a generalized formula to it?(for example if I do not have a particular number of data that i know)
Thank you
Categories
Find more on Gaussian Mixture Distribution in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!