MathGroup Archive 1999

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

Search the Archive

Re: Concurrent Curve Fitting...

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,
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])
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)
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

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...