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
timloaami
Level I

Data Filter stopped in a for-loop

I am writing a for-loop script to search for the x-values of the y-maximum peaks in some parts of the spectra collected in different experimental conditions. However, the Data Filter stopped after running one round by the warning "Your selection was changed in another window." How can I get rid of this warning so that the script can be run smoothly to complete the for-loop?

 

Let me use Big Class.jmp example to demonstrate the problem. The objective is to show the subset of data corresponding to the people having the maximum weight (y-maximum value) in several ranges of heights (x-value ranges, say 55-60, 60-62, 62-65) by different ages (similar to experimental conditions).

 

The x-value ranges are grouped by two lists, one containing the lower limits & another one the upper limits. The maximum is found by Col Maximum with Data Filter. The calculation is looped for several x-value ranges along the lists. However, after running for i=1, the loop stops and the Data Filter warning appears. How to get rid of it to let the script complete the for-loop?

 

 

Names Default To Here( 1 );
ListA = {55, 60, 62};
ListB = {60, 62, 65};
for(i=1, i<=3, i++,
dt = Data Table( "Big Class" );
Current Data Table (dt);
a = ListA[i];
b = ListB[i];
dt << Data Filter(Add Filter(columns(:height), where(:height > a & :height < b)), Mode( Select( 0 ), Show( 0 ), Include( 1 )), Show Window(0), Auto Clear(1));
dt << select where (col maximum(:weight, :age, Excluded()) == :weight & :height > a & :height < b);
dt << subset(selected rows(1), columns({"name", "age", "sex", "height", "weight"}));
dt << Clear Row States;
dt << Clear Select();
);

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
hogi
Level XII

Re: Data Filter stopped in a for-loop

Please have a look at the documentation of Col Max - actually it can do all the job that is needed.
Just use an auxiliary column height_bin (e.g. via Transform Column). No need for a data filter ...

hogi_2-1731756851249.png

according to this table, it's James, Barbara, Judy and Marion.
If you want to define the the height_bins via a Data Filter, make sure that you don't miss the junction points, e.g. height=60.

 

Names Default To Here( 1 );

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

dt  << New Column( "height_bin",
"Character",
	Formula(
		If(
			:height < 60, "<60",
			:height <62, "<62",
			">=62"
		)
	) );
	
New Column( "weight_max",
	Formula( Col Maximum( :weight, :age, :height_bin ) )
);
	
New Column( "is max",nominal,
	Formula( :weight == :weight_max ),
);

Graph Builder(
	Variables( X( :age ), Y( :weight ), Group Y( :height_bin ) ),
	Elements( Bar( X, Y, Label( "Label by Row" ) ) ),
	Local Data Filter( Add Filter( columns( :is max ), Where( :is max == 1 ) ) )
);

View solution in original post

3 REPLIES 3
txnelson
Super User

Re: Data Filter stopped in a for-loop

I believe the simplified JSL below gives you what you want.

Names Default To Here( 1 );
dt = 
// Open Data Table: semiconductor capability.jmp
// → Data Table( "semiconductor capability" )
Open( "$SAMPLE_DATA/big class.jmp" );

ListA = {55, 60, 62};
ListB = {60, 62, 65};

	
For( i = 1, i <= 3, i++,
	a = ListA[i];
	b = ListB[i];
	Current Data Table( dt );
	theMax = Col Maximum( If( :weight & :height > a & :height < b, :weight, . ) );
	dt << select where( theMax == :weight & :height > a & :height < b );
	If( N Rows( dt << get selected rows ) > 0,
		dt << subset( selected rows( 1 ), columns( {"name", "age", "sex", "height", "weight"} ) )
	);
	dt << Clear Row States;
	Wait( 0 );
);
Jim
timloaami
Level I

Re: Data Filter stopped in a for-loop

However, this script does not have the "by age" function. For example, in my script, when i = 2 (ListA = 60, ListB = 62), the result is

 

NameAgeSexHeightWeight
JAMES12M61128
ALICE13F61107
JUDY14F6181

 

However, your script gives the corresponding part as

 

NameAgeSexHeightWeight
JAMES12M61128

 

This is because my script has the "by age" part in Col Maximum. Unfortunately, even if I add "by age" part in your script:

theMax = Col Maximum( If( :weight & :height > a & :height < b, :weight, . ), :age );

An alert appears: "Invalid Row Number"

 

Your script runs smoothly. How can we add the "by age" part in Col Maximum in your script?

hogi
Level XII

Re: Data Filter stopped in a for-loop

Please have a look at the documentation of Col Max - actually it can do all the job that is needed.
Just use an auxiliary column height_bin (e.g. via Transform Column). No need for a data filter ...

hogi_2-1731756851249.png

according to this table, it's James, Barbara, Judy and Marion.
If you want to define the the height_bins via a Data Filter, make sure that you don't miss the junction points, e.g. height=60.

 

Names Default To Here( 1 );

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

dt  << New Column( "height_bin",
"Character",
	Formula(
		If(
			:height < 60, "<60",
			:height <62, "<62",
			">=62"
		)
	) );
	
New Column( "weight_max",
	Formula( Col Maximum( :weight, :age, :height_bin ) )
);
	
New Column( "is max",nominal,
	Formula( :weight == :weight_max ),
);

Graph Builder(
	Variables( X( :age ), Y( :weight ), Group Y( :height_bin ) ),
	Elements( Bar( X, Y, Label( "Label by Row" ) ) ),
	Local Data Filter( Add Filter( columns( :is max ), Where( :is max == 1 ) ) )
);