How may I show a multi modal distribution?

8 次查看(过去 30 天)
I truly appreciate if someone help me for my rudimentary question. I have a data-set (attached) shows multi modal distributions. I know this data is not enough to claim a multimodal distribution confidently. Assuming enough data points, how I can show a multimodal dataset. I means I want to show a data set like the attached figure (the figure is not mine and I only use it to express my question). Thank you in advance!

回答(1 个)

Dev
Dev 2025-4-23
The plot provided in the question above shows a multi-modal distribution modelled as a mixture of Gaussians (Gaussian Mixture Model, GMM). To show such a multimodal distribution in MATLAB, we can generate data from a mixture of two or more normal (Gaussian) distributions and then plot the resulting probability density. We can leverage the following steps to simulate and plot a mixture of two Gaussians, similar to figure attached:
  • Generate two normal distributions using the “normrnd” function in MATLAB. The function requires a mean parameter ‘mu’ and standard deviation parameter ‘sigma’ which we can define according to our usage. I have also attached a reference code snippet for the same below-
% Generate data
N = 10000; % Number of data points
data = [normrnd(mu1, sigma1, round(w1*N), 1);
normrnd(mu2, sigma2, round(w2*N), 1)];
  • Next, compute the weighted Probability Density Functions (PDFs) of each component and the range of values of the PDF. We can then plot the true components using the “plot” function in MATLAB. Please refer to the code snippet below-
% Compute true components
x = linspace(-5, 15, 1000); % Range of values
y1 = w1 * normpdf(x, mu1, sigma1); % Weighted PDFs
y2 = w2 * normpdf(x, mu2, sigma2);
  • Finally, we can fit the Gaussian Mixture Model to the data defined in step 1 using the “fitgmdist” function in MATLAB. We can then estimate the PDF for this mixture model and finally plot the obtained PDF. I have provided an example for the same below-
% Fit a Gaussian Mixture Model (GMM) to the data
gm = fitgmdist(data, 2);
y_gmm = pdf(gm, x');
I have also attached a screenshot of the graph obtained after plotting all the relevant PDFs, for your reference.
Kindly find all the relevant documentation links below-
I hope the above steps help resolve your query.

Community Treasure Hunt

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

Start Hunting!

Translated by