How to fit this model with a Weibull distribution?

23 visualizaciones (últimos 30 días)
Michele Turchiarelli
Michele Turchiarelli el 27 de Sept. de 2024
Comentada: Sam Chak el 29 de Sept. de 2024
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 comentarios
Torsten
Torsten el 27 de Sept. de 2024
Editada: Torsten el 27 de Sept. de 2024
Do you have the original data from which you assume that they follow a Weibull distribution ?
If yes: Apply "mle":
Michele Turchiarelli
Michele Turchiarelli el 27 de Sept. de 2024
Hi. I do not claim my data follows a Weibull distribution. However, I at least would like to to see a valid (i.e. non-negative) R-squared value since I need it.

Iniciar sesión para comentar.

Respuesta aceptada

Sam Chak
Sam Chak el 28 de Sept. de 2024
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
tm = 299578
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])
yfit =
General model: yfit(t) = exp(-((t/299578)/b)^c) Coefficients (with 95% confidence bounds): b = 0.02498 (0.02459, 0.02538) c = 0.5535 (0.5464, 0.5606)
gof = struct with fields:
sse: 0.3121 rsquare: 0.9915 dfe: 471 adjrsquare: 0.9915 rmse: 0.0257
%% 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 comentarios
Michele Turchiarelli
Michele Turchiarelli el 29 de Sept. de 2024
Thank you very much for your help and dedication!

Iniciar sesión para comentar.

Más respuestas (2)

John D'Errico
John D'Errico el 27 de Sept. de 2024
Editada: John D'Errico el 27 de Sept. de 2024
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
wblfit - Weibull parameter estimates This MATLAB function returns the estimates of Weibull distribution parameters (shape and scale), given the sample data in x. Syntax parmHat = wblfit(x) [parmHat,parmCI] = wblfit(x) [parmHat,parmCI] = wblfit(x,alpha) [___] = wblfit(x,alpha,censoring) [___] = wblfit(x,alpha,censoring,freq) [___] = wblfit(x,alpha,censoring,freq,options) Input Arguments x - Sample data vector alpha - Significance level 0.05 (default) | scalar in the range (0,1) censoring - Indicator for censoring array of 0s (default) | logical vector freq - Frequency or weights of observations array of 1s (default) | nonnegative vector options - Optimization options statset('wblfit') (default) | structure Output Arguments parmHat - Estimate of parameters 1-by-2 row vector parmCI - Confidence intervals for parameters 2-by-2 matrix Examples openExample('stats/EstimateParametersOfWeibullDistributionExample') openExample('stats/EstimateParametersOfWeibullDistributionCIExample') openExample('stats/EstimateWeibullParametersOptionsExample') See also mle, wbllike, wblpdf, wblcdf, wblinv, wblstat, wblrnd, wblplot Introduced in Statistics and Machine Learning Toolbox before R2006a Documentation for wblfit doc wblfit
If you provide the data, we can possibly offer more or better advice. Lacking that, just use wblfit.
  13 comentarios
Michele Turchiarelli
Michele Turchiarelli el 28 de Sept. de 2024
Editada: Michele Turchiarelli el 28 de Sept. de 2024
Then why did the exponential fit work? Besides, what am I supposed to do then to make it work with a Weibull distribution? Scale down my values/data?
The exponential doesn't hit 1 at x=0 because of the constant +K added to the model.
Torsten
Torsten el 28 de Sept. de 2024
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).

Iniciar sesión para comentar.


David Goodmanson
David Goodmanson el 27 de Sept. de 2024
Editada: David Goodmanson el 27 de Sept. de 2024
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 comentarios
David Goodmanson
David Goodmanson el 27 de Sept. de 2024
I plotted the data you enclosed vs a linear scale and it does not look in the least like the data in the plot.
Michele Turchiarelli
Michele Turchiarelli el 27 de Sept. de 2024
Sorry, I forgot to give you the values on the x axis (time). Look at the attachment of this message, it contains a file with the x axis values and a file with the y axis values.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by