cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar

Scripting Analyses

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

In this demonstration, we'll see how to script the analyses performed by some of the commonly-used platforms in JMP. In the journal in section I'll click on Concrete Strength and Humidity Data, and this is the data set I'm going to use for all of the examples in this demonstration. So we've got the type of concrete mix, the resulting concrete strength, and the ambient humidity when the concrete dried. I'm going to move this over to the side, as we won't really be looking at the table throughout this demonstration. And back in the course journal, I'm going to click on Distribution Analysis Script. So in this pre-written script, we're sending distribution as a message to the data table Concrete and storing that result in a variable, dist-- storing that object reference. And again, this will be the analysis layer object reference. I'm putting all three columns-- Concrete Type, Humidity, and Strength-- in that Y analysis role, and then I'm also requesting the same options during launch for all three of the columns, but as we'll see when we have the report window open, not all of the columns can respond to all of these options. So I'm going to run lines through And so a couple of things from the arguments to distribution when we launch the platform-- Stack is an option in the red triangle menu-- at the top, next Distributions-- and it just changes the histograms to horizontal, changes the location of the report tables that we typically see below the histograms, and whether they're lined up-- the histograms themselves are lined up side-by-side or vertically. And so Stack is that option in the red triangle menu-- and you can see that our script used the Boolean to turn that off. So your script might choose to do that, because that's actually a very common option that users will change in their preferences so they always have stacked distributions. And if it's important to the result of your script that these be organized in the default manner, you might want to turn the stack off. Additionally, we specify that the histograms be vertical. That is found in the individual red triangle menus for each red triangle under Histogram Options. So you can see that's checked here. And again, that's a default, so the script is just trying to assure that the presentation will look the way the default settings are in JMP, regardless of user preferences. Now, the next line in the script-- line we have the Quantiles turned off. Well, Quantiles only apply to continuous variables. If you look in the red triangle menu next to Concrete Type in any of these submenus, you're not going to find the word "Quantiles." But if I look at the red triangle next to either Humidity or Strength, under Display Options, the Quantiles would actually normally be on by default, but you can see here that it's not checked in this menu, because we used that Boolean Similarly, the Outlier Box Plot is typically turned on for continuous variables. And we turn that off with a Boolean so we don't have the outlier box plot. And then lastly, we requested the Normal Quantile Plot with the Boolean in parentheses, and that is something that would not normally be turned on, but we've requested for these variables. And again, that was part of the platform launch, so the variables that were able to respond to those commands did so. Now, once we've launched the platform and stored the object reference in a variable, with distribution, I can communicate with all of the variables at once, or I can send messages to individual columns or variables. And I do that with subscripts. So line just shows us sending Fit Distribution (Normal)-- so fitting a normal distribution-- to all three of the columns. And of course, Concrete Type being nominal-- can't respond to that, but the Humidity and Strength will respond. So I'll run line And you can see that we have that fitted normal distribution overlaid on both of the continuous distributions, and we also get the fitted normal outline items. This, again, is a command from the red triangle menu. Fit Distribution is an older name for the command. It's called Continuous Fit in newer versions of JMP, but they both still work. And one thing I wanted to note-- let me go back to the log. When I ran the script to launch the distribution, what showed up was the name of the platform. And that is that indication that I have an analysis layer object reference. And in the script, if I hover over dist, that's what I'm going to see. Whereas when I sent the command from the red triangle menu after the fact, I just got that "script-able" result. Now, lines and are going to do a one-sample test of the mean. And in the red triangle menu, the command is simply Test Mean. But it doesn't make sense that, for Humidity-- which has my sample mean as and the Strength for my sample mean is about it wouldn't really make sense for me to test the same hypothetical mean for both of those. So let me actually show you what it looks like interactively. If I go to either red triangle next to the continuous variables and select Test Mean, I enter a value for the hypothesized mean. So I'm going to cancel out of that and return to the script editor window. So line I'm testing that the mean is equal to and I'm sending that to the third column in the distribution window. So I subscript dist with the number So I'll run line And if I navigate over to the Report window, there is the one-sample t-test on the mean. I'm going to do the same thing, then, for Humidity with a different hypothetical mean of and the way I subscript is going to be a little different. I'm going to use the name of the column as a character string-- as my subscript-- rather than its position in the report. So I'll run line and there I get the t-test for Humidity. So that's just a few examples for the distribution platform and scripting the analysis layer using commands from the red triangle menu. Let's go on to the One-Way platform. And I'm going to go ahead and close the distribution script, as well as the distribution report, but I'm still going to use the Concrete data table. So in the journal, I'm going to click one-way ANOVA script. And this was kind of wide to start. We've got the whole launch on one line. So we're sending the message to the data table Concrete. The message is the One-Way Platform launch with Strength in the Y role, Concrete Type in the X role, and we request those mean diamonds be turned on with that Boolean argument. And we store the analysis layer object reference in ow. So I'll run line And so we get our output window and, of course, the name of the platform. And this is what'll be stored in ow if you hover over it. Those green mean diamonds-- if I go to the red triangle next to One-Way Analysis, you can find that under Display Options, Mean Diamonds. And by default, these would not be turned on if I hadn't already done the analysis of variance. But my script can turn them on. Now, I don't need this script window to be so wide now. Let's go on to another couple examples here. So in the red triangle menu here, we have an option to set the alpha level. And there are three standard values. And then there's an Other that you can optionally choose. So in this example, I'm sending the message to ow, Set Alpha Level. And I'm going to set it at And just notice that the height of these green mean diamonds-- that's the confidence interval on the mean or, in other words, the minus alpha confidence interval on the mean. So the default alpha is So if I set the alpha level to these will be confidence interval. So they're going to get taller. So I'll run line And so we see the height of those mean diamonds change. Another report that we can request for the One-Way Platform, if I go to the red triangle, is the Quantiles report. And so I'm turning that on in line And notice that the commands in this menu that don't have sub-menus-- they can take a Boolean argument in parentheses or, as you see on line for the ANOVA, which is synonymous with means, they don't have to take any argument at all, whereas the menu items that have sub-menus will take those sub-menu items as their arguments. And I'll talk in a moment about why we might want to use that Boolean argument, even though it's not required. But for now, I'll run line So that gives me the Quantiles report table as well as putting box plots on the plot. And now, remember, ANOVA and means are synonyms. So this is just another command from the red triangle menu. But again, I haven't put the parentheses in the Boolean argument. So what happens when I run line I'll run that. And I get the analysis of variance. Again, I should be pointing out that in the log, we're seeing that platform name every time we interact with it. Now, what happens if I run line again? I get a message in the log-- a message with an empty Boolean argument enabled an option that's already enabled. That option remains enabled. And it just mentions that in previous versions of JMP, you actually would have toggled back and forth by running that line over and over again without having to supply a Boolean argument. So if you ever are looking at scripts that were written in older versions, you might see that. We're going to recommend as a best practice, though, that you always use that Boolean argument so it's clear in your script that I am turning this option on rather than turning it off. And then when I want to remove it, if I want to remove it, I would run a line that had the Boolean In fact, let's do that to turn the Quantiles report off. So in line I'm going to replace the with a and just run that one line. And so now the Quantiles option has been removed. Lastly, we had seen in a previous demonstration that you can cascade messages to an object. But we can also send a list of messages to an object. So I'm going to get a new line in the script editor window. And the variable ow that's storing my analysis layer object reference will receive the message. And it's going to be a list, Unequal Variances. And I'll use that Boolean argument to turn that on. And let me just come over to the red triangle menu. So there's Unequal Variances. That gives us the tests of heteroscedasticity. And I'll put a comma after that, closing parenthesis on the Boolean argument for Unequal Variances. And I'm going to return the alpha level to that default of So I'll type set alpha level and then, in parentheses, And I need to close that parentheses because I moved my cursor out of this line of code before I was done typing. And then I'll arrow over the list-- let me move this so I can see the whole line-- and put a semicolon. And so I can run just this one line, again, using the Enter key from the numeric keypad. And at the bottom of the window now is the Unequal Variance test. And at the top, you can see that we have restored the alpha level to So these our confidence intervals now. And the little blue lines are just from the unequal variance test. So just a few examples of scripting with the red triangle commands in the One-Way Platform-- let's close this report window and close this script without saving changes. And in the journal, I'm going to click Bivariate script. And again, we're working with the data table Concrete. So the variable storing this analysis layer object references is biv. And I sent Bivariate to that data table with Strength in the Y role, Humidity in the X role. And I request Fit line, which comes from that red triangle menu as part of the platform launch. So I'll run lines through And again, we see the platform name in the log. And if I hover over biv, that's what I'll see. So we plotted Strength against Humidity, fit the regression line. And then some of the other messages-- so if I go to that red triangle, again, there's Fit Line. I can send any of these other commands after the fact. I actually could have sent Fit Line after the launch. But I'm going to use Fit Polynomial. And you see that there's that sub-menu. So we'll have to use these arguments. And in line I send that message to biv, Fit Polynomial so the quadratic or second-order polynomial. I'll run that line. So that gives me a second fit. And when I scroll back up, you can see that that second fit is superimposed on the graph. And I have two red triangle menus here, one for the Linear Fit and one for the Polynomial Fit. And they have their own commands that are different from the commands at the bivariate fit level up at the top of the window. So for example, if I wanted to have a shaded fit of the confidence bands on the linear fits-- the command is Confid Shaded Fit-- I actually have to do something a little special. I have to communicate first with the linear fit. And then the result of the linear fit receiving that message is then sent as a message to the bivariate fit. And the way that's scripted here-- we just refer to the first one as-- they're both referred to as Curve. We use the subscript It receives the message Confid Shaded fit. That is collected in parentheses. And that's the message that's received by biv. If I didn't have these parentheses, biv would try to understand Curve, which, of course, you will not find Curve anywhere in any of the sub-menus or the main menu here. And Confid Shaded Fit you're not going to find here. That's associated with this Curve, which is labeled Linear Fit in the report. So if I run all of line I've got that-- shaded confidence bands on my regression line. Similarly, in either one of these red triangle menus, but I'll click the one next to Polynomial Fit, we can change the line color. The default is red for the first fit, green for the second, and so on. So suppose I want to change that to blue. Again, I can send that to the second curve, wrap that in the parentheses, and that's the message that gets passed on to Bivariate. So I'll run line And you can see that that line color has changed. Now, this is something, too. If you wanted to know how to script this and you didn't need to send it as a message to the platform after it's been launched-- you wanted to include it as part of the launch-- you could do this interactively and then have JMP save that script to the script window and work with it that way. If you were to do that, then the Confid Shaded Fit would be an argument to Fit Line. And you would also fit the polynomial as the argument to launch. And the line color would be an argument to that. The last thing we want to look at here is the Bivariate platform, but with a variable in the By role so that we'll get separate bivariate objects for each level of that By variable. So I'll close the script window. And I'll close the Bivariate report. And in the course journal, I'll click Grouped Bivariate Script. So as in the previous script, I'm launching the Bivariate platform by sending the message to the Concrete data table storing that result in the variable biv with Strength in the Y role and X in the Humidity role. But now, I'm additionally putting Concrete type in that By analysis role. So let's see what that looks like when I run lines through So we actually have six bivariate objects in this report window. And what I see in the log is that a list with six elements has been assigned. Well, what does that list look like? I'm going to come back to the script editor window and hover over biv. And it's a list of six bivariate objects. So I can send a message to biv. And all of the objects will respond, as in line when I send Fit Line. What shows up in the log is the list of all of the objects that responded. And if we look in the window-- I'm going to actually collapse all these linear fits together by holding down the Ctrl key and clicking on the outline disclosure button next to the first linear fit. Because I'm holding down the Ctrl key, that will broadcast to all of those reports in the window, just so I can scroll more easily. And you can see that we've got the bivariate fit for Consolidated Reinforced, Consolidated Standard, EZMix Reinforced, EZMix Standard, and so on. Now, what if I only want to target some of the objects, not all of the bivariate objects? Well, I use subscripts. And I could use an individual subscript to target just one. But let's take a look at two examples where we want to have more than one object respond. So in line for the subscript, we provide a list of the index values of the objects that we want to respond. I want the first and third bivariate objects to fit that quadratic model, the polynomial of degree So I run line And again, I'll use the Ctrl key to collapse the polynomial fit outline item to make scrolling a little easier. So the first object, the first bivariate object, has a polynomial fit. The second one doesn't. The third one does. And of course, the fourth, fifth, and sixth do not. And then in the last example, I'm using that Index function, again, using its operator, which is that infix operator of two double colons. So this will count from the first number to the second number in increments of So this will go to and Fit Spline is an option in the red triangle menu under Flexible. And you can see all the various arguments that you can supply to that. So we're fighting a fairly flexible spline to bivariate and So I'll run line And again, notice in the log-- I forgot to point this out. But when I just send a message to two of the objects, I get a list with two objects. And just now when I send a message to three of the objects, I get a list of the three objects. And if we take a look, we can see that the first and second bivariate fits did not get a spline. The third one did. The fourth one did. The fifth one did. And the sixth one did not. So we can use a By role and have separate analyses, separate objects, for each level of that By variable. And then we can communicate with all of them together or individual ones. So these were just a few examples of launching and then interacting with the analysis layer in some of the commonly used JMP platforms.