Do error bars affect confidence intervals?

16 views (last 30 days)
Luca Italiano
Luca Italiano on 17 Jun 2021
Commented: Luca Italiano on 17 Jun 2021
Hello, I'm working on a lab for my physics class which involves using the Curve Fitting Toolbox to graph an exponential function, a*exp^(bx). The Toolbox states the confidence interval for the parameter b, but when I use the errorbar function in the code of the fit, it doesn't seem to change the confidence intervals, even though I would expect them to be larger with the presence of additional uncertainty. I was wondering if I am doing something wrong in my method of putting in the error bars, or if confidence intervals simply don't have anything to do with error bars?
I'm still relatively inexperienced in Matlab and any help would be appreciated :)
Here's the code used for this part (generated by the Curve Fitting Tool for the most part, but I added the hold on/hold off and the errorbar line):
%% Fit: 'untitled fit 1'.
[xData, yData] = prepareCurveData( A, P );
% Set up fittype and options.
ft = fittype( 'exp1' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [4725487761.40816 -2272.44216041827];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( 'Name', 'untitled fit 1' );
hold on
h = plot( fitresult, xData, yData );
errorbar(A, P, dP, dP, dA, dA, '.');
legend( h, 'P vs. A', 'untitled fit 1', 'Location', 'NorthEast', 'Interpreter', 'none' );
hold off
% Label axes
xlabel( 'A', 'Interpreter', 'none' );
ylabel( 'P', 'Interpreter', 'none' );
grid on

Answers (1)

Scott MacKenzie
Scott MacKenzie on 17 Jun 2021
Edited: Scott MacKenzie on 17 Jun 2021
You note:
when I use the errorbar function in the code of the fit, it doesn't seem to change the confidence intervals
The errorbar function has nothing to do with fit or with confidence intervals computed by functions such as fit. It simply adds errorbars to the plot. The magnitude of the errorbars is determined by the values you pass in to the errorbar function. In your code, the values are dP and dA (for which the assigned values aren't shown).
  3 Comments
Scott MacKenzie
Scott MacKenzie on 17 Jun 2021
I'm not sure what to suggest. Bear in mind that the confidence intervals produced by fit are confidence intervals for the model coefficients, not for predictions produced by the model. Usually when plotting predictions, the confidence intervals for the predictions are shown as a band around the curve, not through errorbars. I suggest you review the writeup on Confidence and Prediction Bounds for the Curve Fitting Toolbox, where all this is explained. Good luck.

Sign in to comment.

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!