cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
BHarris
Level VI

Difference of lines

Suppose I have two lines, distance vs. time for two different moving objects.  The time measurements for object 1 and object 2 are at arbitrary times, i.e., the measured times for object 1 aren't the same times as provided for object 2.

 

Is there a way in Graph Builder to plot the *difference* between those curves vs. time?

12 REPLIES 12
XanGregg
Staff

Re: Difference of lines

Here's a low scripting alternative using the Save Formula command available in the red triangle menu for a Smoother or Line of Fit element.

XanGregg_0-1631541150941.png

 

Starting with Craige's ab.jmp table using Overlay to get two lines/curves, use Save Formula to get a new column with a formula that looks like:

 

If( :Source Table == "a", Spline Eval( ... ), :Source Table == "b", Spline Eval( ... ), . ))

 

Go into the Formula Editor for the new column and change the formula to subtract the two Spline expressions:

 

Spline Eval( ... ) - Spline Eval( ... )

 

And use that as the Y in GB.

XanGregg_1-1631541420331.png

 

BHarris
Level VI

Re: Difference of lines

Due to some bizarre licensing problems* I was only finally able to try this today.  It works quite well, very elegant!

 

Two questions:

 

  1. Is JSL powerful enough to make that formula change for me?  So that whole process could be scripted into a .jsl script?
  2. I expected the difference curve to update as I changed the lambda on the smoother but it doesn't.  Looking deeper I see that the "Save formula" is actually saving off the spline parameters, not maintaining a connection back to the actual splines being used.  I presume the latter is not reasonably possible?

Thanks again!

 

 

****************************************

* I was finally forced to update my Mac to 11.6, not realizing that JMP v14 wouldn't work on it.  So I requested v16 through my company, and it literally took months after getting a PO to actually get a v16 license for me.  There was tons of back-and-forth with tax certs and address changes and PO problems.  I can't tell if the problem was my company's supply-chain or JMP/SAS's sales department, but getting a license if you have money in hand really shouldn't be that hard.

 

hogi
Level XII

Re: Difference of lines

As a combination of the different suggestions, you could also use a simple interpolate() - interpolate() to calculate the difference and then use the lambda setting of the smoother plot to tune the granularity of the curve.

hogi_0-1698514312749.png

Open( "$DOWNLOADS/ab.jmp" );
New Column( "diff",
	Formula(
		rowsA = As Constant( Current Data Table() << get rows where( :Source Table == "a" ) );
		rowsB = As Constant( Current Data Table() << get rows where( :Source Table == "b" ) );
		xA = As Constant( :time[rowsA] );
		xB = As Constant( :time[rowsB] );
		posA = As Constant( :position[rowsA] );
		posB = As Constant( :position[rowsB] );
		If( Min( xA ) <= :time <= Max( xA ) & Min( xB ) <= :time <= Max( xB ),
			Interpolate( :time, xA, posA ) - Interpolate( :time, xB, posB ),
			.
		);
	)
);
Graph Builder(
	Variables( X( :time ), Y( :diff ), Y( :position ), Overlay( :Source Table ) ),
	Elements( Position( 1, 1 ), Points( X, Y, Overlay( 0 ), Legend( 1 ) ), Smoother( X, Y, Overlay( 0 ), Lambda( 0.02 ) ) ),
	Elements( Position( 1, 2 ), Points( X, Y ), Smoother( X, Y ) )
);