Lab for Logistic Curve Fitting

Module for Logistic Curve Fitting

   Check out the new Numerical Analysis Projects page.

Background. Logistic curve fitting [Graphics:po.txtgr1.gif].

for the data points [Graphics:po.txtgr2.gif].

Rearrange the terms [Graphics:po.txtgr3.gif].

Take the logarithm of both sides: [Graphics:po.txtgr4.gif].

Introduce the change of variables: [Graphics:po.txtgr5.gif].

The previous equation becomes [Graphics:po.txtgr6.gif] which is now "linearized."

Use this change of variables on the data points [Graphics:po.txtgr7.gif],
i.e. same abscissa's but transformed ordinates in this case.

Now you have transformed data points: [Graphics:po.txtgr8.gif].

Use the "Fit" procedure get Y = A X + B, which must match the form Y = ln(c) + a X so you see that [Graphics:po.txtgr9.gif] 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".

[Graphics:po.txtgr11.gif][Graphics:po.txtgr10.gif]
 
 
 

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 [Graphics:po.txtgr12.gif] 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 !

[Graphics:po.txtgr11.gif][Graphics:po.txtgr13.gif]

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 [Graphics:po.txtgr14.gif] are not complex numbers. We choose L = 500, i.e. let's hope it doesn't get too crowded.

[Graphics:po.txtgr11.gif][Graphics:po.txtgr15.gif]

Do a series of intermediate computations.

[Graphics:po.txtgr11.gif][Graphics:po.txtgr16.gif]
[Graphics:po.txtgr11.gif][Graphics:po.txtgr17.gif]

Now glue together the transformed parts to form the pairs [Graphics:po.txtgr18.gif].

[Graphics:po.txtgr11.gif][Graphics:po.txtgr19.gif]
[Graphics:po.txtgr11.gif][Graphics:po.txtgr20.gif]

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!)

[Graphics:po.txtgr11.gif][Graphics:po.txtgr21.gif]
[Graphics:po.txtgr11.gif][Graphics:po.txtgr22.gif]

Plot the least squares line in XY space.

[Graphics:po.txtgr11.gif][Graphics:po.txtgr23.gif]

[Graphics:po.txtgr11.gif][Graphics:po.txtgr24.gif]

[Graphics:po.txtgr11.gif][Graphics:po.txtgr25.gif]

For expert Mathematica users ! How are formulas really stored ? What is the data structure ?

[Graphics:po.txtgr11.gif][Graphics:po.txtgr26.gif]
[Graphics:po.txtgr11.gif][Graphics:po.txtgr27.gif]

So the coefficients A and B are located at nodes (2,1) and (1), respectively:

[Graphics:po.txtgr11.gif][Graphics:po.txtgr28.gif]
[Graphics:po.txtgr11.gif][Graphics:po.txtgr29.gif]
[Graphics:po.txtgr11.gif][Graphics:po.txtgr30.gif]

Use [Graphics:po.txtgr31.gif] and a = A to get the coefficients of [Graphics:po.txtgr32.gif] back in the original xy plane.

[Graphics:po.txtgr11.gif][Graphics:po.txtgr33.gif]
[Graphics:po.txtgr11.gif][Graphics:po.txtgr34.gif]
[Graphics:po.txtgr11.gif][Graphics:po.txtgr35.gif]

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.txtgr11.gif][Graphics:po.txtgr36.gif]
[Graphics:po.txtgr11.gif][Graphics:po.txtgr37.gif]
[Graphics:po.txtgr11.gif][Graphics:po.txtgr38.gif]

[Graphics:po.txtgr11.gif][Graphics:po.txtgr39.gif]

[Graphics:po.txtgr11.gif][Graphics:po.txtgr40.gif]

Now get those predictions, based on the mathematical model [Graphics:po.txtgr41.gif].

[Graphics:po.txtgr11.gif][Graphics:po.txtgr42.gif]
[Graphics:po.txtgr11.gif][Graphics:po.txtgr43.gif]
[Graphics:po.txtgr11.gif][Graphics:po.txtgr44.gif]
[Graphics:po.txtgr11.gif][Graphics:po.txtgr45.gif]
 
 

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 [Graphics:po.txtgr46.gif] 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:

[Graphics:po.txtgr11.gif][Graphics:po.txtgr47.gif]
[Graphics:po.txtgr11.gif][Graphics:po.txtgr48.gif]

Use the following initial guesses for Mathematica's FindMinimum subroutine.
Note that A and B and L0 are the values from Exercise 1.

[Graphics:po.txtgr11.gif][Graphics:po.txtgr49.gif]
[Graphics:po.txtgr11.gif][Graphics:po.txtgr50.gif]
[Graphics:po.txtgr11.gif][Graphics:po.txtgr51.gif]
[Graphics:po.txtgr11.gif][Graphics:po.txtgr52.gif]

Form the quantity to be minimized.

[Graphics:po.txtgr11.gif][Graphics:po.txtgr53.gif]
[Graphics:po.txtgr11.gif][Graphics:po.txtgr54.gif]

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.

[Graphics:po.txtgr11.gif][Graphics:po.txtgr55.gif]
[Graphics:po.txtgr11.gif][Graphics:po.txtgr56.gif]

If you are curious if Mathematica found L, then check it out using 19 decimal places.

[Graphics:po.txtgr11.gif][Graphics:po.txtgr57.gif]
[Graphics:po.txtgr11.gif][Graphics:po.txtgr58.gif]

Now go back and substitute these into f(x), get a new mathematical model that we shall call f2(x).

[Graphics:po.txtgr11.gif][Graphics:po.txtgr59.gif]
[Graphics:po.txtgr11.gif][Graphics:po.txtgr60.gif]

Make the predictions using the new function [Graphics:po.txtgr61.gif].

[Graphics:po.txtgr11.gif][Graphics:po.txtgr62.gif]
[Graphics:po.txtgr11.gif][Graphics:po.txtgr63.gif]
[Graphics:po.txtgr11.gif][Graphics:po.txtgr64.gif]
[Graphics:po.txtgr11.gif][Graphics:po.txtgr65.gif]

This values are close to that obtained in Exercise 1.

[Graphics:po.txtgr11.gif][Graphics:po.txtgr66.gif]

[Graphics:po.txtgr11.gif][Graphics:po.txtgr67.gif]

[Graphics:po.txtgr11.gif][Graphics:po.txtgr68.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.

[Graphics:po.txtgr11.gif][Graphics:po.txtgr69.gif]
[Graphics:po.txtgr11.gif][Graphics:po.txtgr70.gif]
[Graphics:po.txtgr11.gif][Graphics:po.txtgr71.gif]
[Graphics:po.txtgr11.gif][Graphics:po.txtgr72.gif]
[Graphics:po.txtgr11.gif][Graphics:po.txtgr73.gif]
[Graphics:po.txtgr11.gif][Graphics:po.txtgr74.gif]
[Graphics:po.txtgr11.gif][Graphics:po.txtgr75.gif]
[Graphics:po.txtgr11.gif][Graphics:po.txtgr76.gif]
 
 

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