Fit[] versus Regress[] inconsistent behahiour
- To: mathgroup at smc.vnet.net
- Subject: [mg31864] Fit[] versus Regress[] inconsistent behahiour
- From: "Robert Nowak" <robert.nowak at ims.co.at>
- Date: Fri, 7 Dec 2001 05:57:02 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Hi to all
Mathematica Manual says:
"Fit[data, funs, vars] finds a leastsquares fit to a list of data as a
linear combination of the functions funs of variables vars."
but behaviour is different as one can see:
In[59]:=
f1[x]=2;
f2[x]=3 x;
In[61]:=
data = {{1, 2}, {2, 2.5}, {3, 3}};
In[62]:=
Fit[data, {f1[x], f2[x]}, x]//CoefficientList[#,x]&
Out[62]=
{1.5,0.5}
(* ?????????? wondering if the above result is correct or is it a
mathemeatica bug ??????????? *)
(* Mathematica seems to strip all linear coefficients form the base functions *)
In[69]:=
Fit[data, {a 1,b x}, x]//CoefficientList[#,x]&
Out[69]=
{1.5,0.5}
(* ?????????? wondering where a and b have gone no error massage a and b
where just stripped ??????????? *)
(* Mathematica seems to strip all linear coefficients form the base functions *)
In[63]:=
Fit[data, {1,x}, x]//CoefficientList[#,x]&
Out[63]=
{1.5,0.5}
(* correct linear fit calulation but perhaps not what you want *)
In[64]:=
<<Statistics`LinearRegression`
In[65]:=
BestFitParameters/.Regress[data, {1,x},
x,RegressionReport->BestFitParameters]
Out[65]=
{1.5,0.5}
(* correct linear fit calulation but perhaps not what you want *)
In[66]:=
BestFitParameters/.Regress[data, {f1[x],f2[x]}, x,
RegressionReport->BestFitParameters]
Out[66]=
{0.75,0.166667}
(* !!!! this should be your correct solution !!!!! *)
--
---
Robert Nowak (robert.nowak at ims.co.at)
IMS Nanofabrication GmbH
A-1020 Wien, Schreygasse 3, Austria
Phone: (+43 1)2144894-32, Fax: (+43 1)2144894-99