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

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
Harck
Level I

Customizing Box Plot in varibility chart to Display Sigma-Based Intervals

Hello everyone,

I am currently working with JMP and using box plots to visualize my data. I noticed that it is possible to configure the display of outliers or quantiles, but I would like to know if it is possible to modify the box plot settings to show intervals based on standard deviations (sigma) around the mean, instead of the usual quartiles.

For example, I would like the box to represent mean ± 3 sigma, and the whiskers to represent ± 4 sigma or ± 6 sigma, in order to better visualize statistical dispersion using this approach.

Does anyone know if this can be done directly in JMP? If yes, could you please guide me on how to set this up or if there is a specific script or option available?

Thank you in advance for your help!

2 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: Customizing Box Plot in varibility chart to Display Sigma-Based Intervals

I would consider having box plot with standard deviations confusing as box plots utilize median and quantiles.  

Here is very hard-coded idea to demonstrate single rectangle with a line (no whiskers but they could be added with Line())

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Variability Data/2 Factors Crossed.jmp");
obj = dt << Variability Chart(
	Y(:Measurement),
	X(:Operator, :part#),
	Model("Crossed")
);

fb = Report(obj)[FrameBox(1)];

ms = fb << Find Seg(MarkerSeg(1));

xs = ms << Get X Values;
ys = ms << Get Y Values;

v = ys[1::3];

s = Std Dev(v);
m = Mean(v);

fb << Add Graphics Script(
	Pen Size(3);
	Pen Color("Green");
	Rect(0.35, 3*s + m, 0.75, -3*s+m);
	Pen Color("Blue");
	Line({0.35, m}, {0.75, m})
);

jthi_0-1761673757132.png

I don't know how much data you have, but you could consider overlaying distribution instead of using the rectangles

jthi_1-1761673938763.png

or violin plots

jthi_2-1761674004365.png

-Jarmo

View solution in original post

jthi
Super User

Re: Customizing Box Plot in varibility chart to Display Sigma-Based Intervals

You have to do the looping inside the Graphic Script (and possibly evaluate some variables inside it).

-Jarmo

View solution in original post

8 REPLIES 8
jthi
Super User

Re: Customizing Box Plot in varibility chart to Display Sigma-Based Intervals

You would have to write a graphical script for such visualizations.

Some links regarding box plots:

-Jarmo
Harck
Level I

Re: Customizing Box Plot in varibility chart to Display Sigma-Based Intervals

Thank you very much, Jarmo.

I already have many scripts completed (variabilty chart, graph builder) , and I will share an example where I need this type of box plot (standard deviation). However, the actual preference is for a quantile box plot rather than a standard deviation box plot. I have read your suggestions but haven’t seen any examples using standard deviation. Could you please advise on how to create a visualization incorporating standard deviation?

To summarize I would like Box Type = Std dev ( quantile NO, Outliers NO)

VarChart = dt << Variability Chart(
		Invisible,
		Y( Eval( Y_list ) ),
		X( Eval( X_list ) ),
		Analysis Type( "Choose best analysis (EMS REML Bayesian)" ),
		Show Range Bars( 0 ),
		Connect Cell Means( 1 ),
		Variability Summary Report( 1 ),
		Std Dev Chart( 0 ),
		Points Jittered( 1 ),
		Show Box Plots( 1 ),
		Local Data Filter(
			Add Filter( 
			columns( :Temperature, :Corner, :Revision, :XY ),
			 )
		),
		SendToReport(
			Dispatch( {}, "Mean", NumberColBox, {Set Format( "Fixed Dec", 8, 3 )} ),
			Dispatch(
				{},
				"Std Dev",
				NumberColBox,
				{Set Format( "Fixed Dec", 8, 3 )}
			),
			Dispatch(
				{},
				"Minimum",
				NumberColBox,
				{Set Format( "Fixed Dec", 8, 3 )}
			),
			Dispatch(
				{},
				"Maximum",
				NumberColBox,
				{Set Format( "Fixed Dec", 8, 3 )}
			),
			Dispatch( {},"Variability Chart",FrameBox,{Frame Size( 1400, 800 )}), // Format A4 (Hauteur, Largeur) 
			Dispatch( {}, "CV", NumberColBox, {Visibility( "Collapse" )} ),
			Dispatch( {}, "Std Err Mean", NumberColBox, {Visibility( "Collapse" )} ),
			Dispatch( {}, "Lower 95%", NumberColBox, {Visibility( "Collapse" )} ),
			Dispatch( {}, "Upper 95%", NumberColBox, {Visibility( "Collapse" )} ),
			Dispatch( {}, "Range", NumberColBox, {Visibility( "Collapse" )} ),
			Dispatch( {}, "Median", NumberColBox, {Visibility( "Collapse" )} ),
			Dispatch( {}, "Observations", NumberColBox, {Visibility( "Collapse" )} ),
			Dispatch( {}, "2", ScaleBox, {Label Row( Set Font Size( 16 ) )} )
		)
	);

 

 

jthi
Super User

Re: Customizing Box Plot in varibility chart to Display Sigma-Based Intervals

I would consider having box plot with standard deviations confusing as box plots utilize median and quantiles.  

Here is very hard-coded idea to demonstrate single rectangle with a line (no whiskers but they could be added with Line())

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Variability Data/2 Factors Crossed.jmp");
obj = dt << Variability Chart(
	Y(:Measurement),
	X(:Operator, :part#),
	Model("Crossed")
);

fb = Report(obj)[FrameBox(1)];

ms = fb << Find Seg(MarkerSeg(1));

xs = ms << Get X Values;
ys = ms << Get Y Values;

v = ys[1::3];

s = Std Dev(v);
m = Mean(v);

fb << Add Graphics Script(
	Pen Size(3);
	Pen Color("Green");
	Rect(0.35, 3*s + m, 0.75, -3*s+m);
	Pen Color("Blue");
	Line({0.35, m}, {0.75, m})
);

jthi_0-1761673757132.png

I don't know how much data you have, but you could consider overlaying distribution instead of using the rectangles

jthi_1-1761673938763.png

or violin plots

jthi_2-1761674004365.png

-Jarmo
Harck
Level I

Re: Customizing Box Plot in varibility chart to Display Sigma-Based Intervals

Thank you very much, Jarmo. I will try your solutions. It would be much more convenient if a function were directly integrated into the software.

jthi
Super User

Re: Customizing Box Plot in varibility chart to Display Sigma-Based Intervals

For that JMP Community does have a JMP Wish List where you can post ideas which you hope to be implemented to JMP in some future version.

-Jarmo
Harck
Level I

Re: Customizing Box Plot in varibility chart to Display Sigma-Based Intervals

I tried to implement your solution, but the boxplot does not stay in place. When using a loop, it shifts on the graph. How can I display all the boxplots simultaneously? Below is the For loop I created.

		// To count the number of catagories in a specific column
	Summarize (T=by(dt:Temperature));
	Summarize (C=by(dt:Corner));
	Ntemp=  N Items(T);
	NCorner=  N Items(C);
	
For( v = 0, v < Ntemp*NCorner , v++, 
	fb << Add Graphics Script(
		Pen Size(2);
		Pen Color("Red");
		Rect(0.3+v, 3*s + m, 0.7+v, -3*s+m);
		Line({0.3+v, m}, {0.7+v, m});
		// Positive
		V line(	((1+2*v)/2),	3*s + m, 	4*s + m );
		Line({	0.3+v, 			4*s + m}, {	0.7+v, 4*s + m});
		V line(	((1+2*v)/2),	4*s + m, 	6*s + m );
		Line({	0.3+v, 			6*s + m}, {	0.7+v, 6*s + m});
		// negative
		V line(	((1+2*v)/2),	-3*s + m, 	-4*s + m );
		Line(	{0.3+v, 		-4*s + m}, {0.7+v, -4*s + m});
		V line(	((1+2*v)/2),	-4*s + m, 	-6*s + m );
		Line({	0.3+v, 			-6*s + m}, {0.7+v, -6*s + m});
	);
	wait(0);
);
jthi
Super User

Re: Customizing Box Plot in varibility chart to Display Sigma-Based Intervals

You have to do the looping inside the Graphic Script (and possibly evaluate some variables inside it).

-Jarmo
jthi
Super User

Re: Customizing Box Plot in varibility chart to Display Sigma-Based Intervals

One example (this is still missing quite a few things such as scaling Y-axis and "whiskers" and it isn't as dynamic as it could be)

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Variability Data/2 Factors Crossed.jmp");
obj = dt << Variability Chart(
	Y(:Measurement),
	X(:Operator, :part#),
	Model("Crossed")
);

dt_groups = dt << Summary(
	Group(:Operator, :part#),
	Freq("None"),
	Weight("None"),
	output table name(""),
	Private
);
group_sizes = dt_groups[0, "N Rows"];
Close(dt_groups, no save);

group_size = group_sizes[1]; // lazy assumption that all groups have same size

fb = Report(obj)[FrameBox(1)];
ms = fb << Find Seg(MarkerSeg(1));
xs = ms << Get X Values;
ys = ms << Get Y Values;


yvals = Shape(ys, N Items(group_sizes), group_size);

xv = xs[1::N Items(xs)::group_size];
stddevs = V Std(yvals`);
means = V Mean(yvals`);

Eval(EvalExpr(
	fb << Add Graphics Script(
		Pen Size(3);
		s = Expr(stddevs);
		m = Expr(means);
		x = Expr(xv);
		For(i = 1, i <= N Items(s), i++,
			Pen Color("Green");
			Rect(x[i]-0.2, 3*s[i]+m[i], x[i]+0.2, -3*s[i]+m[i]);
			Pen Color("Blue");
			Line({x[i]-0.2, m[i]}, {x[i]+0.2, m[i]});
		);
	);	
));

jthi_0-1762523875326.png

 

-Jarmo

Recommended Articles