cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
laurence
Level I

Adding error bars in JMP

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
pmroz
Super User

Adding error bars in JMP

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 )} )
    )
);

 

View solution in original post

9 REPLIES 9
ms
Super User (Alumni) ms
Super User (Alumni)

Adding error bars in JMP

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 )
);

 

pmroz
Super User

Adding error bars in JMP

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 )} )
    )
);

 

bholmes91011
Level I

Re: Adding error bars in JMP

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?

Re: Adding error bars in JMP

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

Thanks,

Phil

pmroz
Super User

Re: Adding error bars in JMP

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

Re: Adding error bars in JMP

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

Thanks.

paquinteroc
Level I

Re: Adding error bars in JMP

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?

Re: Adding error bars in JMP

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

whitelampe
Level II

Re: Adding error bars in JMP

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 :)