How to graph error in parameters from polynomial correspondence - MATLAB

I have a list of data that I am trying to adapt to polynomial, and I am also trying to build 95% confidence ranges for the parameters (in Matlab). If my data is x and y

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

I do not know how to proceed after this to get the minimum and maximum band around my data. Does anyone know how to do this?

+5
source share
1 answer

I see that you have the curve snap tool installed, which is good because you need the following code to work.

Basic fitting of sample data

Let me define some sample data and a possible correspondence function. (I could also use poly2 here, but I would like to keep it a little 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() is not our usual chart function, but the fit1 cfit object method.

enter image description here

Confidence Intervals for Established Parameters

Our fit uses the data to determine the coefficients a , b base model f(x)=ax2+b . You have already done this, but for completeness you can read the uncertainty of the coefficients for any confidence interval here. The coefficients are sorted alphabetically, so I can use ci(1,:) for a , etc.

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

By default, Matlab uses confidence intervals of 2σ (0.95). Some people (physicists) prefer to quote intervals of 1σ (0.68).

Trust and forecast groups

It's a good habit to build confidence bands or forecast bands around data - especially when the odds are correlated! But you should think about which of the two you want to build:

  • Forecast group . If I take a new dimension value, where do I expect it to lie? In terms of Matlab, this is called a “surveillance zone”.
  • Trust group . Where can I expect the true value to be false? In terms of Matlab, this is called a “functional group”.

As in the case of confidence intervals of coefficients, Matlab uses 2σ bands by default, and physicists among us switch this to 1σ intervals. By its nature, the prediction band is larger because it is a combination of model error (confidence band!) And measurement errors.

There is another difference that I do not fully understand. Both Matlab and Wikipedia make this distinction .

  • Pointwise : how large is the prediction / confidence band for one dimension / true value? In almost all cases that I can think of, this is what you would like to ask as a physicist.
  • Simultaneous . How big is your team to make a forecast / confidence range if you want a set of all new dimensions / all prediction points to lie within the range with some certainty?

In my personal opinion, a “simultaneous group” is not a group! To measure with n points, there must be n separate error scales!

Prediction / confidence differences and pointwise / simultaneous differences give you a total of four “strip” options around the plot. Matlab simplifies access to the 2.10 stream prediction range, but what seems interesting to you is the 2σ point-to-point confidence range. This bit is more cumbersome to plot, because you must specify dummy data by which you can estimate the prediction range:

 x_dummy = linspace(min(xdata), max(xdata), 100); figure(1); clf(1); hold all plot(xdata,ydata,'.') plot(fit1) % by default, evaluates the fit over the 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 that the confidence band at x=0 is equal to the confidence interval of the landing coefficient b !

Extrapolation

If you want to extrapolate to x values ​​that are not covered by the range of your data, you can evaluate the fit and the prediction / confidence range for a larger range:

 x_range = [0, 2]; x_dummy = linspace(x_range(1), x_range(2), 100); figure(1); clf(1); hold all 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

+5
source

All Articles