95% confidence bounds from logistic curve (curve fitter) give different results to plotting via equation in script
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Freya
el 6 de Dic. de 2023
I fit the logisitc model a/(1+exp(-b*(x-c))) to my data using curve fitter and it gave me the following graph - the logisitic curve with coefficients, plus the coefficients for the 95% confidence bounds
a = 84.15 (81.76, 86.54)
b = 0.1853 (0.169, 0.2017)
c = 11.8 (11.26, 12.34)
I have now been trying to plot these lines using matlab script into a new plot with the original data on it - and while the lines plot, the 95% coefficent lines do not match those drawn out by curve fitter (instead they show a much narrower range and the upper and lower bounds actually cross over each other). I've included the script for the curves below. Can anybody see why the plotted curves might not match those from curve fitter?
x = 0:0.1:30;
%calculate the logistic curve
l = 84.15./(1+exp(-0.1853*(x-11.8)));
%plot the logistic curve
plot(x,l)
%calculate the 95% confidence bounds lower
s = 81.76./(1+exp(-0.169*(x-11.26)));
%calculate the 95% confidence bounds upper
d = 86.54./(1+exp(-0.2017*(x-12.34)));
% plot confidence bounds
hold on
plot(x,s,'-','Linewidth',1,'color','#C8C8C8');
plot(x,d,'-','Linewidth',1,'color','#C8C8C8');
hold off
grid on
Below is the curve fitter graph - where the 95% confidence bounds appear to be correct:
0 comentarios
Respuesta aceptada
Cameron
el 6 de Dic. de 2023
Editada: Cameron
el 6 de Dic. de 2023
The graph you showed indicates the 95% prediction bounds. The coefficients you provided as a, b, and c have an uncertainty with them that is characterized by the Curve Fitter app. So each parameter needs a confidence bound for where the "true" value is. In short, they're not the same number. If you want to plot the data with prediction bounds like you showed, try doing this.
%Sample Data. Replace x and y with your real data
x = 0:0.1:30;
a = 84.15;
b = 0.1853;
c = 11.8;
y = a./(1+exp(-b*(x-c))) + randi(5,[size(x)]);
%% Fit: 'untitled fit 1'.
[xData, yData] = prepareCurveData( x, y );
% Set up fittype and options.
ft = fittype( 'logistic' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [84.15, 0.1853, 11.8];
prediction_obs = 0.95; %95% prediction interval
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( 'Name', 'untitled fit 1' );
h = plot( fitresult, xData, yData, 'predobs',prediction_obs);
legend( h, 'y vs. x', 'Sigmoid Fit', ...
sprintf('Lower %s%% bounds',num2str(prediction_obs*100)), ...
sprintf('Upper %s%% bounds',num2str(prediction_obs*100)), ...
'Location', 'southeast', 'Interpreter', 'none' );
% Label axes
xlabel( 'x', 'Interpreter', 'none' );
ylabel( 'y', 'Interpreter', 'none' );
grid on
%If you just want the prediction data, use this
ci = predint(fitresult,x,prediction_obs);
0 comentarios
Más respuestas (1)
Torsten
el 6 de Dic. de 2023
It's not possible to just insert lower and upper bounds for the parameters into the model equation to get the curves for the confidence / prediction bounds.
Take a look at
Calculate Prediction Intervals from the Command Line
under
to learn how to proceed.
The function "predint" is the key to get the correct graphs.
0 comentarios
Ver también
Categorías
Más información sobre Linear and Nonlinear Regression en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!