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
shasha_2
Level III

Multiple selection of partition segments

I want to select multiple segments when the partition model is shown. The selected segments will go into the badpopulation jmp file and the rest will go to the good population jmp file. But I don't know how to code it for multiple selection of the segments.

My code is as follows where it can make the separation into two categories:

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA\semiconductor capability.jmp" );

obj = Partition(
	Y( :NPN1 ),
	X( :PNP1, :PNP2, :PNP3, :PNP4, :NPN2, :NPN3, :NPN4 ),
	Method( "Decision Tree" ),
	Validation Portion( .2 )
);
obj << ShowGraph( 0 );
obj << SplitBest( 4 );
obj << Show Split Count( 1 );
obj << Show Split Prob( 1 );
Wait( .5 );
obj << on close(
If( N Items( dt << get selected rows() ) > 0,
dtTemp = dt << subset( invisible, selected rows( 1 ), selected columns( 0 ) );
dt << invert row selection;
dtSEG = dt << subset(  invisible, selected rows( 1 ), selected columns( 0 ) );
filepath = "$Desktop";
Close( dtTemp, save( filepath || "\" || "badpopulation.jmp" ) );
Close(dtSEG, save(filepath || "\" || "goodpopulation.jmp"));
)
);

I want to add for multiple segments,suppose the highlighted ones and get them into one jmp file 

(badpopulation) and rest data into other jmp file(goodpopulation) can anyone help me regarding this coding? snapseg.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
ian_jmp
Level X

Re: Multiple selection of partition segments

It looks like you want to allow the selection of the rows associated with multiple leaf nodes via the 'Select Rows' LRT option. If that's the case, you might be able to use a row state handler, and the code below should get you started. Note this assumes that the user does not make row selections other than via the Partition report.

Names Default To Here( 1 );

dt = Open( "$SAMPLE_DATA\semiconductor capability.jmp" );

// Matrix of all rows that were selected
::wasSelected = [];

// Row state handler function
updateWasSelected = Function({x}, {Default Local},
						// 'x' is a column vector of row states that have CHANGED. We just need those that are now selected . . .
						For( i = 1, i <= NRow(x), i++,
							// Need to accumulate selected rows, not adding duplicates
							If( Selected(RowState(x[i])) & !Contains(::wasSelected, x[i]),
								::wasSelected = VConcat(::wasSelected, x[i]) 
								);
							);
						);
// Assign the handler to the table
rsh = dt << MakeRowStateHandler(updateWasSelected);

// Do the partition and allow user to make selections vis leaf node LRT
obj = dt << Partition(
					Y( :NPN1 ),
					X( :PNP1, :PNP2, :PNP3, :PNP4, :NPN2, :NPN3, :NPN4 ),
					Method( "Decision Tree" )
				);
obj << ShowGraph( 0 );
obj << SplitBest( 4 );
obj << Show Split Count( 1 );
obj << Show Split Prob( 1 );

// Figure out what has been selected and make the auxilliary tables
obj << onClose(
			If( NRows(::wasSelected) > 0,
				filepath = "$Desktop";
				Try(
					dtTemp = dt << subset( invisible, rows( ::wasSelected ), selected columns( 0 ) );
					Close( dtTemp, save( filepath || "\" || "badpopulation.jmp" ) ),
					Print("No rows for table!");
					);
				dt << invert row selection;
				Try(
					dtSEG = dt << subset( invisible, selected rows( 1 ), selected columns( 0 ) );
					Close( dtSEG, save( filepath || "\" || "goodpopulation.jmp" ) ),
					Print("No rows for table!");
					 );
				);
			dt << clearRowStates;
		);

View solution in original post

4 REPLIES 4
ian_jmp
Level X

Re: Multiple selection of partition segments

It looks like you want to allow the selection of the rows associated with multiple leaf nodes via the 'Select Rows' LRT option. If that's the case, you might be able to use a row state handler, and the code below should get you started. Note this assumes that the user does not make row selections other than via the Partition report.

Names Default To Here( 1 );

dt = Open( "$SAMPLE_DATA\semiconductor capability.jmp" );

// Matrix of all rows that were selected
::wasSelected = [];

// Row state handler function
updateWasSelected = Function({x}, {Default Local},
						// 'x' is a column vector of row states that have CHANGED. We just need those that are now selected . . .
						For( i = 1, i <= NRow(x), i++,
							// Need to accumulate selected rows, not adding duplicates
							If( Selected(RowState(x[i])) & !Contains(::wasSelected, x[i]),
								::wasSelected = VConcat(::wasSelected, x[i]) 
								);
							);
						);
// Assign the handler to the table
rsh = dt << MakeRowStateHandler(updateWasSelected);

// Do the partition and allow user to make selections vis leaf node LRT
obj = dt << Partition(
					Y( :NPN1 ),
					X( :PNP1, :PNP2, :PNP3, :PNP4, :NPN2, :NPN3, :NPN4 ),
					Method( "Decision Tree" )
				);
obj << ShowGraph( 0 );
obj << SplitBest( 4 );
obj << Show Split Count( 1 );
obj << Show Split Prob( 1 );

// Figure out what has been selected and make the auxilliary tables
obj << onClose(
			If( NRows(::wasSelected) > 0,
				filepath = "$Desktop";
				Try(
					dtTemp = dt << subset( invisible, rows( ::wasSelected ), selected columns( 0 ) );
					Close( dtTemp, save( filepath || "\" || "badpopulation.jmp" ) ),
					Print("No rows for table!");
					);
				dt << invert row selection;
				Try(
					dtSEG = dt << subset( invisible, selected rows( 1 ), selected columns( 0 ) );
					Close( dtSEG, save( filepath || "\" || "goodpopulation.jmp" ) ),
					Print("No rows for table!");
					 );
				);
			dt << clearRowStates;
		);
shasha_2
Level III

Re: Multiple selection of partition segments

Thank you so much. I will try this one out.
Byron_JMP
Staff

Re: Multiple selection of partition segments

Without using scripting there is a nice solution using the point and click features in JMP

 

First select the rows in the leaf that has "Bad" values, using the Red Triangle Menu (RTM) in the leaf.

Screen Shot 2022-04-04 at 2.32.52 PM.png

Next Name the Selection in Column from the Rows menu tab

Screen Shot 2022-04-04 at 2.33.31 PM.png

Enter a title for your new column and a label for your "bad" rows.

Don't enter a value for the unselected rows. Just leave it blank

Screen Shot 2022-04-04 at 2.33.17 PM.png

Repeat this step for each "Bad" Leaf

JMP Systems Engineer, Health and Life Sciences (Pharma)
Byron_JMP
Staff

Re: Multiple selection of partition segments

Maybe an even better or easier solution:

After you build your tree. Use the RTM to Save the Leaf Numbers

Byron_JMP_0-1649097687831.png

.

Then use Fit YbyX to do an ANOVA using Leaf Number as the X and your response at the Y, and pick the "Bad" leaves off the tree.

Screen Shot 2022-04-04 at 2.43.44 PM.png

JMP Systems Engineer, Health and Life Sciences (Pharma)