fitting a curve

Thread Starter

chandimajaya85

Joined Sep 27, 2023
41
I have a dataset that I wanted to do non linear curve fit to it. dataset.png
Using two exponential, will that help for non linear curve fit. Any suggestions. Can anyone direct me why two exponential is being used for non linear curve fit. Any theory behind it. Thank you.\[ (Ɛ1 * (1 - exp(-(t / t1)))) + (Ɛ2 * (1 - exp(-(t /t2)))) \]
 

MrChips

Joined Oct 2, 2009
34,628
Curve fitting is both an art and a science.
You cannot expect to take an arbitrary equation and attempt to match it to an arbitrary data set.
The first part of the art is to try to recognize the trend of the data set and then try to use an appropriate model.
What you have shown is definitely not an exponential function. It looks more like a step function.

How would you model a step function?
Have a look at this:
https://en.wikipedia.org/wiki/Heaviside_step_function
 

wayneh

Joined Sep 9, 2010
18,088
I once modeled enzyme-catalyzed starch hydrolysis as a combination of two exponential reactions. The enzyme is a single molecule but the starch substrate is a complex milieu of molecules that are hydrolyzed at different rates depending on the length of the monomer chain, the degree of branching, and perhaps a bunch of other factors no one understands.

So why just two decay reactions to describe such a complex system? Because I could model the experimental data pretty well with just two, and didn't have data good enough to justify adding additional complexity to my model.

In essence I had two, first-order decay reactions happening in parallel. Note that this made sense for the reactions actually happening; first-order decay of substrate is a real thing. I was not trying to force some polynomial to fit without having any meaning behind it.

Something like 70% of the total reaction happened at a fast rate and the remainder at a much slower rate. That allowed for a rapid initial stage followed by a long, slow stage and that did a nice job of fitting my data. Your data looks a little bit similar, but I don't disagree with @MrChips assessment that you might be looking at a step function.
 

crutschow

Joined Mar 14, 2008
38,322
My old HP42s calculator has a curve fit function.
You put in the X-Y data points, and then it will determine the best curve fit for those points whether it is Linear, LOG, Exponential, or a Power function.
If interested, here is the app I use (since my physical 42s died), which exactly emulates the look and operation of the 42S (below from my Windows version).
There are versions for Android, Iphone, Windows, Mac, or Linux.


1710654072292.png
 

WBahn

Joined Mar 31, 2012
32,704
I have a dataset that I wanted to do non linear curve fit to it. View attachment 317790
Using two exponential, will that help for non linear curve fit. Any suggestions. Can anyone direct me why two exponential is being used for non linear curve fit. Any theory behind it. Thank you.\[ (Ɛ1 * (1 - exp(-(t / t1)))) + (Ɛ2 * (1 - exp(-(t /t2)))) \]
My first that when I see that data set is that it is a step response to a slightly underdamped second order system. So you might start there.
 

Ian0

Joined Aug 7, 2020
13,097
Excel and Libre Office have curve-fit functions.

But before you just randomly try every type of curve to see which fits best:
First, what type of curve ought to fit? (based on the system you are measuring and the usual relationship between the data sets)
What type of curve looks like it might fit? (Try squaring, square rooting, or taking the logarithm of each of the data sets to see if the resulting graph looks anything like a straight line)
 

Thread Starter

chandimajaya85

Joined Sep 27, 2023
41
Thank you for all of your reply. Here is a separate question from fitting. If I do two smoothing (moving average) on the data set before doing curve fit, will I loose original dataset values. Because of smoothing(curve fit).
 

BobTPH

Joined Jun 5, 2013
11,463
To me, it does look a lot like the exponential charging of a capacitor through a resistor.

i.e. something of the form:

k1 (1-e^-k2 t)

k1 and k2 being constants.

This ignores the oscillation just as the curve is turning, which looks like ringing in an RC charging circuit with a bit of inductance. That may be the second exponential mentioned. You might very well be on the right track.
 

WBahn

Joined Mar 31, 2012
32,704
Thank you for all of your reply. Here is a separate question from fitting. If I do two smoothing (moving average) on the data set before doing curve fit, will I loose original dataset values. Because of smoothing(curve fit).
Of course you will loose the original values -- there's no point in doing the smoothing, or any other operation, if you want to keep the original values. You are creating a new data set that is based on the original data set, but is not equal to the original data set. The fact that it is not the same means that there is data in the original set that is not present in the new set and/or data in the new set that is not in the original set. This is why you don't just blindly apply operations to the data, but instead need to give some thought as to how any manipulation of the data is going to affect the information contained within it, so that you retain and enhance the information you are interested in, while suppressing information that you aren't.
 

MrChips

Joined Oct 2, 2009
34,628
I try to use a model that makes sense with the physical phenomenon. If the rising part of that step function is truly of an exponential phenomenon, then yes, that would be an appropriate model.

I took issue with a manufacturer of industrial sensor instruments. They boasted in their brochure that they were applying a 7th-order polynomial to their sensor calibration. Of course, you can fit a 7th-order polynomial to any set of three data points. But, does the sensor actually exhibit a 7th-order polynomial functional relationship with the stimuli? You don't go to a higher order polynomial on the basis that it gives a better goodness of fit. In that particular case, a 3rd-order polynomial was more fitting (pun intended).

Edit: In other words, you do not want to model the data. You want to model the device that is producing the data.
 

WBahn

Joined Mar 31, 2012
32,704
I try to use a model that makes sense with the physical phenomenon. If the rising part of that step function is truly of an exponential phenomenon, then yes, that would be an appropriate model.

I took issue with a manufacturer of industrial sensor instruments. They boasted in their brochure that they were applying a 7th-order polynomial to their sensor calibration. Of course, you can fit a 7th-order polynomial to any set of three data points. But, does the sensor actually exhibit a 7th-order polynomial functional relationship with the stimuli? You don't go to a higher order polynomial on the basis that it gives a better goodness of fit.
Strongly second that -- in fact, if you use too high a polynomial, you can get very unstable and meaningless fits where the curve is very close to the data points but deviates wildly between them.
 

MrChips

Joined Oct 2, 2009
34,628
Off topic
With the same manufacturer and same instrument, we could not get the instrument to function properly in our equipment.
They were using a Microchip PIC MCU. I ended up disassembling and reverse engineering their embedded code. I found a couple of blatant errors in their code, improper usage of inputs that should have used the available Schmitt trigger inputs, and errors in their ISR.
 

Thread Starter

chandimajaya85

Joined Sep 27, 2023
41
To me, it does look a lot like the exponential charging of a capacitor through a resistor.

i.e. something of the form:

k1 (1-e^-k2 t)

k1 and k2 being constants.

This ignores the oscillation just as the curve is turning, which looks like ringing in an RC charging circuit with a bit of inductance. That may be the second exponential mentioned. You might very well be on the right track.
Thank you for reply. If the creeping increases with time, does the formula requires straight line (mt) term as well.So the equation would like this,

\[ ((Ɛ1∗(1−exp(−(t/t1))))+(Ɛ2∗(1−exp(−(t/t2)))) + mt) \]
 

wayneh

Joined Sep 9, 2010
18,088
Adding terms to a model is only justified when 1) Knowledge of the process informs what the relationship should look like. For instance in this case the apparent ringing might be modeled by an RLC treatment. Point is, the data and experience of others before you applies to the current problem, or 2) Your own data supports the additional term.

For #2 it's common to compare the value of the estimated coefficient to its standard error. If that ratio is greater than two, then the term is possibly significant.

See how your data is fit by the two exponentials and then see if the fit gets any better by adding the linear term. For any and every model you build, plot the residuals versus time and other inputs. A good model leaves no useful information hiding in the residuals - they should be random. If you don't know what that means, look up randomness testing.
 
Top