# Fitting nonlinear curves and getting parameters

I have the following data $(s_i, t_i)$:

$s_i:$ -337.6 202.1 341 387 397.2

$t_i:$ 0.1 1.28 2.418 3.54 4.628

And also have the equation: $s_i= x - y*\exp(-t_i/z)$

How can I get those 3 parameters ($x,y$ and $z$) and fit the curve?

You don't get the parameters from the data, you get estimates of them.

Once you have them, to my mind you have already "fitted the curve". Do you mean something else, such as calculating the fitted values of $s_i$ ($\hat{s}_i$), or perhaps even displaying them?

How you get parameter estimates for a nonlinear equation depends on what you think about the conditional distribution of $s_i|t_i$, and on the dependence between the values.

If you felt that the variance of $s_i$ would be constant as $t_i$ changed*, and the values were independent, you could perhaps perform nonlinear least squares.

* However, with a function that asymptotes it's not uncommon for the variance to change, for example, in some cases getting smaller as asymptotes are approached, and in other cases growing when the mean grows. If you know something about how the distribution changes -- or at least how the spread changes -- with changing $t$, then that may suggest more suitable approaches. You might know this from theoretical considerations (such as the main ways noise/errors enter into the measurements) or from having seen similar studies with more data.

I agree with Mark's nonlinear least squares fit for your data. The fit looks like this:

(The tiny variation about the curve suggests that in this case it probably won't make much difference what approach you use to fit the curve, but with so few points some caution would be in order; you only have two df for error)

• The reason for the apparent discrepancy between our solutions for z is that you have actually solved for the reciprocal of z as defined in the question. I solved for z as defined. Commented Apr 5, 2016 at 17:38
• @Mark Thanks, I spotted it myself and corrected for it about 40 seconds before you posted the comment; since with the correction I had your answers I simply removed my fit -- there's no need to give it twice. Commented Apr 5, 2016 at 17:39

You can apply nonlinear least squares, among other possibilities. Here are the results I obtained, which correspond to a local optimum, which I think, but am not sure, is also the global optimum. The residuals are the LHS - RHS values for the 5 data points when using the fitted x, y, z.

fitted x = 401.8423
fitted y = 825.4560
fitted z = 0.9068
residuals = -0.1753    1.4766   -3.4767    1.8032    0.3722

I leave it to your determination whether this is a good fit, and whether these parameter values make sense. If there are constraints on the possible values of the parameters, you should have indicated so, and if these parameter values don't meet those constraints, then the constraints would need to be incorporated into a revised computation.

• See Glen_b's answer, posted just after mine, which in effect is a useful expansion of my first sentence. Also, to be clear, I performed unweighted, i.e., equally weighted, nonlinear least squares. Commented Apr 5, 2016 at 17:26