![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/799749/image.png)
R2 between histogram and (weibull) distribution
4 views (last 30 days)
Show older comments
Dora de Jong
on 14 Nov 2021
Commented: Star Strider
on 14 Nov 2021
Looking for the following:
R2 between histogram of parameter 'Weibull.Wh_Wp' and weibull distribution of parameter 'Weibull.Wh_Wp'.
[parmHat, parmCI]=wblfit(Weibull.Wh_Wp);
X=linspace(min(Weibull.Wh_Wp),max(Weibull.Wh_Wp));
plot(X,wblpdf(X,parmHat(1),parmHat(2)),'Color','k', 'LineWidth',1.3)
hold on
histogram(Weibull.Wh_Wp,'BinWidth',10,'FaceColor',[0.4660 0.6740 0.1880], 'EdgeColor', [0.45 0.45 0.45],'Normalization','pdf')
Below the figure of the parameter 'Weibull.Wh_Wp' with its histogram and fitted weibull distribution.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/799699/image.png)
0 Comments
Accepted Answer
Star Strider
on 14 Nov 2021
Try something like this —
wblfcn = @(p,x) wblpdf(x,p(1),p(2));
Weibull.Wh_Wp = wblrnd(150, 3, 1, 100);
X=linspace(min(Weibull.Wh_Wp),max(Weibull.Wh_Wp));
[parmHat,parmCI] = wblfit(Weibull.Wh_Wp);
plot(X,wblpdf(X,parmHat(1),parmHat(2)),'Color','k', 'LineWidth',1.3)
hold on
h1 = histogram(Weibull.Wh_Wp,'BinWidth',10,'FaceColor',[0.4660 0.6740 0.1880], 'EdgeColor', [0.45 0.45 0.45],'Normalization','pdf');
ctrs = h1.BinEdges(1:end-1) + diff(h1.BinEdges(1:2))/2;
y = h1.Values;
wblmdl = fitnlm(ctrs, h1.Values, wblfcn, parmHat)
I’m not certain that an
value on a distribution fit using maximum likelihood is statistically correct, however this will provide it if desired. See the documentation for fitnlm for details on it.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/799749/image.png)
.
4 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!