Re: Extracting Parameter Values from NonlinearModelFit

• To: mathgroup at smc.vnet.net
• Subject: [mg127900] Re: Extracting Parameter Values from NonlinearModelFit
• From: Bob Hanlon <hanlonr357 at gmail.com>
• Date: Fri, 31 Aug 2012 03:56:45 -0400 (EDT)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• Delivered-to: l-mathgroup@wolfram.com
• Delivered-to: mathgroup-newout@smc.vnet.net
• Delivered-to: mathgroup-newsend@smc.vnet.net
• References: <20120830080726.B2E206369@smc.vnet.net>

```numberOfDataSets = 5;
numberOfDataPointsPerDataSet = 25;

data =
Table[Reverse[Sort[RandomVariate[
ExponentialDistribution[RandomReal[
{.1, .5}]], numberOfDataPointsPerDataSet]]],
{numberOfDataSets}];

model = a Exp[-k x];

{aValues, kValues} =
Transpose[{a, k} /.
NonlinearModelFit[#, {model, .1 < k < 1},
{a, k}, x]["BestFitParameters"] & /@ data];

Manipulate[
Show[
Plot[model /. {a -> aValues[[n]], k -> kValues[[n]]},
{x, 1, Length[data[[n]]]}],
ListPlot[data[[n]],
PlotStyle -> {Red, AbsolutePointSize[4]}],
PlotRange -> All,
Frame -> True,
Axes -> False],
{n, Range[Length[data]]}]

Bob Hanlon

On Thu, Aug 30, 2012 at 4:07 AM, colang <colangmp at gmail.com> wrote:
> Hi,
>
> I'm modelling a series (>2000) of data points (5x2 lists) using NonlinearModelFit, and trying to extract the Fitted Parameter Values to separate lists using the following code:
>
> model = a Exp[-k x];
> i = 1;
> For[i = 1, i <= Length[data],
>   {nlm = NonlinearModelFit[data[[i]], {model, k<1}, {a, b}, x]["BestFitParameters"];
>    aValues = Append[aValues, nlm[[1, 2]]];
>    kValues = Append[kValues, nlm[[2, 2]]]},
>   i++
>   ];
>
> I'm able to determine the Parameters via nlm, but can't extract the parameter values.
>
> Any thoughts?
>