       Re: Linear and logarithmic fit

• To: mathgroup at smc.vnet.net
• Subject: [mg39387] Re: Linear and logarithmic fit
• From: Bill Rowe <listuser at earthlink.net>
• Date: Thu, 13 Feb 2003 04:54:10 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

```On 2/12/03 at 3:54 AM, joh_nson at yahoo.com (jay Johnson) wrote:

>If I have 9 points in a 2 dimensional space how do I decide if they
>fit better a linear function or a logarithmic function?

One choice would be to use the sum of the errors squared. For example:

First create some data.

In:=
data=Table[{Random[],Random[]},{9}]

Out=
{{0.944293,0.933087},{0.835982,0.570568},{
0.510525,0.861731},{0.624458,0.318239},{
0.795989,0.2449},{0.622892,0.216268},{0.150898,0.567541},{0.41438,0.0978371}\
,{0.17643,0.920655}}

do a linear fit

In:=
f=Fit[data,{1,x},x]

Out=
0.573502\[InvisibleSpace]-0.0848516 x

do a logarithmic fit

In:=
g=Fit[data,{1 Log[x]},x]

Out=
-0.455209 Log[x]

Sum the squared errors for the linear fit

In:=
Tr[((#1[] - f /. x -> #1[])^2 & ) /@ data]

Out=
0.834833

sum the squared errors for the logarithmic fit

In:=
Tr[((#1[] - g /. x -> #1[])^2 & ) /@ data]

Out=
1.59636

Since sum of the squared errors for the logarithmic fit is greater than for the linear fit, conclude the linear fit is better.

Note, using the sum of the squared errors is probably the most commonly used measure of goodness of fit, but it is not the only measure that could be used. I've used this measure since that is what Fit minimizes to compute the fit coefficients.

Also, if you want to compare several different models using a least squares fit, it would probably be better to use the Regress function in the package Statistics`LinearRegression` . There are options for this function to include in the output the sum of the error squared as well as other statistics to judge the fit of the model to the data.

Finally, if you are going to be fitting models to data often it would be a good idea to read a good text on fitting models to data. There are several pitfalls that can lead to very misleading results. A couple of possilbe texts are

Fitting Equations to Data by Daniel and Wood
Applied Linear Regression by Weisberg

```

• Prev by Date: Re: Input output disappear
• Next by Date: Re: a first-time user question
• Previous by thread: Re: Linear and logarithmic fit
• Next by thread: Fwd: Linear and logarithmic fit