Lecture 17 Math 221 

Least Squares Application to Logistic Equations 

 

Another common occurance in the physical world is when the rate of change of a quanity is directly proportional to the amount present.  This occurs in many biological problems and in the radio-active decay of material.  The above relationship can be modeled by a differential equation 

                                                    Typesetting:-mrow(Typesetting:-mi(   

If we separate variables and then integrate we obtain the relationship between the variable y and t. 

 

Typesetting:-mrow(Typesetting:-mi(  or   Typesetting:-mrow(Typesetting:-mi(  which given ln(y)=kt +c .  By raising both sides to the power e we  arrive at the logistic equation.  Typesetting:-mrow(Typesetting:-mi(  or y = Typesetting:-mrow(Typesetting:-mi(  which can be written as  

Typesetting:-mrow(Typesetting:-mi(.  The last equation is the usual starting point of the logistic equation.  Here we need to find the value b and the constant of proportionality k.   We are at an advantage from our development because we can back up to the equation ln(y) = kt +c.  If we set Typesetting:-mrow(Typesetting:-mi( then the equation becomes a linear relationship between Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi( and t. l.e. Typesetting:-mrow(Typesetting:-mi(.  At this point we are back to the problem that we studied in the linear least squares problem.    

 

 

Example 

Consider the following data set (1,5.10),(1.25,5.79),(1.50,6.53),(1.75,7.45),(2.00,8.45).  We are assuming that we know the date is to fit the logistic equation of the form above.  Instead of starting with the equation Typesetting:-mrow(Typesetting:-mi( we will start with tye equation ln(y)=kt +c or Typesetting:-mrow(Typesetting:-mi( .   

The first thing that we need to do is to take the log of each of the dependent variables.   

Let us made a table  

Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi(          1.00     1.25      1.50     1.75     2.00 

Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi(          5.10     5.79      6.53     7.45     8.46 

ln(Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi()     1.629    1.756    1.876   2.008   2,135 

We will now go to Maple to finish the problem 

 

> with(LinearAlgebra):
 

> t:=<1.00,1.25,1.50,1.75,2.00>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> y:=<5.10,5.79,6.53,7.45,8.46>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> y1:=<ln(y[1]),ln(y[2]),ln(y[3]),ln(y[4]),ln(y[5])>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> ones:=<1,1,1,1,1>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> A:=<ones|t>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

>
 

> X:=<c,k>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> A.X =y1;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> ATA:=A^%T.A;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> ATY:=A^%T.y1;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> XS:=BackwardSubstitute(GaussianElimination(<ATA|ATY>));
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> c:=XS[1];
 

1.12248919140000436
 

> k:=XS[2];
 

.505719603199997092
 

The only problem we have is that we would like to write the equation as Typesetting:-mrow(Typesetting:-mi( and we have  

found c instead of b.  b = Typesetting:-mrow(Typesetting:-msup(Typesetting:-mo( so we need to take the exp(c). 

 

> b:=exp(c);
 

3.072492714
 

We can plot the data points and then we can plot the equation.  They can be plotted on the same graph.  We will look at how to plot the points first.   

 

 

> plot([[t[1],y[1]],[t[2],y[2]],[t[3],y[3]],[t[4],y[4]],[t[5],y[5]]],style=POINT);
 

Plot_2d
 

> with(plots):
 

By using the semilog plot that follows we can now see the linear relationship between the data points.  This is scaling the dependent values in a different manner than before .  There was semi-log paper and log-log paper that you could use to do the plotting.  Now most of this is done on the computer by using the commands like the following.   

> logplot([[t[1],y[1]],[t[2],y[2]],[t[3],y[3]],[t[4],y[4]],[t[5],y[5]]],style=POINT);
 

Plot_2d
 

>
 

We now have our logistic equation for this set of data.  

Typesetting:-mrow(Typesetting:-mi(.    

 

We would now like to plot the data and the graph all on one graph.  The origional data not the the semi log plots.  We will need to set up different plots commands so that they can be combined into one plot.  I use the command like in your text and call them data_list. 

 

  

> data_list:=[[t[1],y[1]],[t[2],y[2]],[t[3],y[3]],[t[4],y[4]],[t[5],y[5]]];
 

[[1.00, 5.10], [1.25, 5.79], [1.50, 6.53], [1.75, 7.45], [2.00, 8.46]]
 

> formula:=b*exp(k*tt);
 

`+`(`*`(3.072492714, `*`(exp(`+`(`*`(.505719603199997092, `*`(tt)))))))
 

> CurvePlot:=plot(formula,tt=1..2):
 

> PointPlot:=plot(data_list,style=POINT):
 

> display([PointPlot,CurvePlot],title=`Data Points & Least Squares Curve Fit`);
 

Plot_2d
 

>
 

Equations With Non-Integer Exponent.   

 

We conclude the section on Least Squares with a discussion of equation that arise from the following type of physical problems.     

 

Suppose you know that the rate of change of a substance present varies directly with the substance and inversely with the time.  i.e.  Typesetting:-mrow(Typesetting:-mi( .  Again, when we separate the varialbes we obtain 

the following equation.  Typesetting:-mrow(Typesetting:-mi( .  Now integrate both side  we obtain ln(y) = k ln(t) + c 

or by taking the exp  of both sides we obtainTypesetting:-mrow(Typesetting:-mi(  or  Typesetting:-mrow(Typesetting:-mi(.   Again our development 

leads us to the correct equation that we wish to explore before we get to the finished product.   

The equation we want to find is the equation Typesetting:-mrow(Typesetting:-mi( but the one that is best suited for the least squares examination is the equation ln(y) = k ln(t) + c.   By setting Typesetting:-mrow(Typesetting:-mi( and Typesetting:-mrow(Typesetting:-mi( we now have a linear equation in the new variables Typesetting:-mrow(Typesetting:-mi( which can be studied just line the linear least squares equation that we have looked at before.   

> t:=<2.0,3.0,3.2,3.6,4.0,4.3>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> y:=<2.0,7.0,8.0,11.5,15.0,18.5>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> t1:=<ln(t[1]),ln(t[2]),ln(t[3]),ln(t[4]),ln(t[5]),ln(t[6])>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> y1:=<ln(y[1]),ln(y[2]),ln(y[3]),ln(y[4]),ln(y[5]),ln(y[6])>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> ones:=<1,1,1,1,1,1>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> A1:=<ones|t1>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

>
 

>
 

> A1TA1:=A1^%T.A1;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> A1TY1:=A1^%T.y1;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> Sol:=BackwardSubstitute(GaussianElimination(<A1TA1|A1TY1>));
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

The value of k1 is fine but the value of c1 is not the one desired.  We must again take the exp of this value.  b=Typesetting:-mrow(Typesetting:-msup(Typesetting:-mo(
 

 

> c1:=Sol[1];
 

-1.29171135568805728
 

> k1:=Sol[2];
 

2.90038834832832437
 

> b:=exp(c1);
 

.2748000997
 

Our equation can then be written as 

>
 

>
 

We can again plot the above data against the equation just as we did on the previous problem. 

 

 

> data_list1:=[[t[1],y[1]],[t[2],y[2]],[t[3],y[3]],[t[4],y[4]],[t[5],y[5]],[t[6],y[6]]];
 

[[2.0, 2.0], [3.0, 7.0], [3.2, 8.0], [3.6, 11.5], [4.0, 15.0], [4.3, 18.5]] (3.1)
 

> formula:=b*tt^k1;
 

`+`(`*`(.2748000997, `*`(`^`(tt, 2.90038834832832437)))) (3.2)
 

> CurvePlot:=plot(formula,tt=1.9..4.4):
 

> PointPlot:=plot(data_list1,style=POINT):
 

> display([PointPlot,CurvePlot],title=`Data plots & Least Squares Fit`);
 

Plot_2d
 

When there is more than one possible fit to the data and you want to know which least squares fit is the best representation of the data.  You should pick the least squares fit where the error =norm(y-ys,2) is the smallest.  Here ys is the least squares fit at the t data points.    Also, the least squares fit should not be extended out side the data set since you have no idea of what is happening there.  Least square fit are only good in the interval of the independent variable data points.  Here the independent data points are represented by t.   

Exercise 2.6   

Exercise 2.6.8, Exercise 2.6.10, Exercise 2.611  Problmes are due on October 31, 2008.  You need to plot the data then do a combined plot of the data and the formula as in the examples above.