KRS-fun
KRS-fun

Reputation: 724

Matlab gmdistribution.fit only finding one peak

I have an array named Area, which contains a set of values. The histogram of the array looks like thisenter image description here

The bin width is 60 in this case. I'd like to fit two gaussians to the two peaks here (even if it won't be a great fit).

So I used:

options = statset('Display','final');
obj = gmdistribution.fit(area,2,'Options',options);
gausspdf = pdf(obj, xaxis);
A = sum(gausspdf);
gausspdf = gausspdf/A;

But when I try to plot the two fitted Gaussians, the resulting curve looks like this:

enter image description here

I'm quite confused, as there should be two peaks appearing in the plot?

Upvotes: 2

Views: 945

Answers (2)

Rash
Rash

Reputation: 4336

I think that your peaks are too close and the function can't distinguish them. so maybe you should change the options for gmdistribution or apply a non-linear function to your data first to get more separate peaks in histogram.

Upvotes: 0

Itamar Katz
Itamar Katz

Reputation: 9655

The gmdistribution.fit method fits data according to maximum-likelihood criterion; that is, it tries to find parameters which maximize the likelihood given the data. It will not necessarily fit what you see or expect visually. Still, there is the possibility that the algorithm converged to a "bad" local minimum. You can try and set the initial conditions according to what you want to get, practically 'helping' the algorithm to converge to the desired result. You do this using the Start option to the fit method, which enables you to give it either an initial guess, in which case you should try and estimate the parameters from the histogram, or an initial component index for each data sample. See the documentation for more details.

Upvotes: 1

Related Questions