How can I separate a bimodal distribution into two normal distributions?

2 Comments
Hi @Lazuardi Pujilaksono ,
To separate a bimodal distribution into two normal distributions and estimate their parameters (mean and standard deviation) individually, I will use a mixture model approach assuming that the bimodal distribution is a mixture of two normal distributions. Here is the code snippet that illustrates that,
data = [randn(1000,1) + 2; randn(1000,1) + 5]; % Creating a bimodal distribution
gm = fitgmdist(data, 2); % Fit a Gaussian mixture model with 2 components
mu = gm.mu; % Means of the two normal distributions
sigma = sqrt(gm.Sigma); % Standard deviations of the two normal distributions
x = linspace(min(data), max(data), 1000);
pdf1 = normpdf(x, mu(1), sigma(1));
pdf2 = normpdf(x, mu(2), sigma(2));
figure;
histogram(data, 'Normalization', 'pdf');
hold on;
plot(x, pdf1, 'r', 'LineWidth', 2);
plot(x, pdf2, 'b', 'LineWidth', 2);
legend('Data', 'Normal Distribution 1', 'Normal Distribution 2');
xlabel('Value');
ylabel('Probability Density');
title('Separated Normal Distributions from Bimodal Distribution');
Please see attached plot.

Hope this answers your question.
Answers (1)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!