MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Concurrent Curve Fitting...

  • To: mathgroup at smc.vnet.net
  • Subject: [mg18623] Re: [mg18562] Concurrent Curve Fitting...
  • From: "Wolf, Hartmut" <hwolf at debis.com>
  • Date: Tue, 13 Jul 1999 01:01:40 -0400
  • Organization: debis Systemhaus
  • References: <199907100618.CAA03020@smc.vnet.net.>
  • Sender: owner-wri-mathgroup at wolfram.com

Hello Robert,

Robert Carneim schrieb:
> 
> I have two sets of data which are related in such a way that, when plotted,
> they should have the same shape (or I want to force the curve fits to have
> the same shape), but at a different location.
> So, for example (and simplicity} suppose I have two sets of data which can
> be fit by lines, y=mx+b. I want to fit data set 1 to (y-y1)=m(x-x1)+b, and
> data set 2 to (y-y2)=m(x-x2)+b, where m and b are common and xn and yn are
> specific to the data set.
> This is a fairly easy to do indirectly, even by hand, but is there a way to
> get Mathematica to do this directly, i.e., finding the two curve fits
> concurrently? Obviously, I'm trying to do this for much more complex models.
> 
I'm not quite shure whether I understand you fully, but I'll work out an
example that might help you (this is just a simple idea, but perhaps
there ar much superior methods):

We want to fit two data sets according to the functions f1 = m x + b1,
and 
f2 = m x + b2, i.e. with the _same_ m, but different b.

We prepare two data sets, the first one:

In[1]:= m1=0.77; b1=1.1;
In[2]:= d1={#,m1 # + b1 + 1.7  Random[]}&/@(2 Range[10])
Out[2]=
{{2,3.08172},{4,4.755},{6,6.6166},{8,7.43221},{10,9.896},{12,10.9624},{14,
    12.5774},{16,14.343},{18,15.6232},{20,17.1432}}
In[3]:= f1=Fit[d1,{1,x},x]
Out[3]= 1.65091+0.781106 x

this is the _separate_ fit for set 1. We do the same for set 2:

In[7]:= m2=0.74; b2=-4.;
In[8]:= d2={#,m2 # + b2 + 1.5 Random[]}&/@(2 Range[11]-1)
Out[8]=
{{1,-2.64292},{3,-1.19437},{5,1.05521},{7,2.15956},{9,3.0965},{11,5.30787},{
    13,6.80649},{15,7.87324},{17,9.56328},{19,11.4821},{21,11.756}}
In[9]:= f2=Fit[d2,{1,x},x]
Out[9]= -3.14419+0.742554 x

(We have chosen sligthly different m-values for each set, the fits
respect that, and both sets are shifted)

Now the idea is to tag each set, in order to join them for a single
combined fit:

In[14]:= dd1=Transpose[Insert[Transpose[d1],Table[1,{10}],2]]
In[15]:= dd2=Transpose[Insert[Transpose[d2],Table[2,{11}],2]]

The 'constants' b now become functions of the tag:

In[40]:= c1[_,1]=1; c1[_,2]=0;
In[41]:= c2[_,1]=0; c2[_,2]=1;

The separate fits work with our new representation (and give same
results):

In[45]:= Fit[dd1,{c1[x,y],x},{x,y}]
Out[45]= 0.781106 x+1.65091 c1[x,y]

In[48]:= Fit[dd2,{c2[x,y],x},{x,y}]
Out[48]= 0.742554 x-3.14419 c2[x,y]

Taking the "wrong constants" for each set gives:

In[46]:= Fit[dd1,{c2[x,y],x},{x,y}]
Out[46]= 0.899028 x+0. c2[x,y]

In[49]:= Fit[dd2,{c1[x,y],x},{x,y}]
Out[49]= 0.527733 x+0. c1[x,y]

which is the same as when you do

In[52]:= Fit[d1,{x},{x}]
Out[52]= 0.899028 x

In[53]:= Fit[d2,{x},{x}]
Out[53]= 0.527733 x

The simultanious fit now simply is:

In[50]:= Fit[Join[dd1,dd2],{c1[x,y],c2[x,y],x},{x,y}]
Out[50]= 0.759076 x+1.89324 c1[x,y]-3.32594 c2[x,y]

you clearly see a compromise value for m (the b have adapted too, due to
a 'false' value for m with respect to each set)

---regards, hw



  • Prev by Date: Re: Concurrent Curve Fitting...
  • Next by Date: Re: trouble with greek letter output to EPS
  • Previous by thread: Re: Concurrent Curve Fitting...
  • Next by thread: Re: Concurrent Curve Fitting...