       RE: Regressions and the Mathematica buttons

• To: mathgroup at smc.vnet.net
• Subject: [mg28538] RE: [mg28527] Regressions and the Mathematica buttons
• From: "David Park" <djmp at earthlink.net>
• Date: Wed, 25 Apr 2001 19:21:46 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```Ian,

To get your palette back, use the menu item Files -> Palettes -> BasicInput.
You may also find other useful palettes there.

Here is an example of a nonlinear regression.

Needs["Statistics`NonlinearFit`"]

This defines a function with some noise on it and makes a table of data
points to use in the regression.

f[x_] := Sin[x]/E^x + 0.1*Random[Real, {-1, 1}]
data = Table[{x, f[x]}, {x, 0, 2, 0.02}];

plot1 = ListPlot[data];

This defines a model we will use to fit the data. The model has parameters a
and b, which we are trying to determine. NonlinearRegress returns a alot of
information about the regression. Among this information are a set of
replacement rules for a and b called BestFitParameters. We extract these and
plug them into our model to obtain the best fit function, ffit.

fmodel[a_, b_][x_] := a*Sin[x]*E^(b*x);
NonlinearRegress[data, fmodel[a, b][x], {x}, {a, b}]
ffit[x_] = fmodel[a, b][x] /. (BestFitParameters /. %)

This shows the best fit function on top of the data points.

plot2 = Plot[ffit[x], {x, 0, 2}];
Show[plot1, plot2];

David Park

> From: Ian Fan [mailto:ian at v-wave.com]
To: mathgroup at smc.vnet.net
>
> Hi, I am running Mathematica 4.0 for Students and I was just wondering if
> anyone could tell me how to do a regression given a list of data
> to generate
> a sinusodal (or for that matter, any type of) function - i.e.,
> how can I get
> it to make a best fit graph given a set of data? Also, I made my
> Mathematica
> button (the one with all the quick access to the functions) disappear, can
> anyone tell me how to get it back?
>