In many JMP platforms, you can specify columns as By variables. To do this in a script, include a By argument in the platform command, listing each column as an argument.
The following example uses the Big Class.jmp data table, which contains the names, ages, sex, heights, and weights for 40 students. Create a bivariate report of weight by height, using sex as a By variable, and adding a variety of fits.
1.
|
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
biv = dt << Bivariate( Y( weight ), X( height ), By( sex ));
The first line opens the Big Class.jmp sample data table. The second line creates a platform object called biv that runs a bivariate report of weight and height by sex.
3.
|
Click Run Script .
|
1.
|
Show( biv );
3.
|
In the log, rather than returning a single reference to a platform, Bivariate[], the platform object returns a list of references: biv = {Bivariate[], Bivariate[]}. The two references correspond to the two levels (F and M) of the By variable, sex.
biv << Fit Line;
5.
|
Highlight the line you just created and click Run Script .
|
biv[1] << Fit Polynomial( 3 );
7.
|
Highlight the line you just created and click Run Script .
|
8.
|
biv[2] << Fit Polynomial( 4 );
9.
|
Highlight the line you just created and click Run Script .
|
Figure 9.2 By Group Reports
If you specify more than one column in By argument, graphs appear for each subgroup of each By variable. In this example, By( sex, age ) would produce graphs for females age 12, females age 13, and so on, up to age 17. It would also produce graphs for males age 12 up to age 17.
The following example shows how to launch a platform with By groups and extract results (in this case, variances) from each group:
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
onew = dt << Oneway( x( :age ), y( :height ), by( :sex ), anova );
// onew is the JSL variable holding a list of platforms
r = onew << Report;
// r is a list of reports
nBy = N Items( r );
// nBy is the number of reports generated
vc = J( nBy, 1, 0 );
// vc is an array of as many rows as reports, one column, all set to zero
For( i = 1, i <= nBy, i++,
// for each report, do the following:
vc[i] = r[i]
// vc[i] is the variance of the ith report
[Outline Box( "Analysis of Variance" ),
// look for this outline and
Column Box( "Sum of Squares" )][2]
);
// this column and get the second value
Show( vc );
// debugging, look in log to see this value
Summarize( byValues = By( :sex ) );
// byValues becomes a list of the values in the sex column
New Table( "Variances" )
// makes a new table with two rows (M.F) and two columns
<< New Column( "Sex",
character,
width( 8 ),
values( byValues )
// creates a new column called Sex
) << New Column( "Variance", Numeric, "Continuous", Values( vc ) );
// creates a new column called Variance