Best way to fit functionals with error bars
Show older comments
Hi,
I have the following expression for a rate coefficient
. For the purposes of this question, ρ is a smooth continous increasing function of E. I have values of k (with an error bar associated with them) for different values of E. I need to find the best fitting
that will fit the values i have (keeping into account the error bars). ρ does not have an analytical form, i need to find numerically compute it. So basically i have an array of ρ pre computed.
What is the best way to do this?
Thanks!
Answers (1)
Star Strider
about 3 hours ago
0 votes
That depends on what the error bars indicate, and the information you have about them.
A common way of weighting a regression (linear or nonlinear) is to use inverse variance weighting.. If you can extract the vairances from the error bars, then you can use this method. (This may involve inverting the t-distribution or normal distribution, or the distribution that describes them. A common criterion is to define them as the 95% confidence interval (2.5% to 97.5%), so use that as the default.)
Otherwise, an alternate (and to the best of my knowledge, unproven) method would be to use a function of the inverses of the error bar lengths.
5 Comments
Arun
23 minutes ago
Star Strider
11 minutes ago
I am not certain what you are asking.
If ρ does not have an analytic form although is something you can compute (I have no idea what its independnet variable would be), and knowing nothing more about it, one option sould be to interpolate it using the interp1 function, since I assume that it is a function of one (independent) variable. If it has more than one variable (for example one or more parameters), what you would do would depend on the ρ function itself. I have no idea what that is. You might still be able to interpolate it.
As a general rule, the least square estimation would go something like this --

where
is the known value,
is the regression estimate and a function of the independent variable and parameters, and
is the weighting value at that point.
Everything now depends on what ρ is, whether it has any parameters you might want to fit, and what you want to do with it.
I generally use the Statistics and Machine Learning or Optimization or Global Optimization Toolboxes for these sorts of problems.
.
Is there a function in these toolboxes that does the minimization of the least square estimate that you propose?
It depend on what constraints (if any) you want to apply. If you only intend to apply simple bounds on α and
, then fit() with a custom fittype would work. However, if you need more complicated constraints, you will need something like lsqcurvefit in the Optimization Toolbox.
Either way, the representation of
is not the issue. You would just use interpolation as mentioned but @Star Strider
rho=@(E) interp1(E_samp,rho_samp,E,'linear','extrap') %continuous rho()
Star Strider
4 minutes ago
'I need to find the best fitting
and α that will fit the values i have (keeping into account the error bars).'
This defines
and α as parameters to fit.
The sort of function I would use for this would be something like:
k_fcn = @(b,E) b(1).*rhofcn(E-b(2))./rhofcn(E);
with 'rhofcn' defined as @Matt J defined it above. (I call it 'rhofcn' for clarity, avoiding problems since 'rho' could be used for something else.) Here, 'b(1)' is α, and 'b(2)' is
. The independent variable is E.
You would then use 'k_fcn' as the objective function with lsqcurvefit or fitnlm. Use the weighting vector derived from the error bar values with it.
.
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!