![]()
![]()
Lab for Logistic Curve Fitting
![]()
Background.
Logistic curve fitting
.
for the data points
.
Rearrange the terms
.
Take the logarithm of both sides:
.
Introduce the change of variables:
.
The previous equation becomes
which is now "linearized."
Use this change of variables on the data points
,
i.e. same abscissa's but transformed ordinates in this case.
Now you have transformed data points:
.
Use the "Fit" procedure get Y = A X + B, which must match the form Y
= ln(c) + a X so you see that
and a = A.
Remark 1. For the first method
of "data linearization" we must know the constant L in advance. Since
L is the "limiting population" for the "S" shaped logistic curve, a
value of L that is appropriate to the problem at hand can usually be
obtained by guessing.
Remark 2. The purpose of the
second exercise it to use true least squares techniques to find the
curve. The computer will find A, B, and L using the second
method.
Load in Mathematica's graphics package "Colors".
Report to be handed in.
Computer Exercises
Exercise 1. Use the method of
"data linearization" to find the logistic curve that fits the data
for the population of the U.S. for the years 1900-1980. Fit the curve
to the data points
(1900, 76.1), (1920, 106.5), (1940, 132.6), (1960, 180.7), (1980,
226.5)
which are the census figures for the population of the U.S.
Solution. Enter the data points into a two dimensional array. Be careful with your typing !
Next, a limiting population L, or "carrying capacity" must be
estimated. For this data the number L is not too sensitive, but must
be larger than the largest ordinate so that the values
are not complex numbers. We choose L = 500, i.e. let's hope it
doesn't get too crowded.
Do a series of intermediate computations.
Now glue together the transformed parts to form the pairs
.
Now use the Mathematica procedure Fit to get the least squares line in XY space. Then we shall graph this line in the transformed XY plane. (One of the questions!)
Plot the least squares line in XY space.
![]()
![[Graphics:po.txtgr24.gif]](po.txtgr24.gif)
For expert Mathematica users ! How are formulas really stored ? What is the data structure ?
So the coefficients A and B are located at nodes (2,1) and (1), respectively:
Use
and a = A to get the coefficients of
back in the original xy plane.
When we form the function, we must adjust "x" because we shifted the abscissas to the left. The actual form of the answer is a little different than what we original planned.
![]()
![[Graphics:po.txtgr39.gif]](po.txtgr39.gif)
Now get those predictions, based on the mathematical model
.
Remark. The transformation does not really minimize the sum of the squares of the error, so we try to stay away from the terminology "least squares" and use some other terminology such as "data linearization." There is a difference and the minimization of the nonlinear least squares problem is hard. We would have to use Mathematica's built in FindMinimum procedure. The next exercise shows how to do the previous computations using this powerful subroutine.
Exercise 2. Use the method of
"least squares" to find the logistic curve that fits the data for the
population of the U.S. for the years 1900-1980. This answer is not
the same as the one in Exercise 1, but it is close. Fit the
curve
to the data points
(1900, 76.1), (1920, 106.5), (1940, 132.6), (1960, 180.7), (1980,
226.5)
which are the census figures for the population of the U.S.
Solution. Use the same points
we used above.
We want the objective function to look like:
Use the following initial guesses for Mathematica's
FindMinimum subroutine.
Note that A and B and L0 are the values from Exercise 1.
Form the quantity to be minimized.
The quantities a, c and L are to be found which make sum2 a
minimum.
The values a0, c0 and L0 are the starting values and must be close to
the unknown values.
If you are curious if Mathematica found L, then check it out using 19 decimal places.
Now go back and substitute these into f(x), get a new mathematical model that we shall call f2(x).
Make the predictions using the new function
.
This values are close to that obtained in Exercise 1.
![]()
![[Graphics:po.txtgr67.gif]](po.txtgr67.gif)
Exercise 3. Use the solutions
in Exercises 1 and 2 to predict the following:
3 (a). Estimate the population in
1990.
3 (b). Estimate the population in
2000.
Exercise 4. Go to the library
reference desk and get the book of 1990 US census facts.
Look up the 1990 census figure. How close was your predictions in
problem 3 a ?
Questions to consider. Which method: "data linearization" or "least squares" requires the more sophisticated numerical method ? Which requires more computing time ? Which solves the problem better ? Which one do you trust ?
![]()
![]()
(c) John H. Mathews, 1998