Subscribe Bookmark RSS Feed

Segmented regression

phystudent

Community Trekker

Joined:

Oct 8, 2012

Does anyone know how to perform a segmented regression and calculate the breakpoint (where the 2 lines meet) on JMP?

3 REPLIES

If it's a simple broken stick relationship, you could do something like this:

// Create a broken stick relationship with some noise;

x = [ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];

y = [15, 12, 27, 31, 26, 31, 42, 47, 56, 56, 47, 46, 36, 44, 38, 35, 34, 35, 25, 19];

expr_FX  = expr(a + b*x + c*(x-d):*(x>d));

expr_SSE = expr(sum((y-expr_FX)^2));

// Supply a set of starting values;

a = 20; b = 1; c = -10; d = 15;

print("Starting values:");

show(a, b, c, d);

sse = minimize(expr_SSE, {a, b, c, d}, << tolerance(1e-5));

print("Final estimates:");

show(a, b, c, d);

show(eval(expr_FX));

I've based the above on the Least Squares Example in the JMP 10 Manual, Chapter 8, substituting a broken stick relationship in the expression for the exponential model in the example.  The break point will be parameter d, as that's the x value at which the slope of the line changes.  Note that when you multiply the two matrices (x-d) and (x>d) together, you'll need the element-wise product :* as opposed to a simple multiplication.  You'll also probably need a relatively good starting value for the break point for the expression to converge.  In this example, all the output is written to the log.

Presumably this could also be set up in the nonlinear platform (Analyze | Modeling | Nonlinear), but I haven't tried that yet as I'm not very familiar with using formulae within data tables.  Does that help at all?

ms

Super User

Joined:

Jun 23, 2011

As Dodo suggests, piecewise regression can be done with the Nonlinear platform. Below is an example based on the broken-stick example above.

New Table( "piecewise",

  Add Rows( 20 ),

  New Column( "X",

  Continuous,

  Set Values( [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] )

  ),

  New Column( "Y",

  Numeric,

  Set Values( [15, 12, 27, 31, 26, 31, 42, 47, 56, 56, 47, 46, 36, 44, 38, 35, 34, 35, 25, 19] )

  ),

  New Column( "Ypred",

  Numeric,

  Formula( Parameter( {a = 20, b = 1, c = -10, d = 10}, a + b * :X + c * (:X - d) * (:X > d) ) )

  )

);

Nonlinear( Y( :Y ), X( :Ypred ), Newton, Finish );

phystudent

Community Trekker

Joined:

Oct 8, 2012

Thanks I will try this out!