cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Discussions

Solve problems, and share tips and tricks with other JMP users.
%3CLINGO-SUB%20id%3D%22lingo-sub-225482%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Finding%20the%20X%20range%20that%20will%20include%20a%20certain%20portion%20of%20the%20Y%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-225482%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EYou%20could%20try%20including%20histogram%20borders%20and%20highlighting%20the%20section%20of%20the%20Y%20distribution%20-%20the%20X%20values%20should%20be%20highlighted.%26nbsp%3B%20Then%2C%20if%20you%20want%20to%20examine%20these%2C%20you%20can%20name%20that%20selection%20in%20a%20column%20of%20the%20data%20set%20(e.g.%2C%20points%20of%20interest)%20for%20further%20analysis.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-225519%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Finding%20the%20X%20range%20that%20will%20include%20a%20certain%20portion%20of%20the%20Y%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-225519%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EHi%20%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F15961%22%20target%3D%22_blank%22%3E%40NSadeghi%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Eplease%20have%20a%20look%20at%20this%20script%20and%20let%20us%20know%20if%20it%20is%20useful.%3C%2FP%3E%0A%3CP%3Eperhaps%20someone%20else%20has%20a%20more%20elegant%20way%20of%20doing%20this.%20i%20would%20also%20like%20to%20know%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(%201%20)%3B%0A%0Adt%20%3D%20Open(%20%22%24SAMPLE_DATA%2FBig%20Class.jmp%22%20)%3B%0A%0A%2F%2F%20this%20is%20just%20in%20case%20you%20want%20to%20bring%20the%20data%20back%20to%20original%20row%20order%20later.%0Arowcol%20%3D%20New%20Column(%22Row%22%2C%20Numeric%2C%20%22Continuous%22%2C%20Format(%22Best%22%2C%2012)%2C%20Formula(Row()))%3B%0Adt%20%26lt%3B%26lt%3B%20run%20formulas()%3B%0Arowcol%20%26lt%3B%26lt%3B%20suppress%20eval(%20true%20)%3B%0A%0A%2F%2F%20now%20we%20start%20working%0Adt%20%26lt%3B%26lt%3B%20Sort(%20By(%20%3Aheight%20)%2C%20Order(%20Ascending%20)%2C%20replace%20table%20)%3B%0A%0A%2F%2F%20here%20is%20where%20we%20define%20the%20share%20of%20included%20range%20(0.6)%0Adifcol%20%3D%20New%20Column(%22dif%22%2C%20Numeric%2C%20%22Continuous%22%2C%20Format(%22Best%22%2C%2012)%2C%20Formula(Abs(%3Aheight%20-%20Lag(%3Aheight%2C%20-(N%20Rows()%20*%200.6)))))%3B%0Adt%20%26lt%3B%26lt%3B%20run%20formulas()%3B%0Adifcol%20%26lt%3B%26lt%3B%20suppress%20eval(%20true%20)%3B%0A%0Astart%20%20%3D%20(dt%26lt%3B%3CGET%20rows%3D%22%22%20where%3D%22%22%3E%3D%20start%2C%20row()%26lt%3B%3Dend)%2C1%20%2C0%20%20))%3B%0A%0A%2F%2F%20make%20graphs%20for%20observations%20in%20the%20range%20only.%0ABivariate(%20Y(%20%3Aheight%20)%2C%20X(%20%3Aweight%20)%2C%20Where(%20%3Ainrange%20%3D%3D%201%20)%20)%3B%0A%0AGraph%20Builder(%0A%20Size(%20542%2C%20448%20)%2C%0A%20Show%20Control%20Panel(%200%20)%2C%0A%20Variables(%20X(%20%3Aweight%20)%2C%20Y(%20%3Aheight%20)%20)%2C%20Where(%20%3Ainrange%20%3D%3D%201%20)%2C%0A%20Elements(%20Points(%20X%2C%20Y%2C%20Legend(%203%20)%20)%2C%20Smoother(%20X%2C%20Y%2C%20Legend(%204%20)%20)%20)%0A)%3B%3C%2FGET%3E%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-225520%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Finding%20the%20X%20range%20that%20will%20include%20a%20certain%20portion%20of%20the%20Y%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-225520%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EYou%20find%2C%20select%2C%20and%20subset%20the%20rows%20containing%20the%20(middle)%2060%25%20of%20the%20Y%20values%2C%20and%20then%20examine%20the%20distribution%20of%20the%20associated%20X%20values.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20to%20Here(%201%20)%3B%0A%0Adt%201%20%3D%20Open(%20%22%24SAMPLE_DATA%2FBig%20Class.jmp%22%20)%3B%0A%0Abiv%20%3D%20dt%201%20%26lt%3B%26lt%3B%20Bivariate(%20Y(%20%3Aweight%20)%2C%20X(%20%3Aheight%20)%20)%3B%0A%0Alo%20%3D%20Col%20Quantile(%20%3Aweight%2C%200.2%20)%3B%0Ahi%20%3D%20Col%20Quantile(%20%3Aweight%2C%200.8%20)%3B%0A%0Adt%201%20%26lt%3B%26lt%3B%20Select%20Where(%20lo%20%26lt%3B%3D%20%3Aweight%20%26lt%3B%3D%20hi%20)%3B%0A%0Adt%202%20%3D%20dt%201%20%26lt%3B%26lt%3B%20Subset(%0A%20Selected%20Rows(%201%20)%2C%0A%20Selected%20columns%20only(%200%20)%0A)%3B%0A%0Adist%20%3D%20dt%202%20%26lt%3B%26lt%3B%20Distribution(%20Y(%20%3Aheight%20)%20)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-225474%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EFinding%20the%20X%20range%20that%20will%20include%20a%20certain%20portion%20of%20the%20Y%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-225474%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EHi%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EMy%20problem%20is%20probably%20very%20simple%20but%20I%20just%20don't%20seem%20to%20be%20able%20to%20figure%20it%20out.%3C%2FP%3E%0A%3CP%3EI%20have%20a%20column%20Y%20that%20I%20have%20plotted%20it%20vs%20column%20X%20and%20it%20looks%20something%20like%20the%20attached%20image.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20want%20to%20find%20the%20range%20in%20X%20where%20it%20yields%20(or%20includes)%2060%25%20of%20Y%20points.%20There%20is%20no%20defind%20formula%20that%20relates%20the%202%20columns.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAny%20ideas%3F%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20999px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Fit%20Y%20by%20X.jpg%22%20style%3D%22width%3A%20999px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F19280i5CBE87A114D09FAF%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Fit%20Y%20by%20X.jpg%22%20alt%3D%22Fit%20Y%20by%20X.jpg%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
NSadeghi
Level I

Finding the X range that will include a certain portion of the Y

Hi,

 

My problem is probably very simple but I just don't seem to be able to figure it out.

I have a column Y that I have plotted it vs column X and it looks something like the attached image. 

I want to find the range in X where it yields (or includes) 60% of Y points. There is no defind formula that relates the 2 columns.

 

Any ideas?

Fit Y by X.jpg

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
ron_horne
Super User (Alumni)

Re: Finding the X range that will include a certain portion of the Y

Hi @NSadeghi 

please have a look at this script and let us know if it is useful.

perhaps someone else has a more elegant way of doing this. i would also like to know

Names Default To Here( 1 );

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

// this is just in case you want to bring the data back to original row order later.
rowcol = New Column("Row", Numeric, "Continuous", Format("Best", 12), Formula(Row()));
dt << run formulas();
rowcol << suppress eval( true );

// now we start working
dt << Sort( By( :height ), Order( Ascending ), replace table );

// here is where we define the share of included range (0.6)
difcol = New Column("dif", Numeric, "Continuous", Format("Best", 12), Formula(Abs(:height - Lag(:height, -(N Rows() * 0.6)))));
dt << run formulas();
difcol << suppress eval( true );

start  = (dt<<get rows where(Col minimum (:dif)==:dif))[1];
// here we also mantion the share of included range (0.6)
end = start + nrows(dt)*0.6 -1;

// new binary column for in or out the range
dt << New Column("inrange", Numeric, "Ordinal");
for each row (:inrange = if (and (row() >= start, row()<=end),1 ,0  ));

// make graphs for observations in the range only.
Bivariate( Y( :height ), X( :weight ), Where( :inrange == 1 ) );

Graph Builder(
	Size( 542, 448 ),
	Show Control Panel( 0 ),
	Variables( X( :weight ), Y( :height ) ), Where( :inrange == 1 ),
	Elements( Points( X, Y, Legend( 3 ) ), Smoother( X, Y, Legend( 4 ) ) )
);

View solution in original post

Re: Finding the X range that will include a certain portion of the Y

You find, select, and subset the rows containing the (middle) 60% of the Y values, and then examine the distribution of the associated X values.

 

Names Default to Here( 1 );

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

biv = dt 1 << Bivariate( Y( :weight ), X( :height ) );

lo = Col Quantile( :weight, 0.2 );
hi = Col Quantile( :weight, 0.8 );

dt 1 << Select Where( lo <= :weight <= hi );

dt 2 = dt 1 << Subset(
	Selected Rows( 1 ),
	Selected columns only( 0 )
);

dist = dt 2 << Distribution( Y( :height ) );

View solution in original post

3 REPLIES 3
dale_lehman
Level VII

Re: Finding the X range that will include a certain portion of the Y

You could try including histogram borders and highlighting the section of the Y distribution - the X values should be highlighted.  Then, if you want to examine these, you can name that selection in a column of the data set (e.g., points of interest) for further analysis.

ron_horne
Super User (Alumni)

Re: Finding the X range that will include a certain portion of the Y

Hi @NSadeghi 

please have a look at this script and let us know if it is useful.

perhaps someone else has a more elegant way of doing this. i would also like to know

Names Default To Here( 1 );

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

// this is just in case you want to bring the data back to original row order later.
rowcol = New Column("Row", Numeric, "Continuous", Format("Best", 12), Formula(Row()));
dt << run formulas();
rowcol << suppress eval( true );

// now we start working
dt << Sort( By( :height ), Order( Ascending ), replace table );

// here is where we define the share of included range (0.6)
difcol = New Column("dif", Numeric, "Continuous", Format("Best", 12), Formula(Abs(:height - Lag(:height, -(N Rows() * 0.6)))));
dt << run formulas();
difcol << suppress eval( true );

start  = (dt<<get rows where(Col minimum (:dif)==:dif))[1];
// here we also mantion the share of included range (0.6)
end = start + nrows(dt)*0.6 -1;

// new binary column for in or out the range
dt << New Column("inrange", Numeric, "Ordinal");
for each row (:inrange = if (and (row() >= start, row()<=end),1 ,0  ));

// make graphs for observations in the range only.
Bivariate( Y( :height ), X( :weight ), Where( :inrange == 1 ) );

Graph Builder(
	Size( 542, 448 ),
	Show Control Panel( 0 ),
	Variables( X( :weight ), Y( :height ) ), Where( :inrange == 1 ),
	Elements( Points( X, Y, Legend( 3 ) ), Smoother( X, Y, Legend( 4 ) ) )
);

Re: Finding the X range that will include a certain portion of the Y

You find, select, and subset the rows containing the (middle) 60% of the Y values, and then examine the distribution of the associated X values.

 

Names Default to Here( 1 );

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

biv = dt 1 << Bivariate( Y( :weight ), X( :height ) );

lo = Col Quantile( :weight, 0.2 );
hi = Col Quantile( :weight, 0.8 );

dt 1 << Select Where( lo <= :weight <= hi );

dt 2 = dt 1 << Subset(
	Selected Rows( 1 ),
	Selected columns only( 0 )
);

dist = dt 2 << Distribution( Y( :height ) );

Recommended Articles