Testing Residuals for Normality

This is step 5 in the creation of the oneway advisor.  In the previous step code was produced for testing whether the data within each level of the grouping (X) variable were normally distributed.

In this step code will be developed to determine whether the residuals are normally distributed.

The code will have the same structure as prior step: a user-defined function will be implemented to perform the test and return a result as a p-value.  The main code will set the status icon based on the value of this p-value, and a tool-tip will be implemented to provide a description if the user hovers the mouse over the icon.

Testing for a Normal Distribution

First I want to develop a function that will test whether a set of data contained in a data table column is normally distributed.  To do this interatively in JMP I would perform the following steps:

  1. Analyze>Distribution
  2. Continuous Fit>Normal
  3. Fitted Normal>Goodness of Fit

This sequence generates the following JMP-generated script:

This code can be made more flexible by explicitly adding a table reference (dt) and a column variable (col):

Note also that the Distribution object is assigned to the variable dist – this is required in order to extract results from the report window.

Extracting Results from the Report Window

Sending the message Report to the distribution object (dist) generates a reference (rep) to the window containing the results.  This window is simply a composition of display boxes which can be referenced individually and manipulated by sending them messages (typically to interrogate their values e.g. “<<Get”).

In the code above the p-value has been retrieved from  number column box (cb) contained within a table box (tb) contained within an outline box (gof).

If you have been following the sequence of steps for the oneway advisor then you will recognise this code from the previous step.

Test  Normal

The above code snippets can be combined into  user-defined function Test Normal, that will take two arguments – a table reference and a column name, and return a single value, the p-value associated with the hypothesis that the data are normally distributed.

To make this function available for use by the oneway advisor, the code needs to be added to the file Analysis Components.jsl.

Accessing Residuals Data

We now have a mechanism for testing whether the residuals are normally distributed – but we have no residuals!

When we perform modelling activities in JMP  the residuals only become available to us if we choose to save them to the data table.  Using the JMP scripting language this activity can can be automated by using  the message Save Residuals.

Messages are “sent” using the operator “<<“.  But to send a message we first need an object: the code below creates a oneway object then sends the message:

Test Normal Oneway Residuals

Everything is now in place to create a user-defined function for testing whether the residuals associated with the oneway analysis are normally distributed:


  • Lines 9 and 10 – when the residuals are saved to the table they become the last column of the table., therefore the function NCols is used to determine the position of the residuals data.
  • Line 12 – uses the Test Normal function that was defined earlier
  • Line 13 – once the test has been performed the data can be deleted to restore the table to its original state

This function definition needs to be added to the file Analysis Components.jsl.

Invoking the Function

The code step4.jsl already has a block of code responsible for checking assumptions.  This block can now be extended to include the test for normality of residuals:

Save the revisions as step5.jsl.

Share the joy:

One thought on “Testing Residuals for Normality”

Leave a Reply