How can I force a double exponential (with x offset) to asymptote at a constant?

I have hundreds of files, each with hundreds of curves that need to be fit. I know from the physical properties of the system I'm studying that I'm looking at a double exponential decay function, the asymptote of which is a constant -- in fact the point of doing the fit is to determine the value of the constant. However, sometimes the data are noisy and the fits do strange things.

I'd like a way to force the fit to asymptote to a (as of yet undetermined) constant y value (i.e. a horizontal asymptote).

I've read all I can under DisplayHelpTopic "CurveFit" but the only constraints I see are constraints for coefficients and the X0 value, none of which I know a priori.

So, is there a way to constrain the asymptote to some constant?
Neurons wrote:
So, is there a way to constrain the asymptote to some constant?


From the perspective of your fitting procedure your constant is a variable, right? Fitting is jiggling a variable/s until some maximization condition between the analytical fit function and the data is satisfied.

So just try to fit your double exponential and look in the resulting fit coefficients for the "constant" coef.
Actually, it may help you if you write the fit function yourself. The "new fit function" wizard is quite helpful. The fit function is recorded and compiled in the procedure window (to invoke this window under Windows: ctrl+m)

best,
_sk
I do NOT believe that you really want to force the asymptote. I believe that you need to allow it to vary. Then, you need to analyze the results over the hundreds of curves to determine the best value of the constant.

When this is true, I see it being done in two frameworks: first, with regard to using the best practices to do complete (correct, adequate, proper) engineering data analysis; second, with regard to taking the best approach using Igor Pro.

To make the discussion easy, assume that you only have one coefficient C to fit (the asymptote value).

On the data analysis side, I see two approaches. One is to obtain the fitting coefficient and its uncertainty for each of your hundreds of files. After that, analyze the set of hundreds of fitting coefficients to obtain the weighted average and weighted standard uncertainty of the mean. Report the value and its uncertainty as the representative value for the entire set of hundreds of curves. The second approach is to analyze the hundreds of curves all at once. The result will be a single fitting coefficient and its standard uncertainty to represent the entire data set.

On the Igor Pro side, either of the above is doable. The first involves the use of a fitting function and initially the grunt work to churn through (manually) hundreds of curves. Streamlining this step is done by writing a global function to loop through a set of data folders, pick the wave, fit it, and store the results. The end result is a set of hundreds of fitting coefficients and their uncertainties. Do the subsequent weighted average and weighted standard uncertainty of the mean analysis. The second involves writing an all at once fitting function. Feed that function your hundreds of curves (concatenated together in one long wave). The result will be one coefficient and its uncertainty to represent the entire data set.

To recap ...

* Fit the hundreds of curves one at a time. Obtain C ± \Delta C for each curve. Calculate a weighted mean and weighted standard uncertainty of the mean <\Delta C>.

* Fit the hundreds of curves all at once. Obtain C ± \Delta C for the entire data set.

Either approach is valid. The first is easier to set up in Igor Pro but requires some grunt work. The second is more difficult to set up in Igor Pro but avoids the weighted mean and weighted standard uncertainty calculations.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
To clarify, the constraints available for the dblexp_XOffset CurveFit, function are y0, A1, tau1, A2, and tao2. None of them are the asymptote, or this would be easy, since I've already written a loop to analyze each curve, though I only want to store the values for those fits that are reliable (i.e. those fits whose asymptote is a constant. An oblique asymptote indicates the fit is inaccurate). I also can't average all the curves together, because the entire point of this exercise is to measure changes in variables that are calculable based on the fit values (including the asymptote, which is not returned in the CurveFit function).
HJDrescher wrote:
If you are looking for an asymptote which is constant (horizontal): it is y0.
HJ



If both taos are greater than zero, then the asmptote will equal y0. However, when I try to constrain both taos to > 0, I get an error message that reads:

**** Singular matrix error during curve fitting ****
There may be no dependence on these parameters:
[2]
Neurons wrote:
HJDrescher wrote:
If you are looking for an asymptote which is constant (horizontal): it is y0.
HJ



No, y0 is the value of y when x=0. The horizontal asymptote is the value of y when x =∞

Or, more accurately, the horizontal asymptote is the limit as x approaches ∞ of y = y0+A1*exp(-(x-x0)/tao1)+A2*exp(-(x-x0)/tau2).


Errr...
My understanding of the math is that...
if x=x0 (and tau is non-zero) then x-x0 = 0 and hence the terms exp(-(x-x0)/tau) = 1, and hence y = y0 + A1 + A2.
... and as HJ said,
if x =∞ (and tau is finite) then the terms exp(-(x-x0)/tau) = 0 and hence y = y0.

Putting my understanding of the math to one side, if you cast your fit equation in terms of your fit parameters AND include the asymptote as one of these parameters, then you can fit you data to this new function and simply extract the asymptote as desired.

Good luck,
Kurt

Neurons wrote:
To clarify, the constraints available for the dblexp_XOffset CurveFit, function are y0, A1, tau1, A2, and tao2. None of them are the asymptote, or this would be easy, since I've already written a loop to analyze each curve, though I only want to store the values for those fits that are reliable (i.e. those fits whose asymptote is a constant. An oblique asymptote indicates the fit is inaccurate). I also can't average all the curves together, because the entire point of this exercise is to measure changes in variables that are calculable based on the fit values (including the asymptote, which is not returned in the CurveFit function).


Admittedly, I approached the analysis somewhat askew. My mistake was in not understanding the function for the double exponential and the placement of the asymptote term. Aside from whether one of the fitting parameters is or is not the asymptote (and, as others are now suggesting, whether it can or cannot be incorporated in to the fit equation to extract it), something in what you keep saying is entirely amiss.

"An oblique asymptote indicates the fit is inaccurate".

This result would indicate to me that I have an insufficient range of data to have the last point reach within a specific range of y when x -> infinity. The final value of y(x->infinity) could be perfectly accurate. It is however unspecified to an acceptable degree of confidence.

IOW, the results you state are not demonstrating anything about inaccuracy, they are demonstrating the degree of imprecision.

What happens when you plug the fit constants back in the double exponential equation and extrapolate to get y(x->infinity)? Do you not get a value? Why do you think that value should be discarded from the analysis set? What statistical test have you done to substantiate your "gut feeling" or "subjective decision"? What do you get when you use linear propagation of uncertainty principles to determine the equation for \Delta y as a function of the other uncertainties, plug back in the uncertainty values, and get y(x->infinity) ± \Delta y(x->infinity) _from first principles_?

Along a different line of thinking, I would have to wonder about the rigor in using an asymptote value to discard data sets. How do you really know that your data does or does not have an offset? How do you know the value of that offset does or does not vary from experiment to experiment? I understand the basic strategy ... set a parameter that can be used to discard data sets. But in this case, rather than the asymptote value itself, perhaps you would do better to look at the slope of the fit curve at the final data point in your measurement set. Regardless of whether the data set is offset from zero in the asymptote, the slope at x->infinity must identically be zero. Set a tolerance value on the slope at x(final measured value) being close to zero. Use this to discard data sets. Just do not argue a case for this as a way to discard "inaccurate" data sets. Rather, argue the case for discarding data sets because they have an insufficient extent that correspondingly leads to an unacceptably high imprecision (too low confidence) in the overall fit.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
jjweimer wrote:
How do you really know that your data does or does not have an offset? How do you know the value of that offset does or does not vary from experiment to experiment? I understand the basic strategy ... set a parameter that can be used to discard data sets. But in this case, rather than the asymptote value itself, perhaps you would do better to look at the slope of the fit curve at the final data point in your measurement set. Regardless of whether the data set is offset from zero in the asymptote, the slope at x->infinity must identically be zero. Set a tolerance value on the slope at x(final measured value) being close to zero. Use this to discard data sets. Just do not argue a case for this as a way to discard "inaccurate" data sets. Rather, argue the case for discarding data sets because they have an insufficient extent that correspondingly leads to an unacceptably high imprecision (too low confidence) in the overall fit.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH



I know there is an offset on both curves because of the nature of the physical system under study. An oblique asymptote would suggest basic laws of physics are being violated, so it is more likely the fit is inaccurate given the noise and occasional aberrations in the recordings.
Neurons wrote:
jjweimer wrote:
How do you really know that your data does or does not have an offset?


I know there is an offset on both curves because of the nature of the physical system under study. An oblique asymptote would suggest basic laws of physics are being violated, so it is more likely the fit is inaccurate given the noise and occasional aberrations in the recordings.


I suspect this discussion will go around in circles about the concepts of confidence levels on fitting parameters and the commensurate meanings they convey about accuracy or precision in results. In short, the ONLY WAY I can accept your statement to use an abnormal fitting result as a metric of inaccuracy is when you would also tell me, your measurement instrument is not calibrated. Otherwise, this analysis remains for me a metric of the precision NOT as a metric of accuracy.

By analogy perhaps ...

I can throw a ball at a bucket. The closer I stand, the more often I will hit the bucket. The further away I stand, the less often I will hit the bucket. BUT SOMETIMES I MAY JUST HAPPEN TO THROW THE BALL AROUND THE WORLD AND ACTUALLY HAVE IT LAND IN THE BUCKET!!!!

You are reducing the data range of the fit along x. You are moving further away from the bucket. You are less likely to hit it. That is a metric of lower PRECISION. It is NOT a metric of lower accuracy.

And we have not even inquired about whether Larry Bird could repeat the experiments and do better (be MORE PRECISE) than both of us. :-)

Also, I am NOT talking about an offset in X, the independent parameter. I am talking about an offset in Y, the DEPENDENT PARAMETER.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
Actually, I don't see a way an oblique asymptote could arise in a double exponential fit. If you really want to test for it, add another linear (quadratic, etc.; see comment part below) term to the manually created fit function and subsequently check whether the coefficients differ from zero (or an epsilon value).

The error message you get is typical for dependent variables:
y = y1+A1*exp(-(x-x0)/tau1)+y2+A2*exp(-(x-x0)/tau2) // +v_m*x + v_n*x^2
since an offset y0 can be arbitrarily distributed to y1 and y2.

HJ
To second the above comment ... What exactly do you mean by "oblique asymptote" anyway?

Perhaps you might post a MWE (minimum working example). A graph that shows a fitting result that is correct as you think it should be and a fit that you believe is inaccurate because it has an oblique asymptote would be useful to see.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
In answer to the problem with constraints: You really can't set the constraint exactly at zero. Use a value that is positive, but smaller than anything likely to be a solution. This is described here: DisplayHelpTopic "Constrained Curve Fitting Pitfalls". That situation is described under "Bad Values on the Constraint Boundary".

Perhaps you are trying to fit action potentials having opposite signs for the two exponential terms. In that case, our auto guessing algorithm fails. You must use manual guesses. The Graph Now button in the Curve Fitting dialog can be helpful.

It might also be helpful to post an Igor experiment file containing an example of your data and a fit that seems bad to you.

When I answered your question sent to tech support, I didn't mention that double exponentials can be very tricky to fit. If the decay constants are similar (that would mean closer than an order of magnitude) a double exponential fit can have a lot of trouble distinguishing the two decays. To test for that problem, you need the fit correlation matrix. To generate the matrix, ask the curve fit to generate the covariance matrix- add /M=2 flag to the CurveFit command or turn on the Covariance Matrix checkbox in the dialog on the Output Options tab. Then post-process the matrix:
Duplicate M_Covar, CorMat    // You can use any name instead of CorMat
CorMat = M_Covar[p][q]/sqrt(M_Covar[p][p]*M_Covar[q][q])

If any off-diagonal elements are close to 1 or -1 you have a problem. By "close" I mean values like 0.99. Usually 0.90 is OK, but could be a problem.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com