How can i select random sample from mixture of two normal distributions in MATLAB ?

Hi everyone Could you please let me know how can i select random sample from contaminated normal distribution (i.e., mixture of two normal distributions) in MATLAB? .Suppose i need a sample of 100 values from mixture normal distributions such that 5% values are from Normal distribution with mean zero and variance 25 and 95% values are from normal with mean zero and variance 1. In mathematical terms i can write my problem as:
5% from N(0,25)+95% from N(0,1) This is mixture random sample of two normal distributions.

 採用された回答

Roger Stafford
Roger Stafford 2016 年 5 月 1 日
r = rand(100,1)>=.05;
R1 = normrnd(0,sqrt(25),100,1);
R2 = normrnd(0,sqrt(1),100,1);
S = (1-r).*R1+r.*R2;
S contains your 100 samples.
This assumes that your two normal distributions are statistically independent.

4 件のコメント

zahid
zahid 2016 年 5 月 3 日
Dear Roger Stafford When i run r = rand(100,1)>=.05;it gives mean a vector having four zeros and 96, ones.Logically it should give me 5 zeros and 95 ones.What is wrong with it?Suppose i change to 20% samples from one distribution and and 80% sample from another then it will deal .Please generalized this random selection to any percentage that i want.
Roger Stafford
Roger Stafford 2016 年 5 月 3 日
編集済み: Roger Stafford 2016 年 5 月 3 日
_“When i run r = rand(100,1)>=.05;it gives mean a vector having four zeros and 96 ones.“_
That is NOT how ‘rand’ works, Zahid. The ‘rand’ function is statistically uniform throughout the range from 0 to 1. That means, statistically speaking, there is a 5%, that is 1 in 20, chance that its value will lie between 0 and .05 and 19 out of 20 chance that it will lie outside that range. You can arrive at that conclusion by dividing .05-0 by 1 to get .05 = 1/20, and dividing 1-.05 by 1 to get .95 = 19/20. It is a very simple calculation.
You cannot conclude that out of each 100 samples there will be four zeros or five zeros or any other definite number. We are dealing with a statistical situation here. All you can say is that the average number would be five zeros and ninety-five ones. That is all you can say.
zahid
zahid 2016 年 5 月 6 日
Dear Stafford Thank you very much for your explanation.Logically i taking 5% values from one distribtuion i.e 5 values out of 100 as sample size is 100.Similarly 95% values from other normal distribution which means 95 values out of 100.How can i do this?Your logic i did not understand
zahid
zahid 2016 年 5 月 6 日
Thank your Roger Stafford now i have get your point.The logic which you are using is true in probability sense.
Regards

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Random Number Generation についてさらに検索

質問済み:

2016 年 5 月 1 日

コメント済み:

2016 年 5 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by