turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Blogs
- :
- JMP Blog
- :
- Simple nonlinear least squares curve fitting in JM...

Article Options

- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Email to a Friend
- Printer Friendly Page
- Report Inappropriate Content

Dec 18, 2013 10:11 AM
(1443 views)

Simple nonlinear least squares curve fitting in JMP

In his Walking Randomly blog, Mike Croucher shows how to fit a simple nonlinear curve using five different statistical programming libraries: R, MATLAB, Maple, Julia and Python/numpy. The idea is to provide concrete examples for a commonly asked modeling question that is simple to state but not so simple to solve.

For a the given data set of 10 x and y values, the problem is to find the best values for parameters p_{1} and p_{2} so that the following curve best fits the y values:

p_{1} cos( p_{2} x ) + p_{2} sin( p_{1} x )

Since nonlinear fitting involves an iterative search of the solution space, we need starting parameter values, which Croucher gives as

p_{1}=1.0, p_{2} = 0.2.

So how would you do the same thing in JMP?

Normally, you would start with a data table and use the Nonlinear platform under the Analyze menu to interactively launch the fit. For a model like this, which isn't built-in to JMP, you could add it in a formula column and use that in the Nonlinear dialog. But like most everything in JMP, it can be completely driven by a JSL script if you want.

Here's my JSL version:

xv= **[**-**2**, **-1.64**, -**1.33**, **-0.7**, **0**, **0.45**, **1.2**, **1.64**, **2.32**, **2.9****]**;

yv = **[****0.699369**, **0.700462**, **0.695354**, **1.03905**, **1.97389**,

**2.411430**, **1.910910**, **0.919576**, **-0.730975**, **-1.42001****]**;

dt = New Table**(**"Data",

New Column**(**"x", Set Values**( **xv **))**,

New Column**(**"y", Set Values**( **yv **)****)**

**)**;

dt << **Nonlinear****(** Y**(** :y **)**, X**(** :x **)**,

Model**(** Parameter**(** **{**p1 = **1**, p2 = **0.2****}**,

p1 *Cosine**(** p2 *:x **)** + p2 *Sine**(** p1 *:x **)** **)****)**,

Finish, Confidence Limits **)**;

That script produces the following interactive output.

Some of the other languages require a bit of extra work to get the confidence intervals, so it's nice to see it's just one option away in JMP.

You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.