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
r30363
Level II

how to make cumulative probability plots in JMP?

How can I make cumulative probability plot like the one below? Appreciate your help.

r30363_0-1658152068599.png

 

 

36 REPLIES 36
jthi
Super User

Re: how to make cumulative probability plots in JMP?

These two topics might be helpful:

You might be able to use similar methods with Variables (search Graph Builder Box from Scripting Index).

 

-Jarmo
hogi
Level XII

Re: how to make cumulative probability plots in JMP?

"remove variable" - just in front of my eyes, but I did not see it.

Many thanks

hogi_0-1677100587366.png

 

Names Default To Here( 1 );


dt = Current Data Table();


updatePlot2 = Function( {},
	If( Length( clb << get selected ) == 0 | Length( clb2 << get selected ) == 0,
		Print( "value missing" ),
		gbr = Report( gb );
		gbb = gbr[Graph Builder Box( 1 )];
		var = (clb << get selected)[1];
		groupByvar = (clb2 << get selected)[1];

		allVariables = (gbb << get variables);
		For Each( {var, idx}, Reverse( allVariables ),
			gbb << remove variable( {var[1] , Role(  Arg( var[2] ) )} )
		);

		gbb << add variable( {Column( var ), Role( "X" )} );
		
		Eval(
			Eval Expr(
				gbb << add variable(
					{Transform Column(
						"Cumulative Probability[1=100%]",
						Formula(
							Col Rank( Expr( Name Expr( As Column( var ) ) ), Expr( Name Expr( As Column( groupByvar ) ) ),Excluded() ) / (
							Col Number( Expr( Name Expr( As Column( var ) ) ), Expr( Name Expr( As Column( groupByvar ) ) ),Excluded() ) + 1)
						)
					), Role( "Y" )}
				)
			)
		);
		
		gbb << add variable( {Column( groupByvar ) , Role( "Overlay" )} ) ;
		
// SendToReport( Dispatch( {}, "Cumulative Probability[1=100%]", ScaleBox, {Scale( "Normal Probability" ), Format( "Best", 12 )} ) ) yAxis = ((gb << xpath( "//ScaleBox" ))[2]); yAxis << {Scale( "Normal Probability" ), Format( "Best", 12 ), Title}; gb << getXML(); ) ); gbWindow = New Window( "Grouped Cumulative Probability", hlb = H List Box( V List Box( Panel Box( "Value", clb = Col List Box( all, <<Set Data Type( "numeric" ), max selected( 1 ), updatePlot2() ) ), Panel Box( "group by", clb2 = Col List Box( all, max selected( 1 ), updatePlot2() ) ) ), gb = dt << Graph Builder( Size( 724, 560 ), Show Control Panel( 0 ), Elements( Points( X, Y, Legend( 7 ) ), Smoother( X, Y, Legend( 8 ), Method( "Savitzky-Golay" ), Lambda( 2 ) ) ), SendToReport( Dispatch( {}, "Cumulative Probability[1=100%]", ScaleBox, {Scale( "Normal Probability" ), Format( "Best", 12 )} ) ) ) ) );

updates: 
- remove & add variable (Y) deletes the normal probability setting on this axis
->  send the normal probability   command again

- new problem: when running the "transform column" a second time and more often, jmp adds a counter to the name on the y axis: Cumulative Probability[1=100%] XX -> Y axis no longer accessible by its original name
-> get the y axis title via xPath

- Excluded() added in the Col... functions to force jmp to ignore excluded() rows in the calculation.

 

hogi
Level XII

Re: how to make cumulative probability plots in JMP?

edit: unfortunately, this code is wrong - see below 
... but can be fixed - see further below

I just detected the Cumulative Percent entry in the Summary settings:

hogi_5-1725887783933.png

 

This way it gets very easy to generate a grouped CDF Plot - even with the possibility to use a column switcher:

hogi_6-1725887814243.png

 

 

Names Default To Here( 1 );

dt = Current Data Table();

myCols = {};

ex = New Window( "Modal Dialog example",
	"Modal",
	V List Box(
		Lineup Box( N Col( 2 ),
			Panel Box( "", fcs = Filter Col Selector() ),
			Panel Box( "",
				Lineup Box( N Col( 2 ),
					Button Box( "variables", variableColsLB << append( fcs << get selected ) ),
					variableColsLB = Col List Box(Continuous, width( 200 ), min items( 1 ), nlines( 10 ) ),
					Button Box( "group by", groupColLB << append( fcs << get selected ) ),
					groupColLB = Col List Box( Nominal, width( 200 ), max items( 1 ), min items( 1 ), nlines( 1 ) )
				)
			)
		),
		H List Box(
			Button Box( "OK",
				For Each( {col, idx}, variableColsLB << get items(), Insert Into( myCols, Name Expr( As Column( dt, col ) ) ) );
				groupColName = (groupColLB << get items)[1];
				groupCol = Name Expr( As Column( dt, groupColName ) );
			),
			Button Box( "cancel" )
		)
	)
);

If(
	Not( ex["button"] == 1 ), Stop(),
	N Items( myCols ) == 0,
		Stop()
	
);

col1 = myCols[1];

Eval(
	Substitute(
			Expr(
				dt << Graph Builder(
					Show Control Panel( 0 ),
					Show Title( 0 ),
					Size( 500, 300 ),
					Variables( X( __col1__ ), 
					Y( __col1__ ), // here is the error: use a column with "1"s instead to make it right
Overlay( __groupCol__ ) ), Elements( Points( X, Y, Summary Statistic( "Cumulative Percent" ) ) ), Column Switcher( __col1__, __myCols__ ), SendToReport( Dispatch( {}, "Graph Builder", OutlineBox, {Set Title( "Cumulative Distribution Plot" ), Image Export Display( Normal )} ) ) ) ), Expr( __col1__ ), Name Expr( col1 ), Expr( __myCols__ ), Name Expr( myCols ), Expr( __groupCol__ ), Name Expr( groupCol ), ) );

 

Mauro_Gerber
Level IV

Re: how to make cumulative probability plots in JMP?

//librecall:storeRoles( "CDF", verbose );

I had to mute the librecall function since I get an error in JMP17. But it seems it works without it just fine.

 

Can we mark this as solved @r30363 ?

 

 

"I thought about our dilemma, and I came up with a solution that I honestly think works out best for one of both of us"
- GLaDOS
hogi
Level XII

Re: how to make cumulative probability plots in JMP?

Thanks, I removed it.

Thomas1
Level V

Re: how to make cumulative probability plots in JMP?

Thanks for this great JSL code.

hogi
Level XII

Re: how to make cumulative probability plots in JMP?

Ouch -  sorry, unfortunately, the code doesn't do what it should do.

Cumulative Percent sounded like Cumulative Probability [%] , but unfortunately, it doesn't sum ONES and divide by N, it sums the individual values and divides by the sum of all values:

hogi_0-1678125330242.png

 

If the values are "similar", it's a quick hack to get something similar to CDF, but e.g. if the values start from 0 - or are even negative, the plot differs significantly from a CDF.

So close - but too far to fix it, right?

 

 

hogi_2-1678125597146.png

 

 

dt = Open( "$SAMPLE_DATA/Airline Delays.jmp" );
dt << Graph Builder(
	Variables( X( :Arrival Delay ), Y( :Arrival Delay ), Overlay( :Airline ) ),
	Elements(
		Points( X, Y, Legend( 6 ), Summary Statistic( "Cumulative Percent" ) )
	)
);

 

hogi
Level XII

Re: how to make cumulative probability plots in JMP?

I posted a wish to add Cumulative Probability as an additional option for summary Statistics in Graph Builder:
Summary Statistics: add Cumulative Probability 

 

So, perhaps in Jmp18 it will be THAT EASY to generate a grouped Cumulative Probability Plot in Graph Builder.

 

The huge advantage compared to https://community.jmp.com/t5/Discussions/how-to-make-cumulative-probability-plots-in-JMP/m-p/607570/... :It would be compatible with the Column Switcher Feature of Graph Builder. No need to generate a GUI around the plot.

Mauro_Gerber
Level IV

Re: how to make cumulative probability plots in JMP?

@hogi :

Mauro_Gerber_0-1679466946825.png

 

"I thought about our dilemma, and I came up with a solution that I honestly think works out best for one of both of us"
- GLaDOS
hogi
Level XII

Re: how to make cumulative probability plots in JMP?

@Mauro Thanks a lot for the Kudo - an also for the other 3.
With 4 Kudos this feature should be kind of save to appear in a future Jmp version