How to fit this model with a Weibull distribution?
조회 수: 21 (최근 30일)
이전 댓글 표시
Hi. I'm trying to fit my empirical curve with a theoretical Weibull distribution through curve fitting (cftool). The problem is that I get a negative value and I can't understand why.
I tried adding a +c constant to the Weibull function, but it only got worse:
I also tried adjusting the variables' StartingPoint values but nothing changed. I am pretty sure this has to work somehow. Thank you in advance.
댓글 수: 2
채택된 답변
Sam Chak
2024년 9월 28일
I normalized the x-axis data to facilitate the fitting algorithm's search process. Is this solution acceptable?
%% data
X = load("x_axis.mat");
Y = load("y_axis.mat");
%% process a bit
t = X.t;
tm = max(X.t) % max t for normalization; makes the fitting easier
y = Y.M_empRel;
% Fitting model
fo = fitoptions('Method', 'NonlinearLeastSquares',...
'Lower', [0.02, 0.5],...
'Upper', [0.03, 0.6]);
ft = fittype('exp(-((t/299578)/b)^c)', ...
'dependent', {'prob'}, 'independent', {'t'}, ...
'coefficients', {'b', 'c'}, ...
'options', fo);
%% Fit curve to data
[yfit, gof] = fit(t, y, ft, 'StartPoint', [0.025, 0.55])
%% Plot results
plot(yfit, t, y), grid on
xlabel('t'), ylabel('y(t)')
title({'$y(t) = \exp\left(- \left(\frac{t}{299578 b}\right)^{c}\right)$, with $b = 0.02498$ and $c = 0.5535$'}, 'interpreter', 'latex', 'fontsize', 16)
legend('Data', 'Fitted model', 'fontsize', 14)
댓글 수: 4
추가 답변 (2개)
John D'Errico
2024년 9월 27일
편집: John D'Errico
2024년 9월 27일
If this is data that you think comes from a Weibull, then you do not want to use regression techniques to fit the distribution. And adding a constant term invalidates the result as a Weibull distribution.
You can use MLE. But more approprately, use wblfit.
help wblfit
If you provide the data, we can possibly offer more or better advice. Lacking that, just use wblfit.
댓글 수: 13
Torsten
2024년 9월 28일
Then why did the exponential fit work?
Because a*exp(b*x) is not a distribution function for arbitrary choices of the parameters a and b.
Besides, what am I supposed to do then to make it work with a Weibull distribution? Scale down my values/data?
It will be difficult with a modified Weibull function because only in a very special case it passes through (0/1).
David Goodmanson
2024년 9월 27일
편집: David Goodmanson
2024년 9월 27일
Hi MIchele,
One possibility is that you are not fitting the correct statistical function to the data. The algebraic expression you have is a probability density function (pdf), but the data runs from y = 1 down to y = 0 [eventually], and looks like a cumulative distribution function (cdf), more specifically (1-cdf) since a cdf runs from 0 up to 1. For the weibull cdf,
y = 1-exp(-(x/b)^c) and (1-y) = exp(-(x/b)^c)
and the latter function you can fit to the data.
When x=0 then y=1, and when x=b then y = exp(-1) = .368 for all vaues of c. Looking at your plot, .368 occurs close to x = 1 which implies that b is approximately 1.
I guess another possibility is that y is a pdf that so happens to equal 1 at x = 0. This occurs for the weibull pdf when c = 1, which is the same as the pdf of an exponential distribution, (1/b) exp(-x/b).
댓글 수: 3
David Goodmanson
2024년 9월 27일
I plotted the data you enclosed vs a linear scale and it does not look in the least like the data in the plot.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!