how can I generate data mixture of 2 Normal distributions and has the form f(x) = 0.4X1 + 0.6X2 where X1 ~ N(0.4 ,0.15^2) and X2 ~ N(0.7 , 0.09^2)?

13 views (last 30 days)
i need help to generate data from two mixture normal distributions of the denstiy function f(x)=0.4*x1+0.6*x2 where x1~N(0.4,0.15^2) & x2~N(0.7,0.09^2)
  1 Comment
the cyclist
the cyclist on 21 Dec 2018
I interpreted what you wrote a little bit differently from the math you actually wrote. Did you mean that you want there to be 40% probability that the draw is from x1, and 60% that it is from x2? (That's what I assume you meant.)

Sign in to comment.

Accepted Answer

the cyclist
the cyclist on 21 Dec 2018
Edited: the cyclist on 21 Dec 2018
Here is one way:
% The number of random samples to generate
N = 10000;
% First, generate a binomial variable, which 40% of the time (on average) will be equal to 1,
% and 60% of the time (on average) will be equal to zero.
frac = rand(N,1) < 0.4;
% Generate the two normal distributions to sample from
norm1 = 0.4 + 0.15*randn(N,1);
norm2 = 0.7 + 0.09*randn(N,1);
% If "frac" is equal to 1, then the choice will be from the first normal.
% If "frac" is equal to 0, then the choice will be from the second normal.
d = frac.*norm1 + (1-frac).*norm2;
% Plot the resulting distribution
figure
histogram(d)
  5 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Tags

Products


Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!