I have a chart that evolves over time. At each time point I compute a point estimate and for each point estimate I compute a lower and upper confidence interval value. This gives a range at each time point but it also gets narrower over time as I have more data as time evolves.
An example of some data and the chart I created in graph builder are attached.
Is there a way of coding to shade in the region that is covered by the interval estimate?
I include a PNG file to hopefully make clear what I mean. (The yellow would extend from beginning to end of the time period.)
If anybody can help would be great.
Thanks!
You can add any kind of graphics to your Graph Builder output by adding an
Add Graphics Script
item to your platform. See the script below:
dt=current data table();
Graph Builder(
Size( 531, 454 ),
Show Control Panel( 0 ),
Variables(
X( :Index ),
Y( :Point estimate ),
Y( :Lower, Position( 1 ) ),
Y( :Upper, Position( 1 ) )
),
Elements(
Points( X, Y( 1 ), Y( 2 ), Y( 3 ), Legend( 3 ) ),
Line( X, Y( 1 ), Y( 2 ), Y( 3 ), Legend( 5 ) )
),
SendToReport(
Dispatch(
{},
"400",
ScaleBox,
{Legend Model(
3,
Base( 0, 0, 0, Item ID( "Point estimate", 1 ) ),
Base( 1, 0, 0, Item ID( "Lower", 1 ) ),
Base( 2, 0, 0, Item ID( "Upper", 1 ) ),
Properties( 0, {Line Color( 0 )}, Item ID( "Point estimate", 1 ) ),
Properties( 1, {Line Color( 0 )}, Item ID( "Lower", 1 ) ),
Properties( 2, {Line Color( 0 )}, Item ID( "Upper", 1 ) )
), Legend Model(
5,
Properties( 0, {Line Color( 0 )}, Item ID( "Point estimate", 1 ) ),
Properties( 1, {Line Color( 0 )}, Item ID( "Lower", 1 ) ),
Properties( 2, {Line Color( 0 )}, Item ID( "Upper", 1 ) )
)}
),
Dispatch(
{},
"Graph Builder",
FrameBox,
{Add Graphics Script(
2,
Description( "Script" ),
dt = Current Data Table();
yMatrix = dt:upper << get values |/
Matrix( Reverse( As List( dt:lower << get values ) ) );
xMatrix = dt:index << get values |/
Matrix( Reverse( As List( dt:index << get values ) ) );
Fill Color( "yellow" );
Polygon( xMatrix, yMatrix );
), Grid Line Order( 1 ), Reference Line Order( 3 )}
)
)
);
You can add any kind of graphics to your Graph Builder output by adding an
Add Graphics Script
item to your platform. See the script below:
dt=current data table();
Graph Builder(
Size( 531, 454 ),
Show Control Panel( 0 ),
Variables(
X( :Index ),
Y( :Point estimate ),
Y( :Lower, Position( 1 ) ),
Y( :Upper, Position( 1 ) )
),
Elements(
Points( X, Y( 1 ), Y( 2 ), Y( 3 ), Legend( 3 ) ),
Line( X, Y( 1 ), Y( 2 ), Y( 3 ), Legend( 5 ) )
),
SendToReport(
Dispatch(
{},
"400",
ScaleBox,
{Legend Model(
3,
Base( 0, 0, 0, Item ID( "Point estimate", 1 ) ),
Base( 1, 0, 0, Item ID( "Lower", 1 ) ),
Base( 2, 0, 0, Item ID( "Upper", 1 ) ),
Properties( 0, {Line Color( 0 )}, Item ID( "Point estimate", 1 ) ),
Properties( 1, {Line Color( 0 )}, Item ID( "Lower", 1 ) ),
Properties( 2, {Line Color( 0 )}, Item ID( "Upper", 1 ) )
), Legend Model(
5,
Properties( 0, {Line Color( 0 )}, Item ID( "Point estimate", 1 ) ),
Properties( 1, {Line Color( 0 )}, Item ID( "Lower", 1 ) ),
Properties( 2, {Line Color( 0 )}, Item ID( "Upper", 1 ) )
)}
),
Dispatch(
{},
"Graph Builder",
FrameBox,
{Add Graphics Script(
2,
Description( "Script" ),
dt = Current Data Table();
yMatrix = dt:upper << get values |/
Matrix( Reverse( As List( dt:lower << get values ) ) );
xMatrix = dt:index << get values |/
Matrix( Reverse( As List( dt:index << get values ) ) );
Fill Color( "yellow" );
Polygon( xMatrix, yMatrix );
), Grid Line Order( 1 ), Reference Line Order( 3 )}
)
)
);
Thanks, Jim!
Much better than my solution.........one learns something new in JMP every day
@txnelson: Different solutions for different circumstances... :D
... and I'm always in favor of promoting Graphics Scripts and the use of the Customize menu.
M
Coming in later to this - this is a nice solution and opens up some things I didn't know about JMP. One follow up question.
How would you adjust the area so that it only covered a portion of the graph? For the example dataset provide, say I only wanted to have the yellow area for the index values >20 rather than for all the values. Didn't see how you would do that here.
You can do that using my solution from above, and just restricting the polygons to the values above 20.
Or, even though I have not worked throught the following, I assume that a secondary set of values could be added to the Graph Builder chart, that would only have duplicated values above 20, and that an overlay could then let you make that one an area display.
Hi all,
This caught my eye just today even though it is 2 weeks old. I didn't see any scripts attached for an Area/Range element, so I am adding one. This is a slight modification combining the range plot with transformed columns. Note the element order allows the shading to be in the background.
Fun discussion!
dt = current data table();
gb = dt << Graph Builder(
Size( 531, 454 ),
Show Control Panel( 0 ),
Variables(
X( :Index ),
Y( :Point estimate ),
Y( :Lower, Position( 1 ) ),
Y( :Upper, Position( 1 ) ),
Y(
Transform Column(
"Transform[Lower]",
Formula( If( :Index >= 20, :Lower ) )
),
Position( 1 )
),
Y(
Transform Column(
"Transform[Upper]",
Formula( If( :Index >= 20, :Upper ) )
),
Position( 1 )
)
),
Elements(
Area( X, Y( 4 ), Y( 5 ), Legend( 1 ), Area Style( "Range" ) ),
Points( X, Y( 1 ), Y( 2 ), Y( 3 ), Legend( 4 ) ),
Line( X, Y( 1 ), Y( 2 ), Y( 3 ), Legend( 6 ) )
),
SendToReport(
Dispatch(
{},
"400",
ScaleBox,
{Legend Model(
1,
Level Name(
0,
"Recent Range",
Item ID( "Transform[Lower]..Transform[Upper]", 1 )
),
Properties(
0,
{Line Color( 9 ), Fill Color( 9 ), Transparency( 0.5 )},
Item ID( "Transform[Lower]..Transform[Upper]", 1 )
),
Properties(
-1,
{Line Color( 9 ), Fill Color( 9 ), Transparency( 0.5 )},
Item ID( "Recent Range", 1 )
)
), Legend Model(
6,
Properties( 2, {Line Color( 19 )}, Item ID( "Upper", 1 ) )
)}
)
)
);