curve fitting - how to graph error in parameters from polynomial fit - MATLAB -


i have list of data trying fit polynomial , trying plot 95% confidence bands parameters (in matlab). if data x , y

f=fit(x,y,'poly2') plot(f,x,y) ci=confint(f,0.95); a_ci=ci(1,:); b_ci=ci(2,:); 

i not know how proceed after minimum , maximum band around data. know how that?

i can see have curve fitting toolbox installed, good, because need following code work.

basic fit of example data

let's define example data , possible fit function. (i have used poly2 here, wanted keep bit more general.)

xdata = (0:0.1:1)';               % column vector! noise = 0.1*randn(size(xdata)); ydata = xdata.^2 + noise; f = fittype('a*x.^2 + b');  fit1 = fit(xdata, ydata, f, 'startpoint', [1,1]) plot(fit1, xdata, ydata) 

side note: plot() not our usual plot function, method of cfit-object fit1.

enter image description here

confidence intervals of fitted parameters

our fit uses data determine coefficients a,b of underlying model f(x)=ax2+b. did this, completeness here how can read out uncertainty of coefficients confidence interval. coefficients alphabetically ordered, why can use ci(1,:) a, , on.

names = coeffnames(fit1)   % check coefficient order! ci = confint(fit1, 0.95);  % 2 sigma interval a_ci = ci(1,:) b_ci = ci(2,:) 

by default, matlab uses 2σ (0.95) confidence intervals. people (physicists) prefer quote 1σ (0.68) intervals.

confidence , prediction bands

it's habit plot confidence bands or prediction bands around data – when coefficients correlated! should take moment think 1 of 2 want plot:

  • prediction band: if take new measurement value, expect lie? in matlab terms, called “observation band”.
  • confidence band: expect true value lie? in matlab terms, called “functional band”.

as coefficient’s confidence intervals, matlab uses 2σ bands default, , physicists among switch 1σ intervals. nature, prediction band bigger, because combination of error of model (the confidence band!) , error of measurement.

there destinction make, 1 don’t understand. both matlab , wikipedia make distinction.

  • pointwise: how big prediction/confidence band single measurement/true value? in virtually cases can think of, want ask physicist.
  • simultaneous: how big have make prediction/confidence band if want set of new measurements/all prediction points lie within band given confidence?

in personal opinion, “simultaneous band” not band! measurement n points, should n individual error bars!

the prediction/confidence distinction , pointwise/simultaneous distinction give total of 4 options “the” band around plot. matlab makes 2σ pointwise prediction band accessible, seem interested in 2σ pointwise confidence band. bit more cumbersome plot, because have specify dummy data on evaluate prediction band:

x_dummy = linspace(min(xdata), max(xdata), 100); figure(1); clf(1); hold plot(xdata,ydata,'.') plot(fit1)    % default, evaluates fit on currnet xlim % use "functional" (confidence!) band; use "simultaneous"=off conf1 = predint(fit1,x_dummy,0.95,'functional','off'); plot(x_dummy, conf1, 'r--') hold off 

enter image description here

note confidence band @ x=0 equals confidence interval of fit-coefficient b!

extrapolation

if want extrapolate x-values not covered range of data, can evaluate fit , prediction/confidence band bigger range:

x_range = [0, 2]; x_dummy = linspace(x_range(1), x_range(2), 100); figure(1); clf(1); hold plot(xdata,ydata,'.') xlim(x_range) plot(fit1) conf1 = predint(fit1,x_dummy,0.68,'functional','off'); plot(x_dummy, conf1, 'r--') hold off 

enter image description here


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -