turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Discussions
- :
- Adding error bars in JMP

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Feb 9, 2012 8:04 AM
(16906 views)

Hi guys, I have a simple problem which I have been unable to solve. I have a dataset which I would like to plot in a Fit Y by X style scatterplot against another dataset. For each datapoint I know the standard deviation and I would like to add these standard deviations as error bars to the plot, is there anyway to do this?

It seems like JMP only does this normally if it has calculated the standard deviation itself, I don't want this as I already know the standard deviation for each and every datapoint.

Thanks for any help

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

It's possible to use Graph Builder to show error bars without stacking the data. I.e. you have 3 separate columns: center point, upper limit and lower limit. Using the data above, you drag the X variable (age) to the X axis. Then highlight upper and lower and drag them to the Y axis. Right click in the center of the graph, click Points > Change to > Bar. Then right click in the graph, click Bar > Bar Style > Interval. Now drag the column Mean(height) just to the right of the Y axis. Next add connecting lines and remove the connecting lines for upper and lower.

Here's a JSL script that does it, along with some formatting:

```
// Make an example table
dt = Open( "$ENGLISH_SAMPLE_DATA/Big Class.jmp" );
dtsum = dt << Summary( Group( :age ), Mean( :height ), Std Err( :height ) );
// Add columns with Mean ± SE
dtsum << New Column( "lower", numeric,
values(
(:Name( "Mean(height)" ) << get as matrix) –
(:Name( "Std Err(height)" ) << get as matrix)
)
);
dtsum << New Column( "upper",
numeric,
values(
(:Name( "Mean(height)" ) << get as matrix) +
(:Name( "Std Err(height)" ) << get as matrix)
)
);
Graph Builder(
Show Control Panel( 0 ),
Variables(
X( :age ),
Y( :lower ),
Y( :upper, Position( 1 ) ),
Y( :Name( "Mean(height)" ), Position( 1 ) )
),
Elements(
Bar(
X,
Y( 1 ),
Y( 2 ),
Y( 3 ),
Legend( 2 ),
Bar Style( "Interval" ),
Summary Statistic( "Mean" )
),
Line( X, Y( 3 ), Legend( 4 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
SendToReport(
Dispatch(
{},
"400",
ScaleBox,
{Legend Model(
2,
Properties( 0, {Line Color( 0 )} ),
Properties( 1, {Line Color( 0 ), Marker( "FilledCircle" )} )
)}
),
Dispatch( {}, "Graph Builder", FrameBox, {Marker Size( 3 )} )
)
);
```

9 REPLIES

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

It is possible but I have not found a straightforward way to do it. First you need to calculate mean-SE and mean+SE. Then you'll get the best result if you first stack the columns. Try the script below. It illustrates some ways to do it in JMP 9.

```
// Make an example table
dt = Open( "$ENGLISH_SAMPLE_DATA/Big Class.jmp" );
dtsum = dt << Summary( Group( :age ), Mean( :height ), Std Err( :height ) );
// Add columns with Mean ± SE
dtsum << New Column( "lower",
numeric,
values(
(:Name( "Mean(height)" ) << get as matrix) - (:Name( "Std Err(height)" ) << get as matrix)
)
);
dtsum << New Column( "upper",
numeric,
values(
(:Name( "Mean(height)" ) << get as matrix) + (:Name( "Std Err(height)" ) << getasmatrix)
)
);
// Stack columns
dtstacked = dtsum << Stack(
columns( :Name( "Mean(height)" ), :lower, :upper ),
Source Label Column( "Label" ),
Stacked Data Column( "Data" ),
Name( "Non-stacked columns" )(Keep( :age ))
);
// Three ways to make a graph with mean and error bars based known SE
// 1. Overlay plot with range plot. Ugly graph and markers are visible for ± SE
dtsum << Overlay Plot( X( :age ), Y( :Name( "Mean(height)" ), :lower, :upper ), Range Plot( 1 ) );
// 2. Graph builder. Nicer graph but table must be stacked first.
dtstacked << Graph Builder(
Show Control Panel( 0 ),
Variables( X( :age ), Y( :Data ) ),
Elements(
Points(
X,
Y,
Legend( 0 ),
Jitter( 0 ),
Summary Statistic( "Mean" ),
Error Bars( "Range" ),
)
)
);
// 3. Chart platform. Similar to graph in 2.
dtstacked << Chart(
X( :age ),
Y( Mean( :Data ) ),
Add Error Bars to Mean( Range ),
Overlay Axis << {{Min( 52.5 ), Max( 72.5 ), Inc( 5 ), Minor Ticks( 1 )}},
Y[1] << Point Chart( 1 )
);
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

It's possible to use Graph Builder to show error bars without stacking the data. I.e. you have 3 separate columns: center point, upper limit and lower limit. Using the data above, you drag the X variable (age) to the X axis. Then highlight upper and lower and drag them to the Y axis. Right click in the center of the graph, click Points > Change to > Bar. Then right click in the graph, click Bar > Bar Style > Interval. Now drag the column Mean(height) just to the right of the Y axis. Next add connecting lines and remove the connecting lines for upper and lower.

Here's a JSL script that does it, along with some formatting:

```
// Make an example table
dt = Open( "$ENGLISH_SAMPLE_DATA/Big Class.jmp" );
dtsum = dt << Summary( Group( :age ), Mean( :height ), Std Err( :height ) );
// Add columns with Mean ± SE
dtsum << New Column( "lower", numeric,
values(
(:Name( "Mean(height)" ) << get as matrix) –
(:Name( "Std Err(height)" ) << get as matrix)
)
);
dtsum << New Column( "upper",
numeric,
values(
(:Name( "Mean(height)" ) << get as matrix) +
(:Name( "Std Err(height)" ) << get as matrix)
)
);
Graph Builder(
Show Control Panel( 0 ),
Variables(
X( :age ),
Y( :lower ),
Y( :upper, Position( 1 ) ),
Y( :Name( "Mean(height)" ), Position( 1 ) )
),
Elements(
Bar(
X,
Y( 1 ),
Y( 2 ),
Y( 3 ),
Legend( 2 ),
Bar Style( "Interval" ),
Summary Statistic( "Mean" )
),
Line( X, Y( 3 ), Legend( 4 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
SendToReport(
Dispatch(
{},
"400",
ScaleBox,
{Legend Model(
2,
Properties( 0, {Line Color( 0 )} ),
Properties( 1, {Line Color( 0 ), Marker( "FilledCircle" )} )
)}
),
Dispatch( {}, "Graph Builder", FrameBox, {Marker Size( 3 )} )
)
);
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

THis was very helpful for me, i am trying to write JSL script so that I can plot standard deviation error bars on a control chart as each datapoint on the control chart is the average of x individual points. Is there a way that the JSL script used for Graph Builder can be used in Run Chart, XBar, IR, UWMA, or PreSummarize Control Chart script?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

This is really useful but how do you remove the connecting lines for upper and lower (other than by scripting)?

Thanks,

Phil

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Right click on the graph and select **Line > Y > upper** (or whatever you called your upper bound column). Repeat for the lower bound.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Brilliant. I did not realise that is was that simple.

Thanks.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Thank you for the answer. Any of the three methods work nicely to include error bars in the y axis. Do you know how can I include both, x and y error bars in the same scatter plot?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

There is an add-in from Ian Cox that might be what you are looking for.

JMP Add-In that plots uncertainty in X and Y values

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

There is an easier option - even without the jitter-problem when you use an additional overlay variable. First create a column for lower and the upper value each (as descripted above). Then stack the data (central point, upper value, lower value). Open graph-builder and add the stacked data to the y-axis. Then choose summary statistic "mean" and Error bars "range". That's it. Even without the jitter problem! Good luck :)