Checking Distributions Within Group Levels

This is the fourth step in building the oneway advisor.

It’s time to start developing the code that will check the assumptions of the oneway analysis.  The first assumption is that data within each level of the grouping variable are normally distributed.

To be technically correct, this isn’t a true assumption of the analysis but it is a useful diagnostic, particularly if the second assumption (normally distributed residuals) in not valid. The assumption will be tested by using a function Test Normal Each Level.  This is a user-defined function that has not yet been written!

Creating and using the function is the theme of this step.

Using JMP to Walk-Through Code Logic

In order to write code to implement the function Test Normal Each Level we need to understand how the test would be performed interactively using JMP.

For test purposes I am going to use the sample data table Big Class.  The Y variable will be weight and the X variable will be sex.  To test the distributions of the data within each level of the X variable I can use the By role within the Distribution platform:

dist-by

This will produce separate distributions for the two levels of sex – ‘F’ and ‘M’.  For each of these levels the option Continuous Fit>Normal can be used to fit a normal distribution and then the option Goodness of Fit can be used to calculate the associated p-values:

dist-by-complete

JMP Generated Code

Associated with these steps is a JSL script which can be written as:

Extracting Report Output

The above script will generate the required  output – but what we need to do is to unpick the output and isolate the p-values.  The first step in doing this is to reference the report window, which I can illustrate with the following code:

This produces the following log-window output:

step4-log

Using the Word Function to Split Text

The variable reportWindow is a list of display boxes – this is because of the By-clause used to generate the distributions. The Word function can be used to extract the level from the title:

Referencing the Report’s Display Tree

For each level the p-value needs to be retrieved from the Goodness of Fit test.  The following notation references this portion of the report:

The p-value is the first item in the second column of a Table Box:

Constructing an Associative Array

The levels and p-values can be combined into a single data structure – an associative array:

Putting It All Together

The mechanics of the user-defined function Test Normal Each Level have now been established.  Here is the full implementation, which should be created in a new script file called Analysis Components.jsl:

Testing the Function

You can test the function by temporarily adding the following three lines and running the script:

The (JMP Log window) output should look like this:

test-test-levels-results

Including The External JSL File

Now that the user-defined function has been developed and tested it can now be incorporated into the main code.  First it needs to be “included”.  Modify the script step3.jsl and add an additional include statement as indicated below:

Invoking the Function

At the end of the file, after the new window has been created for the oneway advisor, add the code required to invoke the new function and process the results:

Referencing the Icon Buttons

Our user function generates a p-value for each level.  If the smallest of these is less than the alpha level of 0.05 then the icon for this test is set to FAIL, otherwise it is set to PASS.  This code assumes that the button containing the icon is called btnNormalLevels. The portion of code that contains the button definition needs to be revised to contain the button name:

Running the revised code should display a pass or fail icon for the first test, depending on the data being used:

check1
In future steps we will want to reference the other buttons so now is a good time to name all the buttons:

  • btnNormalLevels
  • btnNormalResids
  • btnEqualVariance
  • btnIndependentData

Creating Button Tooltips

Finally I want to button to convey information when the mouse “hovers” over the icon.  This is achieved by assigning a “tip” to the button:

This is how the tip will appear to the user:

tip1image

And Finally

This completes step 4!  Make sure you save the revised code as step4.jsl. Here is what the file should look like:

Continue to step 5.

One thought on “Checking Distributions Within Group Levels”

Leave a Reply

Your email address will not be published. Required fields are marked *