       Re: Fitting a Function with no closed form

• To: mathgroup at smc.vnet.net
• Subject: [mg98686] Re: [mg98633] Fitting a Function with no closed form
• From: Darren Glosemeyer <darreng at wolfram.com>
• Date: Thu, 16 Apr 2009 04:15:02 -0400 (EDT)
• References: <200904150857.EAA07833@smc.vnet.net>

```Adam Dally wrote:
> I have a histogram which I am trying to fit with a convoluted function.
>
> I get out the list of bin counts easy enough, but I can't figure out a way
> to fit the function to the data.
>
> This is the function:
> F(x)=Re[NIntegrate [normalizer*(E0 - u)^2 Sqrt[1 - m^2/(E0 - u)^2]*Exp[(-((x
> - u)^2/(2 \[Sigma]^2)))/(Sqrt[2 \[Pi]] \[Sigma])], {u, 0, E0}]]
> "E0" and "sigma" are known constants. "Normalize" and "m" are the fitting
> parameters.
>
> I can get a plot or of a table of values out of the function by:
> Plot[F(x),{x, minRange, maxRange}]
> Table[F(x),{x, minRange, maxRange, binWidth}]
>
> Is there a way to fit using a function like this? I would also like to error
> bars on the fit parameters.
>
> Thank you,
>

The function can be defined as a function that requires that the
variables and fitting parameters to be numeric as follows

In:= f[x_?NumericQ, normalizer_?NumericQ, m_?NumericQ, \[Sigma]_,
E0_] :=
Re[NIntegrate[
normalizer*(E0 - u)^2 Sqrt[1 - m^2/(E0 - u)^2]*
Exp[(-((x - u)^2/(2 \[Sigma]^2)))/(Sqrt[2 \[Pi]] \[Sigma])],
{u,
0, E0}]]

Note that I left off the numeric requirement on \[Sigma] and E0 because
these will be known numbers, so there will be no need for the check so
long as we always enter numbers for them.

Here is some simulated data to demonstrate fitting.

In:= data = Table[{x, f[x, 3, 2, 1, 10] + RandomReal[{-.1, .1}]}, {x, 0,
2, .2}]

Out= {{0., 447.74}, {0.2, 484.515}, {0.4, 518.662}, {0.6, 549.172},
{0.8, 575.508}, {1., 597.046},

>    {1.2, 613.54}, {1.4, 624.76}, {1.6, 630.629}, {1.8, 631.295}, {2.,
627.419}}

In version 7, NonlinearModelFit can be used to fit the data to the model
and obtain an object that knows about various results and diagnostics.

In:= Normal[nlm =
NonlinearModelFit[data,
f[x, normalizer, m, 1, 10], {{normalizer, 2}, {m, 2.5}}, x]]

Out= f[x, 2.99854, 1.98476, 1, 10]

Among the available results are "ParameterConfidenceIntervalTable" which
presents estimates, standard errors and confidence intervals in a
tabular form (alignment may appear off in the following text form in
some email apps) and "ParameterConfidenceIntervals" which just gives the
intervals.

In:= nlm["ParameterConfidenceIntervalTable"]

Out=              Estimate   Standard Error   Confidence Interval

2.99614
normalizer   2.99854    0.0010641        3.00095

1.9589
m            1.98476    0.0114313        2.01062

In:= nlm["ParameterConfidenceIntervals"]

Out= {{2.99614, 3.00095}, {1.9589, 2.01062}}

properties, you can refer to the following:

http://reference.wolfram.com/mathematica/ref/NonlinearModelFit.html
http://reference.wolfram.com/mathematica/tutorial/StatisticalModelAnalysis.html

In version 6, you can use the NonlinearRegress function in the
NonlinearRegression` package to fit the function and get confidence
intervals.

Darren Glosemeyer
Wolfram Research

```

• Prev by Date: Re: Any way to make help browser remember the last position?
• Next by Date: Re: Simplify
• Previous by thread: Fitting a Function with no closed form
• Next by thread: Re: Fitting a Function with no closed form