cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Register for our Discovery Summit 2024 conference, Oct. 21-24, where you’ll learn, connect, and be inspired.
Choose Language Hide Translation Bar
Neo
Neo
Level VI

Correlation plot without modifying datatable structure

I would like to do a correlation plot to compare tested parameter (Id) between TestStages for different parts as shown in the attached example data table.

I want median for Id1 (for all parts) on x-axis and median for Id2 (for all parts) on y-axis with associated limits ref. lines on respective axes (i.e. LSL/USL vertical lines for TestStage 1 needed on x axis while LSL/USL horizontal lines for TestStage 2 needed on y-axis).

How to do this without modifying the datatable structure using JSL? 

As done below, I can to do this type of correlation plot if I have the median for Id1 and Id2, limits etc. as column data (not as row data as in attached).

I do not want to change the data table structure (which I pull using another JSL script) or generate a new data-table (using split() as below) based on it, hence my question. 

Names Default To Here (1);

Data Table( "egDataTable" ) << Split(
	Split By( :TestStage ),
	Split( :Median, :LSL, :USL ),
	Remaining Columns( Drop All ),
	Sort by Column Property
);

Graph Builder(
	Size( 528, 457 ),
	Show Control Panel( 0 ),
	Variables(
		X( :Median 1 ),
		X( :LSL 1, Position( 1 ) ),
		X( :USL 2, Position( 1 ) ),
		Y( :Median 2 ),
		Y( :LSL 2, Position( 1 ) ),
		Y( :USL 2, Position( 1 ) )
	),
	Elements(
		Points( X( 1 ), X( 2 ), X( 3 ), Y( 1 ), Y( 2 ), Y( 3 ), Legend( 65 ) )
	),
	SendToReport(
		Dispatch(
			{},
			"400",
			ScaleBox,
			{Legend Model(
				65,
				Properties(
					0,
					{Marker( "Star" )},
					Item ID( "Median 2 / Median 1", 1 )
				),
				Properties(
					1,
					{Marker( "Minus" )},
					Item ID( "LSL 2 / Median 1", 1 )
				),
				Properties(
					2,
					{Marker( "Minus" )},
					Item ID( "USL 2 / Median 1", 1 )
				),
				Properties(
					3,
					{Marker( "Pipe" )},
					Item ID( "Median 2 / LSL 1", 1 )
				),
				Properties( 4, {Marker( "Minus" )}, Item ID( "LSL 2 / LSL 1", 1 ) ),
				Properties( 5, {Marker( "Minus" )}, Item ID( "USL 2 / LSL 1", 1 ) ),
				Properties(
					6,
					{Marker( "Pipe" )},
					Item ID( "Median 2 / USL 2", 1 )
				),
				Properties( 7, {Marker( "Minus" )}, Item ID( "LSL 2 / USL 2", 1 ) ),
				Properties( 8, {Marker( "Minus" )}, Item ID( "USL 2 / USL 2", 1 ) )
			)}
		)
	)
);

 

When it's too good to be true, it's neither
1 ACCEPTED SOLUTION

Accepted Solutions
SDF1
Super User

Re: Correlation plot without modifying datatable structure

Hi @Neo ,

 

  I'm not sure if I understand your issue entirely, but here's how I've interpreted it to come up with what I think is a solution. First off, It's clear you don't want to change the table structure, which is understandable, especially if you're designing this to be run as an automated JSL script or something.

 

  The below JSL script is ONE way to do it. I'm sure there are many others, but it at least gets you in the right direction, where you can now edit it as you wish, for color, style, etc. It might not be exactly what you're after, but I think it should be close.

 

Names Default To Here( 1 );

dt = Data Table( "egDataTable" );

dt << New Column( "Median1", Continuous, Numeric );
dt << New Column( "Median2", Continuous, Numeric );

For( i = 1, i <= N Rows( dt ), i++,
	If(
		:TestParameter[i] == "Id1" & :TestStage[i] == 1,
			:Median1[i] = :Median[i];
			_LSL1_ = :LSL[i];
			_USL1_ = :USL[i];,
		:TestParameter[i] == "id2" & :TestStage[i] == 2,
			:Median2[:PartNumber[i]] = :Median[i];
			_LSL2_ = :LSL[i];
			_USL2_ = :USL[i];,
		.
	)
);

Graph Builder(
	Graph Spacing( 4 ),
	Variables( X( :Median1 ), Y( :Median2 ) ),
	Elements( Points( X, Y, Legend( 3 ) ) ),
	SendToReport(
		Dispatch(
			{},
			"Median1",
			ScaleBox,
			{Min( 0 ), Max( 1.1 ), Inc( 0.2 ), Minor Ticks( 1 ), Add Ref Line( _LSL1_, "Solid", "Blue", "LSL1", 1 ),
			Add Ref Line( _USL1_, "Solid", "Blue", "USL1", 1 )}
		),
		Dispatch(
			{},
			"Median2",
			ScaleBox,
			{Min( -0.03 ), Max( 0.8 ), Inc( 0.1 ), Minor Ticks( 0 ), Add Ref Line( _LSL2_, "Solid", "Blue", "LSL2", 1 ),
			Add Ref Line( _USL2_, "Solid", "Blue", "USL2", 1 )}
		),
		Dispatch( {}, "400", ScaleBox, {Legend Model( 3, Properties( 0, {Marker( "Star" )}, Item ID( "Median2", 1 ) ) )} )
	)
);

Hope this helps!,

DS

 

*Edit: One thing I meant to mention is that if you want to generalize this for working with other kinds of data tables, you might want to consider having consistency across labels, for example, your TestParameter column has mix of lower and upper case, e.g. Id1, id2, id3, instead of all being ID#, or id#, etc. When doing the conditional coding, it's sometimes a lot easier when you have consistent syntax so there's less chance of having to debug because of letter case.

View solution in original post

3 REPLIES 3
SDF1
Super User

Re: Correlation plot without modifying datatable structure

Hi @Neo ,

 

  I'm not sure if I understand your issue entirely, but here's how I've interpreted it to come up with what I think is a solution. First off, It's clear you don't want to change the table structure, which is understandable, especially if you're designing this to be run as an automated JSL script or something.

 

  The below JSL script is ONE way to do it. I'm sure there are many others, but it at least gets you in the right direction, where you can now edit it as you wish, for color, style, etc. It might not be exactly what you're after, but I think it should be close.

 

Names Default To Here( 1 );

dt = Data Table( "egDataTable" );

dt << New Column( "Median1", Continuous, Numeric );
dt << New Column( "Median2", Continuous, Numeric );

For( i = 1, i <= N Rows( dt ), i++,
	If(
		:TestParameter[i] == "Id1" & :TestStage[i] == 1,
			:Median1[i] = :Median[i];
			_LSL1_ = :LSL[i];
			_USL1_ = :USL[i];,
		:TestParameter[i] == "id2" & :TestStage[i] == 2,
			:Median2[:PartNumber[i]] = :Median[i];
			_LSL2_ = :LSL[i];
			_USL2_ = :USL[i];,
		.
	)
);

Graph Builder(
	Graph Spacing( 4 ),
	Variables( X( :Median1 ), Y( :Median2 ) ),
	Elements( Points( X, Y, Legend( 3 ) ) ),
	SendToReport(
		Dispatch(
			{},
			"Median1",
			ScaleBox,
			{Min( 0 ), Max( 1.1 ), Inc( 0.2 ), Minor Ticks( 1 ), Add Ref Line( _LSL1_, "Solid", "Blue", "LSL1", 1 ),
			Add Ref Line( _USL1_, "Solid", "Blue", "USL1", 1 )}
		),
		Dispatch(
			{},
			"Median2",
			ScaleBox,
			{Min( -0.03 ), Max( 0.8 ), Inc( 0.1 ), Minor Ticks( 0 ), Add Ref Line( _LSL2_, "Solid", "Blue", "LSL2", 1 ),
			Add Ref Line( _USL2_, "Solid", "Blue", "USL2", 1 )}
		),
		Dispatch( {}, "400", ScaleBox, {Legend Model( 3, Properties( 0, {Marker( "Star" )}, Item ID( "Median2", 1 ) ) )} )
	)
);

Hope this helps!,

DS

 

*Edit: One thing I meant to mention is that if you want to generalize this for working with other kinds of data tables, you might want to consider having consistency across labels, for example, your TestParameter column has mix of lower and upper case, e.g. Id1, id2, id3, instead of all being ID#, or id#, etc. When doing the conditional coding, it's sometimes a lot easier when you have consistent syntax so there's less chance of having to debug because of letter case.

Neo
Neo
Level VI

Re: Correlation plot without modifying datatable structure

@SDF1  Thanks for your inputs. 

The table I attached is a cooked up example table so that I could show what I wanted the plot to look like. In the actual case, each test stage has about 50 test parameters tested and there are 10 test stages.

 

I would not want to generate a column for each tested parameter in each test stage (your script if I understand correctly) to compare against another test stage, unless there is another approach which does not need generating new columns. Also, there are thousands of parts tested so the data set is normally quite big to start with . 

 

I think I will change my approach and get the user select which two test stages and which parameters need to be correlated and then go from there.

 

If there is a more efficient approach, I am all ears/eyes 

When it's too good to be true, it's neither
SDF1
Super User

Re: Correlation plot without modifying datatable structure

Hi @Neo ,

 

  I figured the data table was just a mock-up. With as many test parameters, and stages you have, I understand why you wouldn't want to generate new columns. If you're not wanting to make new columns or split the data table, there is another way to graph the data you want, but you're limited in the statistics you can do on it since the data is not it's own dedicated column. You can't use it in other platforms within JMP like you can columns.

 

  The code below will generate a graph with the same style that you want, but it's just for "display" purposes as the data that is being graphed is data saved in memory as a vector rather to the data table as a column. You can still do some statistics -- I've included some statistics such as the mean and 1 std dev as an oval around the mean. But, you will be limited with some things because of what I've mentioned before. You can't do a density ellipse on this, for example (at least I don't know how to).

 

  I think you should be able to generalize the script to work with however many test stages, parameters and parts you have, you'd basically just be looping through the table to save all the vectors in memory and then perhaps have a popup window (via Expr() ) for the user to select which Test stages they want to look at.

 

Output:

SDF1_0-1686857416294.png

Script:

Names Default To Here( 1 );

dt = Data Table( "egDataTable" );

xrows = dt << RowSelection( Select Where( :TestStage == 1 ) ) << get selected rows();
xx = dt:Median[xrows];
xMean = Matrix( Mean( xx ) );
Xstdev = Std Dev( xx );

yrows = dt << RowSelection( Select Where( :TestStage == 2 ) ) << get selected rows();
yy = dt:Median[yrows];
yMean = Matrix( Mean( yy ) );
Ystdev = Std Dev( yy );

obj = New Window( "Example",
	gbox = Graph Box(
		Frame Size( 300, 300 ),
		YName( "Median 2" ),
		XName( "Median 1" ),
		Y Scale( _LSL2_ - 0.1, _USL2_ + 0.1 ),
		X Scale( _LSL1_ - 0.1, _USL1_ + 0.1 ),
		Marker( Marker State( 11 ), Color State( 0 ), xx, yy ),
		Marker( Marker State( 0 ), Color State( 4 ), xMean, yMean ),
		Pen Color( "Green" ),
		Oval( xMean - Xstdev, yMean + YStdev, xMean + Xstdev, yMean - Ystdev ),
		Title( "Median 2 vs Median 1" )
	)
);
yaxisbox = gbox[axisBox( 1 )];
xaxisbox = gbox[axisBox( 2 )];
yaxisbox << Add Ref Line( _LSL2_, "Line", blue, "LSL2" );
yaxisbox << Add Ref Line( _USL2_, "Line", blue, "USL2" );
xaxisbox << Add Ref Line( _LSL1_, "Line", blue, "LSL1" );
xaxisbox << Add Ref Line( _USL1_, "Line", blue, "USL1" );

Hope this helps you get going!,

DS