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
Marco1
Level IV

Can JMP show the probability of 1 result or range through a graph?

Hello everyone!!!, a question:
What graph in JMP can answer the probabilities of obtaining a value or range of response, for example like the following graph.

Marco1_0-1699317866245.png

Greetings,

Marco

 

57 REPLIES 57
Marco1
Level IV

Re: Can JMP show the probability of 1 result or range through a graph?

Hello Hogi,

Attached I share a simple example applying your idea in JMP, when comparing it with the graphs of the initial example, it seems that the calculation method is not the same and it does not have the sliding bar for ranges. I still think JMP can have a bar chart equal to or better than the initial example I shared.

Greetings,

Marco

Marco1
Level IV

Re: Can JMP show the probability of 1 result or range through a graph?

Hello Hogi,

Attached I share a simple example applying your idea in JMP, when comparing it with the graphs of the initial example, it seems that the calculation method is not the same and it does not have the sliding bar for ranges. I still think JMP can have a bar chart equal to or better than the initial example I shared.

Greetings,

Marco

jthi
Super User

Re: Can JMP show the probability of 1 result or range through a graph?

You can script this and make it look quite nice, but the graph builder option with (global) data filter  is much more simple to implement (there are also most likely other platforms which can do somewhat what you want).

 

Below is an IDEA what can be done with scripting, it is not finished script and could (and should) be improved

View more...
Names Default To Here(1);

dt = Open("$DOWNLOADS/Certainty Formula.jmp");
dt << Clear Select;

lowval = 200;
maxval = 10000;

nw = New Window("plot",
	V List Box(
		dist = dt << Distribution(
			Stack(1),
			Continuous Distribution(
				Column(:Total sale),
				Horizontal Layout(1),
				Vertical(0),
				Count Axis(1),
				Prob Axis(1)
			),
			Histograms Only,
			SendToReport(
				Dispatch(
					{"Total sale"},
					"1",
					ScaleBox,
					{Inc(200), Minor Ticks(0)} //inc should be made changeable
				),
				Dispatch(
					{"Total sale"},
					"Distrib Histogram",
					FrameBox,
					{Frame Size(889, 391)}
				)
			)
		),
		H List Box(
			neb_min = number edit box(lowval, << Enabled(0)),
			sb = Range Slider Box(
				-500,
				15000,
				lowval,
				maxval,
				dt << Select Where(
					:Total sale >= lowval & :Total sale <= maxval, current selection("clear")
				);
				sel_rows = dt << get selected rows;
				tb << Set Text(	
					Char(Round((Sum(:Total Sale[sel_rows]) / Col Sum(:Total Sale))*100, 2)) || "%"
				);
				neb_min << Set(lowval);
				neb_max << Set(maxval);
			),
			neb_max = Number Edit Box(maxval, << Enabled(0))
		),
		H Center Box(
			H List Box(
				Text Box("Certainty:"),
				tb = Text Box("")
			)
		)
	)
);
sb << Set Width(700);

fb = Report(dist)[FrameBox(1)];
fb << Add Graphics Script(
	Pen Color("Blue");
	Pen Size(2);
	V Line(lowval);
	V Line(maxval);
);

jthi_0-1699627281580.png

 

-Jarmo
Marco1
Level IV

Re: Can JMP show the probability of 1 result or range through a graph?

Hello JTHI,

I'm glad to greet you! I couldn't apply your motivating and great idea to the example in JMP that I shared (Certainty Formula.jmp), the image you share shows that JMP can equal or even improve the way of answering questions about certainty, If possible, could you share the script that works with any new example or an add-in for JMP?

Greetings,

Marco

jthi
Super User

Re: Can JMP show the probability of 1 result or range through a graph?

I can make an example script which is a bit better written when I have some extra time.

-Jarmo
Marco1
Level IV

Re: Can JMP show the probability of 1 result or range through a graph?

Hello JTHI,

Sure, when you have time... I think JMP has as many options to achieve the example I shared, as there are grains of sand on a beach.

Greetings,

Marco

jthi
Super User

Re: Can JMP show the probability of 1 result or range through a graph?

This code isn't commented and it is messy, but it might function as first working version. I haven't verified if the calculations are correct, I just tried to get the graph working properly (I'm not selecting values from data table as it provides more flexibility for the graph BUT it can have it's limits on something else)

View more...
/*""" https://community.jmp.com/t5/Discussions/Can-JMP-show-the-probability-of-1-result-or-range-through-a/m-p/696981

Author: jthi
Creation Date: 2023-11-11
Creation JMP Version: JMP Pro 17.2

Description: Custom "platform"

Todo:
    * Cleanup script
    * Add comments
    * Add settings (bin counts and such)
    * Make into addin
    * Fix to work with different types of datasets (bin calculation might need some work regarding this)
    
    * Don't create new column during initialization --- DONE
	
"""*/

Names Default To Here(1);


If(N Table() == 0,
	Throw("No tables open");
);


dt = Current Data Table();

nw = New Window("Select Column", << Modal, << Return result,
	Tab Box(
		Tab Page Box("Select Column",
			fcs = Filter Col Selector(
				Data Table(dt),
				<< Character(0),
				<< Nominal(0),
				<< Ordinal(0)
			),
			<< Set Base Font("Title")
		),
		Tab Page Box("Cast Column",
			Lineup Box(N Col(2),
				Button Box("Add", << Set Function(function({this},
					clb << Set Items((fcs << get selected)[1])
				))),
				clb = Col List Box(Datatable(dt), << Set Data Type("Numeric"))
			),
			<< Set Base Font("Title")
		),
		Tab Page Box("Actions",
			Lineup Box(N Col(2),
				Button Box("OK",
					col_of_interest = clb << get items;
				),
				Button Box("Cancel"),
			),
			<< Set Base Font("Title")
		), << Set Style("Horizontal Spread")
	)
);

If(nw["Button"] != 1,
	Throw("Cancelled");
);

If(N Items(col_of_interest) < 1,
	Throw("No columns selected");
,
	col_of_interest = col_of_interest[1];
);

Try( // lazy solution


colref = Column(dt, col_of_interest);

bin_count = Ceiling(Sqrt(N Rows(dt)));
data_max = Col Max(colref);
data_min = Col Min(colref);
data_range =  data_max - data_min;
bin_width = data_range/bin_count;

/*
new_col = dt << New Column("Bins", Numeric, Continuous, << Set Each Value(
	If(
		colref[] < data_min, data_min,
		colref[] >= data_max, data_max,
		bin_width * Floor(colref[] / bin_width)
	);	
));

Summarize(dt, bins = by(:Bins), freq = Count(colref));
dt << Delete Columns(new_col);
*/

aa = Associative Array();
For Each Row(dt,
	cur_bin = If(
		colref[] < data_min, data_min,
		colref[] >= data_max, data_max,
		bin_width * Floor(colref[] / bin_width)
	);
	If(!Contains(aa, char(cur_bin)),
		aa[char(cur_bin)] = 1;
	,
		aa[char(cur_bin)]++;
	);
);


bins = Transform Each({{key, val}}, aa, Output("List"), Num(key));
bins = Matrix(bins);
rbins = Rank(bins);
bins = bins[rbins];
freq = (aa << get values)[rbins];

lowval = data_min;
highval = data_max;

plot_histogram = Expr(
	try(histogram << delete);
	histogram_collector << Append(histogram = Graph Box(
		Frame Size(1200, 500),
		X Name(col_of_interest),
		// Y Scale(0, Max(freq) * 1.1),
		X Scale(data_min - data_max * 0.05, data_max * 1.05),
		//X Scale(data_min - data_max * 0.05, data_max * 1.05),
		Y Axis(Scale ID(1), Side(1), Min(0), Max(Max(freq) * 1.05)),
		Y Axis(Scale ID(2), Side(2), Min(0), Max(data_max / Sum(bins) * 1.05)),
		Pen Color("Black"),
		Transparency(0.5),
		For (i = 1 , i < nrow(bins), i++,
			If(bins[i] + bin_width > lowval & bins[i] < highval,
				Fill Color("Blue");
			,
				Fill Color("Red");
			);
			Rect(bins[i], freq[i], bins[i + 1], 0, 1);
		);
		Pen Color("Black"),
		Transparency(1),
		For(i = 1, i < N Row(bins), i++,
			Rect(bins[i], freq[i], bins[i + 1], 0, 0)
		)
	));
	histogram << Set Y Name("Frequency", 1);
	histogram << Set Y Name("Probability", 2);
	histogram[AxisBox(2)] << Format("Percent", 15, 2) << Inc(0.001);
	histogram[TextEditBox(1)] << Rotate Text("Left");
	histogram[TextEditBox(2)] << Rotate Text("Right");

	histogram[AxisBox(1)] << Show Minor Grid(1);
	histogram[AxisBox(1)] << Show Major Grid(1);
	histogram[FrameBox(1)] << Add Graphics Script(
		Pen Size(3);
		Pen Color("Blue");
		V Line(lowval);
		V Line(highval);
	);
);

update_certainty = Expr(
	val_idx = Loc(lowval < bins < highval);
	cert_perc = Round(100 * Sum((bins  freq)[val_idx]) / Sum(bins  freq), 2);
	tb_val << Set Text(Char(cert_perc) ||"%");
);

update_window = Expr(
	plot_histogram;
	update_certainty;
);

left_padding = 56;
right_padding = 70;

nw = New Window("Forecast " || col_of_interest,
	V List Box(
		H Center Box(Text Box("Frequency Chart for " || col_of_interest, << Set Font Size(16), << Set Font Style("Bold"), << Set Wrap(1000))),
		histogram_collector = V List Box(),
		H List Box(
			Spacer Box(Size(left_padding, 0)),
			rsb = Range Slider Box(data_min - data_max * 0.04, data_max * 1.04, lowval, highval,
				neblow << Set(lowval, run script(0));
				nebhigh << Set(highval, run script(0));
				update_window;
				histogram << Inval;
			),
		),
		H Center Box(
			H List Box(
				Text Box("Certainty: "),
				tb_val = Text Box("100%"),
			)
		),
		H List Box(
			Spacer Box(Size(left_padding, 0)),
			neblow = Number Edit Box(lowval, <<Set Function(Function({this}, // << Set Number Changed is too aggressive
				rsb << Set Lower(this << get, 1, run script(1));
			))),
			Spacer Box(Size(1000 - right_padding, 0)),
			nebhigh = Number Edit Box(highval, <<Set Function(Function({this}, 
				rsb << Set Upper(this << get, 1, run script(1));
			)))
		)
	)
);
nw << Show Window(0);

update_window;
nw << Update Window;

left_padding = (histogram[AxisBox(1)] << get size)[1];
right_padding = (histogram[AxisBox(2)] << get size)[1];
rsb << Set Width(1200);
wait(0);
nw << Show Window(1);

, // catch
show(exception_msg);
Try(nw << Close Window);
);

 

jthi_0-1699731721192.png

jthi_3-1699732084483.png

 

 

Other dataset (JMP's example data Probe.jmp)

jthi_2-1699732063536.png

 

JMP's Diabetes.jmp table

jthi_4-1699732260371.png

 

-Jarmo
hogi
Level XII

Re: Can JMP show the probability of 1 result or range through a graph?

Nice

And here is more or less the same as a Jmp application.

Edit: Fill selection mode changed to "selected same color". 
colors can be changes via File/Preferences ...

 


edit: [copy paste error]  code adjusted
probability calculated via #_selected/ #_total (same as : Col Number(selected())/#_total )
[before: Sum()/Sum()]

hogi
Level XII

Re: Can JMP show the probability of 1 result or range through a graph?

Lessons learned:

  • by default there is no range slider box in Application Builder - so it has to be added manually. Then it shows up in the editor - but there is no possibility to adjust the settings via the GUI - just via JSL commands.
  • In the column variables,
    hogi_0-1699735771073.png
    the columns are saved as lists: *)
    myCol = {:Total sale}

    beautiful idea
    -> myCol can be used directly as an argument in formulas, so the ultimate fix for Custom Function - how to reference the column 
    and one can use myCol[1] to get the actual column - unevaluated

Marco1
Level IV

Re: Can JMP show the probability of 1 result or range through a graph?

Hello Hogi,

Another Ingenious solution!!!, three questions:

1. The chart could accept placing the minimum and maximum number (range)
2. Could the script accept more than 1 objective?
3. Can it be an add-in for JMP?

Greetings,

Marco