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%3ERi%3A%20Trovare%20l'intervallo%20X%20che%20includer%C3%A0%20una%20certa%20porzione%20di%20Y%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-225482%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EPotresti%20provare%20ad%20includere%20i%20bordi%20dell'istogramma%20ed%20evidenziare%20la%20sezione%20della%20distribuzione%20Y%3A%20i%20valori%20X%20dovrebbero%20essere%20evidenziati.%26nbsp%3B%20Quindi%2C%20se%20si%20desidera%20esaminarli%2C%20%C3%A8%20possibile%20assegnare%20un%20nome%20a%20quella%20selezione%20in%20una%20colonna%20del%20set%20di%20dati%20(ad%20es.%20Punti%20di%20interesse)%20per%20ulteriori%20analisi.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-225519%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERi%3A%20Trovare%20l'intervallo%20X%20che%20includer%C3%A0%20una%20certa%20porzione%20di%20Y%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-225519%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ECiao%20%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F15961%22%20target%3D%22_blank%22%3E%20%40NSadeghi%20%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Eper%20favore%20dai%20un'occhiata%20a%20questo%20script%20e%20facci%20sapere%20se%20%C3%A8%20utile.%3C%2FP%3E%0A%3CP%3Eforse%20qualcun%20altro%20ha%20un%20modo%20pi%C3%B9%20elegante%20di%20farlo.%20vorrei%20anche%20sapere%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%3ERi%3A%20Trovare%20l'intervallo%20X%20che%20includer%C3%A0%20una%20certa%20porzione%20di%20Y%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-225520%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%C3%88%20possibile%20trovare%2C%20selezionare%20e%20sottoinsieme%20le%20righe%20contenenti%20il%20(medio)%2060%25%20dei%20valori%20Y%2C%20quindi%20esaminare%20la%20distribuzione%20dei%20valori%20X%20associati.%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%3ETrovare%20l'intervallo%20X%20che%20includer%C3%A0%20una%20certa%20porzione%20di%20Y%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-225474%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ECiao%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIl%20mio%20problema%20%C3%A8%20probabilmente%20molto%20semplice%20ma%20non%20riesco%20proprio%20a%20capirlo.%3C%2FP%3E%0A%3CP%3EHo%20una%20colonna%20Y%20che%20l'ho%20tracciata%20rispetto%20alla%20colonna%20X%20e%20sembra%20qualcosa%20come%20l'immagine%20allegata.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EVoglio%20trovare%20l'intervallo%20in%20X%20dove%20fornisce%20(o%20include)%20il%2060%25%20di%20punti%20Y.%20Non%20esiste%20una%20formula%20di%20definizione%20che%20collega%20le%202%20colonne.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EQualche%20idea%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