Plot of a fitted normal distribution

Hello!
I have following problem:
My data consists of a vector x, which contains the possible results of a property (e.g. x = particle size), and a vector y, which contains the relative frequency of x.
For example:
x = 0,1 ; 0,5 ; 1 ; 5 ; 10 ; 50 ; 100; 500
y = 7% ; 9% ; 12% ; 15% ; 30% ; 13% ; 8% ; 6%
I don´t have any absolute frequencies.
I want to plot a fitted normal distribution of this data.
Thank You!
Best regards
Leo

2 Commenti

Could you replace the x and y lines with something we can copy-paste into matlab without errors?
Sorry, my mistake. FYI: I write the relative frequencies without the percent sign.
x
0.1000 0.5000 1.0000 5.0000 10.0000 50.0000 100.0000 500.0000
y
0.0700 0.0900 0.1200 0.1500 0.3000 0.1300 0.0800 0.0600

Accedi per commentare.

 Risposta accettata

Adam Danz
Adam Danz il 25 Mar 2021
Modificato: Adam Danz il 25 Mar 2021
x = [0.011 0.013 0.015 0.017 0.02 0.023 0.026 0.03 0.034 0.039 0.044 0.051 0.058 0.067 0.076 0.087 0.1 0.115, ...
0.131 0.15 0.172 0.197 0.226 0.259 0.296 0.339 0.389 0.445 0.51 0.584 0.669 0.766 0.877 1.005 1.151 1.318, ...
1.51 1.729 1.981 2.269 2.599 2.976 3.409 3.905 4.472 5.122 5.867 6.72 7.697 8.816 10.097 11.565 13.246, ...
15.172 17.377 19.904 22.797 26.111 29.907 34.255 39.234 44.938 51.471 58.953 67.523 77.34 88.583 101.46, ...
116.21 133.103 152.453 174.616 200 229.075 262.376 300.518 344.206 394.244 451.556 517.2 592.387 678.504, ...
777.141 890.116 1019.515 1167.725 1337.481 1531.914 1754.613 2009.687 2301.841 2636.467 3000];
y = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.00036 0.0012533, ...
0.00147 0.00151 0.0013867 0.0011333 0 0 0 0 0 0 0 0 0.00084 0.0025433 0.0058567 0.012833 0.025703 0.048463, ...
0.079867 0.10807 0.11754 0.12896 0.13169 0.11523 0.086417 0.056513 0.03343 0.01883 0.010793 0.0059967, ...
0.0033333 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
f = fit(log(x(:)),y(:),'gauss1');
x0 = linspace(min(log(x)), max(log(x)), 100);
y0 = feval(f,x0);
clf()
hold on
plot(log(x),y,'b-','LineWidth', 3, 'DisplayName', 'Data')
plot(x0,y0, 'r--', 'LineWidth', 3, 'DisplayName', 'fit')
xlabel('log(x)')
ylabel('y')
title([formula(f), newline(), strjoin(compose('%s=%.3f ',string(coeffnames(f)), coeffvalues(f)'))], ...
'FontName','FixedWidth')
legend()
grid on
box on

8 Commenti

Thank you very much!
The coefficients are perfect me, but I have one more problem: The x-axis should be shown as x and not as log(x). Only the scale should be logarithmic. This means, that I need a scale with 1,10,100,1000.
I know that your solution is the same, but I have to present this graph in an axis-system with x and y and not with log(x) and y.
Best regards and thank you again!
Adam Danz
Adam Danz il 25 Mar 2021
Modificato: Adam Danz il 26 Mar 2021
plot(exp(x0),y0, 'r--', 'LineWidth', 3, 'DisplayName', 'fit')
and
set(gca,'xscale','log')
Ignore the log(x) xlabel....
Thank you! It looks great. Thank you for your support.
My last question: Is it possible to solve integrals with matlab?
I want to find the value1 for which 10% of the area under the fitted curve is "left" from this value1.
And i want to find the value2 for which 10% of the area under the fitted curve is "right" from the value2.
And i want to find the value3 for which the area under the fitted curve is splitted in 50% und 50%.
I want to find the median and the other two values.
Best regards!
Adam Danz
Adam Danz il 26 Mar 2021
Modificato: Adam Danz il 27 Mar 2021
Glad I could help.
Regards to your new question, here are all of the post-processing functions that accepts the model (f) as an input.
See the integrate function. Again, the fun input will be f, your model.
Leo
Leo il 26 Mar 2021
Modificato: Leo il 26 Mar 2021
Thank you for your support!!! You helped me a lot!
Unfortunately i don´t get the values, which I need, because I need the coefficients not for log(x). I need the median and co. of the particle size x and don´t of the log(particle size) and it is not correct for the distribution to say median = 10^log(median[in log]).
"I want to find the value1 for which 10% of the area under the fitted curve is "left" from this value1.
And i want to find the value2 for which 10% of the area under the fitted curve is "right" from the value2.
And i want to find the value3 for which the area under the fitted curve is splitted in 50% und 50%.
I want to find the median and the other two values."
The distribution is not gaussian without the log transform.
You can compute the mean, median, etc from the fit and then transform the results back to their original scale using the same method I showed with the previous plot, using exp().
Ok, thank you!
Best regards! :)
Glad I could help.

Accedi per commentare.

Più risposte (1)

x=[ 0.1000 0.5000 1.0000 5.0000 10.0000 50.0000 100.0000 500.0000];
y=[0.0700 0.0900 0.1200 0.1500 0.3000 0.1300 0.0800 0.0600];
z=[];
y=floor(100*y);
x=log10(x);%looks like your data is logarithmic (if you don't take log(x), normal distribution will not be great)
for k=1:length(x)
z=[z,repmat(x(k),1,y(k))];%replicate the data based on the frequencies
end
pd=fitdist(z','Normal');
X=-3:.1:5;
Z = normpdf(X,pd.mu,pd.sigma);
plot(X,Z);

3 Commenti

Leo
Leo il 25 Mar 2021
Modificato: Leo il 25 Mar 2021
First of all thank you!
But my problem is not yet solved.
I will show you other data, which should clarify my problem.
I will plot this distribution on a logartihmic x-axis. In the axis system with linear y-axis and log x-axis this data should "look" like a normal distribution. By using the term semilogx(x,y), i get a graph, which is too angular, because the connection between points is linear. Furthermore i would get the mean value and D90 and D10 of the distribution.
I send new data:
x =
1.0e+03 *
Columns 1 through 10
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
Columns 11 through 20
0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001
Columns 21 through 30
0.0002 0.0002 0.0002 0.0003 0.0003 0.0003 0.0004 0.0004 0.0005 0.0006
Columns 31 through 40
0.0007 0.0008 0.0009 0.0010 0.0012 0.0013 0.0015 0.0017 0.0020 0.0023
Columns 41 through 50
0.0026 0.0030 0.0034 0.0039 0.0045 0.0051 0.0059 0.0067 0.0077 0.0088
Columns 51 through 60
0.0101 0.0116 0.0132 0.0152 0.0174 0.0199 0.0228 0.0261 0.0299 0.0343
Columns 61 through 70
0.0392 0.0449 0.0515 0.0590 0.0675 0.0773 0.0886 0.1015 0.1162 0.1331
Columns 71 through 80
0.1525 0.1746 0.2000 0.2291 0.2624 0.3005 0.3442 0.3942 0.4516 0.5172
Columns 81 through 90
0.5924 0.6785 0.7771 0.8901 1.0195 1.1677 1.3375 1.5319 1.7546 2.0097
Columns 91 through 93
2.3018 2.6365 3.0000
y =
Columns 1 through 10
0 0 0 0 0 0 0 0 0 0
Columns 11 through 20
0 0 0 0 0 0 0 0 0 0
Columns 21 through 30
0 0 0 0 0 0 0 0 0 0
Columns 31 through 40
0 0 0 0 0 0 0 0 0 0
Columns 41 through 50
0 0 0 0 0 0 0.0004 0.0013 0.0015 0.0015
Columns 51 through 60
0.0014 0.0011 0 0 0 0 0 0 0 0
Columns 61 through 70
0.0008 0.0025 0.0059 0.0128 0.0257 0.0485 0.0799 0.1081 0.1175 0.1290
Columns 71 through 80
0.1317 0.1152 0.0864 0.0565 0.0334 0.0188 0.0108 0.0060 0.0033 0
Columns 81 through 90
0 0 0 0 0 0 0 0 0 0
Columns 91 through 93
0 0 0
Hopefully you can solve my problem. Thank you!!!
We can't access data the way you've shared it.
One option is to use formatted code to supply data in a copy-paste format such as
x = [ 1 2 3
4 5 6
7 8 9];
Another option is to save the data to a mat file and attach the file.
x = 1000*[0.000011000000000 0.000013000000000 0.000015000000000 0.000017000000000 0.000020000000000 0.000023000000000 0.000026000000000 0.000030000000000 0.000034000000000 0.000039000000000 0.000044000000000 0.000051000000000 0.000058000000000 0.000067000000000 0.000076000000000 0.000087000000000 0.000100000000000 0.000115000000000 0.000131000000000 0.000150000000000 0.000172000000000 0.000197000000000 0.000226000000000 0.000259000000000 0.000296000000000 0.000339000000000 0.000389000000000 0.000445000000000 0.000510000000000 0.000584000000000 0.000669000000000 0.000766000000000 0.000877000000000 0.001005000000000 0.001151000000000 0.001318000000000 0.001510000000000 0.001729000000000 0.001981000000000 0.002269000000000 0.002599000000000 0.002976000000000 0.003409000000000 0.003905000000000 0.004472000000000 0.005122000000000 0.005867000000000 0.006720000000000 0.007697000000000 0.008816000000000 0.010097000000000 0.011565000000000 0.013246000000000 0.015172000000000 0.017377000000000 0.019904000000000 0.022797000000000 0.026111000000000 0.029907000000000 0.034255000000000 0.039234000000000 0.044938000000000 0.051471000000000 0.058953000000000 0.067523000000000 0.077340000000000 0.088583000000000 0.101460000000000 0.116210000000000 0.133103000000000 0.152453000000000 0.174616000000000 0.200000000000000 0.229075000000000 0.262376000000000 0.300518000000000 0.344206000000000 0.394244000000000 0.451556000000000 0.517200000000000 0.592387000000000 0.678504000000000 0.777141000000000 0.890116000000000 1.019515000000000 1.167725000000000 1.337481000000000 1.531914000000000 1.754613000000000 2.009687000000000 2.301841000000000 2.636467000000000 3.000000000000000]
y = [ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.000360000000000 0.001253333333333 0.001470000000000 0.001510000000000 0.001386666666667 0.001133333333333 0 0 0 0 0 0 0 0 0.000840000000000 0.002543333333333 0.005856666666667 0.012833333333333 0.025703333333333 0.048463333333333 0.079866666666667 0.108070000000000 0.117543333333333 0.128960000000000 0.131686666666667 0.115226666666667 0.086416666666667 0.056513333333333 0.033430000000000 0.018830000000000 0.010793333333333 0.005996666666667 0.003333333333333 0 0 0 0 0 0 0 0 0 0 0 0 0 0]

Accedi per commentare.

Categorie

Richiesto:

Leo
il 24 Mar 2021

Commentato:

il 27 Mar 2021

Community Treasure Hunt

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

Start Hunting!

Translated by