cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
lwx228
Level VIII

How do I use JSL to categorize positive and negative values in the same column?

According to the data of the "weight" column in document "Arrhythmia" 、and the "criterion" file in the attachment, the "level" column is obtained.

Then, according to the "level" column and "class" column, the data of "V3 QRSTA" column are classified according to the following rules:
Row basis is "level", column basis is "class", and positive value and negative value of "V3 QRSTA" column are classified and summarized respectively.

2019-07-18_15-43-22.png


The above operations can be easily completed with excel and its functions, but the speed is slow when the data volume is large.


If the amount of data is large, how to use JMP JSL should be completed more quickly.Thank you very much!
This problem is quite complicated. I made several pictures and uploaded 2 files.

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How do I use JSL to categorize positive and negative values in the same column?

Here is an example of one way to do the processing to set the grade for each raw data row.  I have it set to have an Example data table of 50,000, which on my 4 year olf Window's pc takes about 2 seconds to create the example data and then to set the grade for each row.

Names Default To Here( 1 );

// Create a sample standards table
dtStandard = New Table( "Standards",
	Add Rows( 200 ),
	New Column( "standards", formula( Random Integer( 93500, 1000000 ) ) )
);
dtStandard << run formulas;
dtStandard:standards << delete property( "formula" );
dtStandard << sort( by( :standards ), order( ascending ), replace table( 1 ) );
dtStandard << rerun formulas;
dtStandard << New Column( "grades", formula( Row() ) );
dtStandard:grades << delete property( "formula" );

// Create an example table
dt = New Table( "Example",
	Add Rows( 50000 ),
	New Column( "Raw Data", formula( Random Integer( 93500, 1000000 ) ) )
);
dt << run formulas;
dt:Raw Data << delete property( "formula" );

// Make sure the standards table has the same range as the example table
If( dtStandard:standards[1] > Col Min( dt:raw data ),
	dtStandard:standards[1] = Col Min( dt:raw data )
);
If( dtStandard:standards[200] < Col Max( dt:raw data ),
	dtStandard:standards[200] = Col Max( dt:raw data )
);

// Set the standard
// The code below is the actual code that performs the setting of the grade

// Create a column to hold the original row positions in the data table
dt << New Column( "OrigRow", formula( Row() ) );
dt:OrigRow << delete property( "formula" );

// Add the new grades column to the Example data
dt << New Column( "grade" );

// Sort the data in order of the raw data
dt << sort( by( :Raw Data ), order( ascending ), replace table( 1 ) );

For( i = 1, i <= N Rows( dt ), i++,
	If( i == 1,
		lkupRow = Max( dtStandard << get rows where( dtStandard:standards <= dt:Raw Data[i] ) )
	);
	While( dtStandard:standards[lkupRow] < dt:Raw Data[i], lkupRow = lkupRow + 1 );
	dt:grade[i] = dtStandard:grades[lkupRow];
);

// Sort the data back to the original order
dt << sort( by( :OrigRow ), order( ascending ), replace table( 1 ) );

// Delete the origrow column
dt << delete columns( "OrigRow" );
Jim

View solution in original post

22 REPLIES 22
lwx228
Level VIII

Re: How do I use JSL to categorize positive and negative values in the same column?

dt = Open( "$SAMPLE_DATA/Arrhythmia.jmp" );

 

 

lwx228
Level VIII

Re: How do I use JSL to categorize positive and negative values in the same column?

2019-07-18_15-50-57.png

 

lwx228
Level VIII

Re: How do I use JSL to categorize positive and negative values in the same column?

When I did it myself, I added three columns to file Arrhythmia.jmp :"level"、"positive"、"negative".
I know it's stupid, but it's the only way I can handle it.Thank you very much!

lwx228
Level VIII

Re: How do I use JSL to categorize positive and negative values in the same column?

It seems that there are many steps in my project, so I need to complete it in several steps:
Solve the first step above all: how to divide "weight" column by the "criterion" in accessory a few grades.

 

2019-07-19_21-45-47.png

lwx228
Level VIII

Re: How do I use JSL to categorize positive and negative values in the same column?

See screenshot for standard: The operation of this step, I can only use the way of "IF". Excel has several functions that do this. How does JSL do this quickly?Thank you very much!

txnelson
Super User

Re: How do I use JSL to categorize positive and negative values in the same column?

This can be handled easily in a JMP formula

If(weight<=30, 1
weight <= 40, 2,
weight <= 50, 3,

etc.

)
Jim
lwx228
Level VIII

Re: How do I use JSL to categorize positive and negative values in the same column?

Thank Jim!

but If this grade classification reaches more than 100, such classification method code is more cumbersome.

Re: How do I use JSL to categorize positive and negative values in the same column?

If you had the classification in a table as shown above, a script could easily create the expression for the necessary If() function. Or you could use the approach of lookup in such a table.

 

More than 100 classes? Would they be meaningful or useful? At this point you might want to just use the original continuous variable.

lwx228
Level VIII

Re: How do I use JSL to categorize positive and negative values in the same column?

Thank you for your time.