cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar

Creating a Script to Perform a Common Action

Started ‎11-08-2022 by
Modified ‎11-08-2022 by
View Fullscreen Exit Fullscreen

So in this demonstration, I'm going to illustrate the agreement between the interactive actions and the elements in the corresponding script. And I'll do that by creating a scatterplot with two continuous variables and then fit a trend line to the data. And I'm going to note the steps that are involved in the process. So I have JMP open. And I've opened the course journal, which is called Intro to JSL. And in the first section, called Preliminary to Course, I want to click the script called Initial Setup. And any time you open this journal in a new session of JMP, you'll want to run this initial setup script. So I'll click that. And then when I get the alert that the initial setup is complete, I'll click OK. And then I'll click Next to advance into the next section of the course journal. So we have a script here called Big Class Data. And this is going to create the same data table that's installed as one of our sample files. But because the journal uses a script to create it, we don't have to worry about pointing to any particular file location. So I'll click that. And then I'll go to the Analyze menu and select Fit Y by X. And I want to put weight in the Y role. And just kind of notice that role is called Y. And then height in the X role-- and again, noticing that that role is called X-- And that when I have these two continuous variables in the X and Y roles, we see the word Bivariate appear here. I'll click OK. And this produces the scatterplot. And again, I want to fit that regression line. So I'll go to the red triangle next to Bivariate Fit and select Fit Line. So now I'd like to see the script that JMP will write that would recreate this output. So I'll go to that red triangle next to Bivariate Fit again, and under Save Script, I'll select To Script Window. Now I've increased the font size of my Script Editor through the preferences that you can find in the File menu. And so if I right click in this Script Editor window and select Reformat Script, JMP is going to reformat that by nesting the options that I selected. If you are following along, or repeat the same procedure, and you can see all of that script in the one line in your Script Editor window, you can simply resize the window to make it smaller and then try reformatting again. It won't do it if you can see all of the code. Now in your copy of JMP, you may not see line numbers here in the Script Editor window. And if you'd like to see those, and it is helpful for this course, you can go to the File menu and select Preferences. And in the Preferences in the Script Editor group, check this option to show the line numbers in Script Editor windows. By default, that is not checked. So I'm going to click OK to dismiss the Preferences window. And let's take a look at the script that JMP wrote. So first, we see that word Bivariate here, and that was the platform that we launched when we had the two continuous variables. We see the Y and X roles, as we saw in the dialog, with the column's weight and height. Now one thing is this colon preceding the name of each column. The colon is a scoping operator. And that just tells JMP that the name that follows will be referring to a data table column. In this case, if I don't have that colon there, JMP is still going to look for a data table column, because this is an analysis role in the Bivariate platform. But it's a good practice to include that preceding column names. Remember that when we went to the red triangle menu, I selected Fit Line. And Fit Line, by default, is going to produce a red line. JMP has added this optional element of the line color, where it specifies the RGB values for that line color. In fact, I could delete everything that I've selected, including the parentheses after Fit Line. And I would still get a red line. But the optional specification of the line color is available. Now, you don't have to memorize the RGB colors. I'm going to get rid of those three numbers with the curly brackets around them. And I could replace that with an index value for a specific color or the name of a color. And the different indexes and names are given in the documentation. I'm going to actually change the line color to blue. And so I'm going to type a double quotes. And you notice that JMP automatically close the double quotes for me. And I'm going to type the word Blue with a capital letter. Now to run a script, there are several options. You can go to the Edit menu and select Run Script. And you can see here there's also a keyboard shortcut, Ctrl+R. You can right click in the Script Editor window, and select Run script. And then there's also a toolbar button with a little green Play button that you can use. I tend to use keyboard shortcuts. But since I'm ending your tour of how to run the scripts up here in the toolbar, I'll go ahead and just click that button. And so here we have the same analysis, but with my mild modification of changing that line color. And although this example is simple, it really illustrates a very important concept in JSL, which is that I performed the actions interactively, let JMP write the script for me, and then made modifications as necessary. So that's something to keep in mind, that whenever we can let jump write the script for us, we want to be sure to do that.