MathGroup Archive 2001

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

Search the Archive

Re: Fit[]: how to obtain the parameter values?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg31839] Re: Fit[]: how to obtain the parameter values?
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Fri, 7 Dec 2001 05:55:54 -0500 (EST)
  • References: <9ul2bt$6lu$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Peter,

Not my area, and someone may have a better way, but two of the packages
might help:

    f1[x_]=2 ;f2[x_]=3x;
     data={{1,2},{2,2.5},{3,3}};

    <<Statistics`LinearRegression`

    reg=Regress[data,{2, 3x},{x},
      RegressionReport->ParameterTable];

params= (ParameterTable/.reg)[[1,All,1]]

{0.75,0.166667}

<<Statistics`NonlinearFit`

BestFitParameters/.NonlinearRegress[data,a  2 + b 3x,{x},{a,b},
    RegressionReport->BestFitParameters]

{a->0.75,b->0.166667}

The use of the option RegressionReport simply stops the calculation of
unwanted material - it can be left out at the cost of slower computation.

--
Allan

---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565


"Peter Marzlin" <peter.marzlin at uni-konstanz.de> wrote in message
news:9ul2bt$6lu$1 at smc.vnet.net...
> Hi all,
>
> I am trying to use Fit to get a linear least square fit with some
> complicated functions. In principle this works fine, but I cannot
> get the parameter values.
>
> For instance, using the two functions
>
> f1[x] = 2    and    f2[x] = 3x
>
> I would like to get the parameters a1 and a2 in the fit function
>
> f[x] = a1 f1[x] + a2 f2[x]
>
> for the set of data     data = {{1, 2}, {2, 2.5}, {3, 3}}
>
>
> Using the command
>
> Fit[data, {f1[x], f2[x]}, x]
>
> I get the answer 1.5 + 0.5 x
>
>
> This is correct but not what I want. I need a1 and a2, but
> they cannot easliy be obtained because Fit merges the prefactors
> in the definition of f1 and f2 with the value of the parameters
> a1 and a2.
>
> Of course, in this simple example I can get a1 and a2 by hand, but
> I am actually interested in a much more involved problem where
> extracting
> the parameter values from the Fit output is a rather tedious if not
> practically impossible task.
>
> Any help would be greatly appreciated.
>
> Peter
>




  • Prev by Date: Penrose Seasons Greetings
  • Next by Date: Re: Fit[]: how to obtain the parameter values?
  • Previous by thread: Re: Fit[]: how to obtain the parameter values?
  • Next by thread: Re: Fit[]: how to obtain the parameter values?