- Open a new script window. Start with Names Default to Here(1); at the top.
- Open the Big Class from the sample data directory. Copy the code from the enhanced log assigning a table reference to it.
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
- Launch the Fit Y by X platform with weight as Y and height as X. Select Fit Mean, Fit Line, and Fit Polynomial > 2, Quadratic from the hotspot. Directly below the graph, to the left of Linear Fit, use the hotspot to change the line color to the middle blue choice, 4th from the bottom and Line Style to the third option. Change the color of the polynomial fit line to the middle orange option and the second line style.
- Close the Bivariate Fit report. The code for the report window with all the changes appears in the Enhanced Log. From the hotspot at the top left, select Save Script > To Script Window.
- Open returns a reference to the opened data table. Add a variable reference.
tblRef = Open( "$SAMPLE_DATA/Big Class.jmp" );
- Replace the hard coded table reference with the variable reference created above. The Bivariate platform message returns a reference to the platform. Create a variable to capture it.
bivariatePlt = tblRef << Bivariate(…
- Add Ignore Platform Preference(1) as the first argument to Bivariate. This will override any user selected platform preferences.
- Add the following three lines below Bivariate. The messages are identical to their associated arguments in Bivariate and will be used to replace them. Delete the arguments from the Bivariate message otherwise the fits will appear twice each.
biv << Fit Mean({Line Color( {212, 73, 88} )});
biv << Fit Line({Line Color( "Blue" ), Line Style( "Dashed" )} );
biv << Fit Polynomial(2,{Line Color( "Orange" ), Line Style( "Dotted" )});
Using messages instead of arguments to control report output gives us a simple and compact way to implement options. We could, for example, check for certain conditions using an If statement and decide whether the option should be turned on based on the results. In most cases, arguments and messages will be identical as seen above. To double check, we can look up the Bivariate platform object in the Scripting Index.
Color and line style keywords can be specified with or without quotes and are not case sensitive. The Solid line style is default and does not need to be added.
- Replace the list of three numbers in the Fit Mean message with the word “Red”. Quotes are optional and case is ignored.
bivariatePlt << Fit Mean( {Line Color( Red )} );
We can specify line colors using one of 67 names, a three number list corresponding to red, green, and blue values, or a single value between 0 and 84. Names and numbers are given in the graph below.
Colors in the 2nd though 5th columns are prefixed with the name at the top of the column. For example, 73 is Light Yellow, 9 is Yellow and 25 is Medium Dark Yellow. The short column at the far right contains shades of gray, the names of which appear at their right. Of the 85 color numbers, 67 are unique. The grays and Black are duplicated. 65 of the 67 colors appear in the color pop-up palette.
The JMP color palette
The order of the colors from top to bottom are, starting in the second row, Red, Orange, Yellow, YellowGreen, Green, BlueGreen, Cyan, BlueCyan, Blue, Purple, Magenta, and Fuchsia. The shades go Dark, Medium Dark, (no prefix), Medium Light, and Light. The five grayscale colors in the top row are Black, Dark Gray, Gray, Light Gray, and White. Medium Dark Gray and Medium Light Gray do not appear in the palette. For even more choices, you can specify a three-value list giving the red, green, and blue values of the color. Values can be specified on a either a 0 to 255 or 0 to 1 scale. For example, periwinkle is {204,204,255} (according to Wikipedia).
The names for the Line Styles are Solid, Dotted, Dashed, DashDot, and DashDotDot.
- Create a reference to the report layer of the analysis.
bivariateRpt = bivariatePlt << Report;
Alternatively, the Report function could have been used.
bivariateRpt = Report(bivariatePlt);
In general, visual report components are part of the report layer whereas analytical components are part of the platform.
- We will use XPath to create a reference to every Parameter Estimates outline box to check the p-values.
paramEstOutBoxes = bivariateRpt << XPath("//OutlineBox[text() = 'Parameter Estimates']");
Since we have more than one Parameter Estimates outline, we want an easy and reliable way to reference all of them. Xpath is an open-source expression language developed by the World Wide Web Consortium standards organization.
- We will loop through each of the Parameter Estimates outlines and check the last value in the last column of the table. If it is below a prespecified value, we will remove the fit. Let’s specify the value as a variable at the top of the script just below Names Default to Here.
alpha = 0.05;
- Loop using For Each
For Each({paramEst,i},parEstOutBoxRefs,
nextPValues = paramEst[Number Col Box(4)] << Get;
If(nextPValues[N Items(nextPValues)]>alpha,
/*Code to Remove Fit*/
);
);
Get returns the entire column as a list.
- If we were doing this interactively, we would go to the hotspot associate with the fit and select Remove Fit. Let’s start by assuming it is part of the platform. If we tried to send the Remove Fit message directly to the platform reference, nothing would happen. We can use the Scripting Index to get more information.
- Type remove fit in the search box at the top. In the list box directly below all items with either remove or remove fit appear.
- Select the first Remove Fit and scroll through the list using the down arrow. In the list box on the left, the objects associated with the entry are highlighted. The seventh Remove Fit entry is associated with Bivariate.
The syntax at the upper right shows us how to use it.
bivariatePlt << (Curve[i+1] << Remove Fit);
We need to use i+1 to reference the curve because Fit Mean does not have a Parameter Estimates box. This should give use the code we need.