load(geyser);
hist(geyser,20);
Computational Statistics Toolbox has the csfinmix() function for estimating the finite mixture model. Thus:>> [p,mu,var]=csfinmix(geyser',[50,80],[1 1],[0.5 0.5],100,1e-5)
p =
0.3076 0.6924
mu =
54.2027 80.3603
var =
24.5223 56.3646
p =
0.3076 0.6924
mu =
54.2027 80.3603
var =
24.5223 56.3646
We can use this model to generate more samples, let's try 500 more of them:
n=500;
r = rand(1,n);
ind1 = find(r <= p(1));
ind2 = find(r > p(1));
x(ind2)=normrnd(mu(2),sqrt(var(2)),size(ind2));
x(ind1)=normrnd(mu(1),sqrt(var(1)),size(ind1));
figure;
hist(x,20);
Compare the below figure to the figure above.
No comments:
Post a Comment