Background ||| Techie-Stuff ||| Instructions ||| Syntax Rules ||| Model Library

This page lets you fit any function of up to eight parameters to a set
of
data. Just specify the function, the data
points, and
initial guesses to the parameters. When you click the **Iterate**
button,
the JavaScript program refines these estimates to produce what should
be
a better set of parameters. This process is iterative, and with good
guesses
(and good luck) usually converges to the least squares solution in five
to
ten iterations. This program can also fit nonlinear
Least-Absolute-Value
curves and Percentile Curves (having a specified fraction of the points
below
the curve).

Simple **linear** curve fitting deals with functions that are **linear
in the parameters**, even though they may be **nonlinear in the
variables**. For example, a parabola *y=a+b*x+c*x*x* is a **nonlinear
function of x** (because of the *x*-squared term), but fitting
a parabola
to a set of data is a relatively simple **linear curve-fitting
problem
**because the parameters enter into the formula as simple multipliers
of
terms that are added together. Another example of a linear
curve-fitting
problem is *y= a+b*Log(x)+c/x*; the terms involve nonlinear
functions
of the independent variable *x*, but the parameters enter into
the formula
in a simple, linear way.

Unfortunately, many functions that arise in real world situations
are
**nonlinear in the parameters**, like the curve for exponential
decay
*y=a*Exp(-b*x)*, where *b* is "wrapped up" inside the
exponential
function. Some nonlinear functions can be linearized by transforming
the
independent and/or dependent variables. The exponential decay curve,
for
example, can be linearized by taking logarithms: *Log(y)=a'-b*x*
. The
*a'* parameter in this new equation is the logarithm of *a*
in
the original equation,so once *a' *has been determined by a
simple linear
curve-fit, we can just take its antilog to get *a*.

But we often encounter functions that cannot be linearized by any
such tricks,
a simple example being exponential decay that levels off to some
unknown
value: *y=a*Exp(-b*x)+c*. Applying a logarithmic transformation
in this
case produces *Log(y-c)=a'-b*x*. This linearizes *b*, but
now
*c* appears inside the logarithm; either way, we're stuck with an
intrinsically nonlinear parameter estimation problem, which is
considerably
more difficult than linear curve-fitting. That's the situation this web
page
was designed to handle.

For a more in-depth treatment of this topic, check out Dr. Harvey
Motulsky's
new web site: Curvefit.com -- a
complete
guide to nonlinear regression. Most of the information here is
excerpted
from *Analyzing Data with GraphPad Prism*, a book that
accompanies the
program *GraphPad Prism*. You can
download this book
as a pdf file.

Techie-stuff (for those who might be interested):

This page contains a straightforward, no-frills *JavaScript*
implementation
of the method of differential corrections, which involves expanding the
function
to be fitted in a Taylor series around current estimates of the
parameters,
retaining first-order (linear) terms, and solving the resulting linear
system
for incremental changes to the parameters. The program computes
finite-difference
approximations to the required partial derivatives, then uses a simple
elimination algorithm to invert and solve the simultaneous equations.
Central-limit estimates of parameter standard errors are obtained from
the
diagonal terms of the inverse of the normal equations matrix. The
covariance
matrix is computed by multiplying each term of the inverse normal
matrix
by the weighted error-variance. It is used to estimate parameter error
correlations and to compute confidence bands around the fitted curve.
These
show the uncertainty in the fitted curve arising from sampling errors
in
the estimated parameters, and do not include the effects of errors in
the
independent and dependent variables. The page also computes a
generalized
correlation coefficient, defined as the square root of the fraction of
total
*y* variance explainable by the fitted function.

Unequal weighting is accomplished by specifying the standard error
associated
with the *y* variable. Constant errors, proportional errors, or
Poisson
(square root) errors can be specified by a menu, and don't have to be
entered
with the data. Standard errors can also be entered along with the *x*
and *y* variables. Finally, replicate *y* measurements can
be entered;
the program will compute the average and standard error of the mean.

Also available are a number of simple variable transformations (log,
reciprocal,
square root), which might simplify the function to be fitted and
improve
the convergence, stability and precision of the iterative algorithm. If
a
transformation is applied to the *y* variable, the program will
adjust
the weights appropriately.

The page also fits least-absolute-value curves by applying an iterative reweighting scheme by which each point is given a standard error equal to the distance of that point from the fitted curve. An option allows differential weighting of above-curve points vs. below-curve points to achieve a specified split of points above and below the curve (a percentile curve fit).

No special goal-seeking methods, precision-preserving techniques (such as pivoting), convergence-acceleration, or iteration-stabilizing techniques (other than a simple, user-specified fractional adjustment), are used. This method may not succeed with extremely ill-conditioned systems, but it should work with most practical problems that arise in real-world situations.

The current implementation is limited to eight parameters and eight independent variables. These arbitrary limits could be increased without much trouble if necessary. I don't know what the maximum number of data points is; it's probably dependent on your browser's maximum string size, since the contents of the Data and Results windows are treated as large text strings. I've used this page to fit 500-point datasets with no problems.

The fields below are pre-loaded with a simple example: the
temperature of
a cup of water as it cools from boiling hot to room temperature over
the
course of an hour, being fit to Newton's Law of Cooling:

*Temp = ( T _{0} - T_{room} ) * Exp( - k * Time ) +
T_{room}*