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
jnikkel
Level II

Making my script more user-friendly

 

Being very new to scripting, I was able to generate this script to help streamline some data analysis for my research group. As of now, it is not very user friendly, (have to go into the script and manually insert Target File Path, change all of the 'By1' and 'By1 Variable #' to match the sample name defined by the Target File Path (By1 = Target File Path), and manually close all data, tabulate, and report windows that the script opens. I am trying to teach myself through the scripting index how to overcome all those obstacles and streamline the script, but it is relatively slow going.

 

My goal is that the operator only has to interact with two prompt windows, one that asks you to designate the file you want to open and then one to save the final generated data table, while closing all windows generated by the script.

 

Any suggestions and tips are welcome, learning scripting for the first time in JSL is very enjoyable!

Names Default To Here( 1 );

dt = Open( "Target File Path");
obj = dt << Tabulate(
	Add Table(
		Column Table(
			Analysis Columns( :X1, :Y, :X2, :X3 ),
			Statistics( Mean )
		),
		Row Table( Grouping Columns( :By1, :By2 ) )
	)
);

obj << Make into Data Table;
nw = New Window ("Bivarate By2 Fit",
	V List Box(
		Fit Group(
			Biv = Bivariate(
				SendToByGroup( {:By1 == "By1 Variable 1"} ),
				SendToByGroup( {:By1 == "By1 Variable 1"}, Y( :Name( "Mean(X1)" ) ) ),
				SendToByGroup(
					{:By1 == "By1 Variable 1", Platform Index( 2 )},
					Y( :Name( "Mean(X3)" ) )
				),
				SendToByGroup(
					{:By1 == "By1 Variable 1", Platform Index( 3 )},
					Y( :Name( "Mean(X2)" ) )
				),
				SendToByGroup( {:By1 == "By1 Variable 2"}, Y( :Name( "Mean(X1)" ) ) ),
				SendToByGroup(
					{:By1 == "By1 Variable 2", Platform Index( 2 )},
					Y( :Name( "Mean(X3)" ) )
				),
				SendToByGroup(
					{:By1 == "By1 Variable 2", Platform Index( 3 )},
					Y( :Name( "Mean(X2)" ) )
				),
				SendToByGroup( {:By1 == "By1 Variable 3"}, Y( :Name( "Mean(X1)" ) ) ),
				SendToByGroup(
					{:By1 == "By1 Variable 3", Platform Index( 2 )},
					Y( :Name( "Mean(X3)" ) )
				),
				SendToByGroup(
					{:By1 == "By1 Variable 3", Platform Index( 3 )},
					Y( :Name( "Mean(X2)" ) )
				),
				SendToByGroup( {:By1 == "By1 Variable 4"}, Y( :Name( "Mean(X1)" ) ) ),
				SendToByGroup(
					{:By1 == "By1 Variable 4", Platform Index( 2 )},
					Y( :Name( "Mean(X3)" ) )
				),
				SendToByGroup(
					{:By1 == "By1 Variable 4", Platform Index( 3 )},
					Y( :Name( "Mean(X2)" ) )
				),
				SendToByGroup( {:By1 == "By1 Variable 5"}, Y( :Name( "Mean(X1)" ) ) ),
				SendToByGroup(
					{:By1 == "By1 Variable 5", Platform Index( 2 )},
					Y( :Name( "Mean(X3)" ) )
				),
				SendToByGroup(
					{:By1 == "By1 Variable 5", Platform Index( 3 )},
					Y( :Name( "Mean(X2)" ) )
				),
				SendToByGroup( {:By1 == "By1 Variable 6"}, Y( :Name( "Mean(X1)" ) ) ),
				SendToByGroup(
					{:By1 == "By1 Variable 6", Platform Index( 2 )},
					Y( :Name( "Mean(X3)" ) )
				),
				SendToByGroup(
					{:By1 == "By1 Variable 6", Platform Index( 3 )},
					Y( :Name( "Mean(X2)" ) )
				),
				SendToByGroup( {:By1 == "By1 Variable 7"}, Y( :Name( "Mean(X1)" ) ) ),
				SendToByGroup(
					{:By1 == "By1 Variable 7", Platform Index( 2 )},
					Y( :Name( "Mean(X3)" ) )
				),
				SendToByGroup(
					{:By1 == "By1 Variable 7", Platform Index( 3 )},
					Y( :Name( "Mean(X2)" ) )
				),
				SendToByGroup( {:By1 == "By1 Variable 8"}, Y( :Name( "Mean(X1)" ) ) ),
				SendToByGroup(
					{:By1 == "By1 Variable 8", Platform Index( 2 )},
					Y( :Name( "Mean(X3)" ) )
				),
				SendToByGroup(
					{:By1 == "By1 Variable 8", Platform Index( 3 )},
					Y( :Name( "Mean(X2)" ) )
				),
				X( :Name( "Mean(Y)" ) ),
				Fit Line( {Line Color( {212, 73, 88} )} ),
				By( :By1 )
			)
		)	
	)
);
Report ( Biv[1] ) ["Parameter Estimates"][Table Box(1)] << Make Combined Data Table;
dt = current data table ();
obj = dt << Split(
	Split By( :Term ),
	Split( :Y, :By1, :Estimate ),
	Remaining Columns( Drop All ),
	Sort by Column Property
);
New Column( "By2", Numeric, Continuous );
:"By2" << Format( "Percent", ,2 );
:"Estimate Mean(Y)" << Set Name ("Estimate Mean");
dt = current data table();
col =Column(dt, "By2");
col << Set Formula (:Estimate Mean() / :Estimate Intercept);
obj = dt << Tabulate(
	Add Table(
		Column Table(
			Grouping Columns( :By1 Intercept ),
			Analysis Columns( :By2 )
		),
		Row Table( Grouping Columns( :Y Intercept ) )
	)
);

obj << Make into Data Table;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
jnikkel
Level II

Re: Making my script more user-friendly

I figured out the open and close functions, but I am still having trouble figuring out how to auto-populate the By1 variable in the Fit Group section from the data in the opened files By1 column.

 

Any Suggestions? updated script below

 

dt1 = Open(
	Pick File("Select JMP File",
	"$Documents",
	{"JMP Files|jmp", "All Files|*"},
	1,
	0 
	)
);

obj1 = dt1 << Tabulate(
	Add Table(
		Column Table(
			Analysis Columns( :X1, :Y, :X2, :X3 ),
			Statistics( Mean )
		),
		Row Table( Grouping Columns( :By1, :By2 ) )
	)
);	

obj1 << Make into Data Table;
dt2 = current data table();
Close (dt1);

nw1 = New Window ("Bivarate Fit",
	V List Box(
		Fit Group(
			Biv = Bivariate(
				SendToByGroup( {:By1 == "Series-1"} ),
				SendToByGroup( {:By1 == "Series-1"}, Y( :Name( "Mean(X1)" ) ) ),
				SendToByGroup(
					{:By1 == "Series-1", Platform Index( 2 )},
					Y( :Name( "Mean(X2)" ) )
				),
				SendToByGroup(
					{:By1 == "Series-1", Platform Index( 3 )},
					Y( :Name( "Mean(X3)" ) )
				),
				SendToByGroup( {:By1 == "By1 Variable 2"}, Y( :Name( "Mean(X1)" ) ) ),
				SendToByGroup(
					{:By1 == "By1 Variable 2", Platform Index( 2 )},
					Y( :Name( "Mean(X2)" ) )
				),
				SendToByGroup(
					{:By1 == "By1 Variable 2", Platform Index( 3 )},
					Y( :Name( "Mean(X3)" ) )
				),
				SendToByGroup( {:By1 == "By1 Variable 3"}, Y( :Name( "Mean(X1)" ) ) ),
				SendToByGroup(
					{:By1 == "By1 Variable 3", Platform Index( 2 )},
					Y( :Name( "Mean(X2)" ) )
				),
				SendToByGroup(
					{:By1 == "By1 Variable 3", Platform Index( 3 )},
					Y( :Name( "Mean(X3)" ) )
				),
				SendToByGroup( {:By1 == "By1 Variable 4"}, Y( :Name( "Mean(X1)" ) ) ),
				SendToByGroup(
					{:By1 == "By1 Variable 4", Platform Index( 2 )},
					Y( :Name( "Mean(X2)" ) )
				),
				SendToByGroup(
					{:By1 == "By1 Variable 4", Platform Index( 3 )},
					Y( :Name( "Mean(X3)" ) )
				),
				SendToByGroup( {:By1 == "By1 Variable 5"}, Y( :Name( "Mean(X1)" ) ) ),
				SendToByGroup(
					{:By1 == "By1 Variable 5", Platform Index( 2 )},
					Y( :Name( "Mean(X2)" ) )
				),
				SendToByGroup(
					{:By1 == "By1 Variable 5", Platform Index( 3 )},
					Y( :Name( "Mean(X3)" ) )
				),
				SendToByGroup( {:By1 == "By1 Variable 6"}, Y( :Name( "Mean(X1)" ) ) ),
				SendToByGroup(
					{:By1 == "By1 Variable 6", Platform Index( 2 )},
					Y( :Name( "Mean(X2)" ) )
				),
				SendToByGroup(
					{:By1 == "By1 Variable 6", Platform Index( 3 )},
					Y( :Name( "Mean(X3)" ) )
				),
				SendToByGroup( {:By1 == "By1 Variable 7"}, Y( :Name( "Mean(X1)" ) ) ),
				SendToByGroup(
					{:By1 == "By1 Variable 7", Platform Index( 2 )},
					Y( :Name( "Mean(X2)" ) )
				),
				SendToByGroup(
					{:By1 == "By1 Variable 7", Platform Index( 3 )},
					Y( :Name( "Mean(X3)" ) )
				),
				SendToByGroup( {:By1 == "By1 Variable 8"}, Y( :Name( "Mean(X1)" ) ) ),
				SendToByGroup(
					{:By1 == "By1 Variable 8", Platform Index( 2 )},
					Y( :Name( "Mean(X2)" ) )
				),
				SendToByGroup(
					{:By1 == "By1 Variable 8", Platform Index( 3 )},
					Y( :Name( "Mean(X3)" ) )
				),
				SendToByGroup( {:By1 == "By1 Variable 9"}, Y( :Name( "Mean(X1)" ) ) ),
				SendToByGroup(
					{:By1 == "By1 Variable 9", Platform Index( 2 )},
					Y( :Name( "Mean(X2)" ) )
				),
				SendToByGroup(
					{:By1 == "By1 Variable 9", Platform Index( 3 )},
					Y( :Name( "Mean(X3)" ) )
				),
				SendToByGroup( {:By1 == "By1 Variable 10"}, Y( :Name( "Mean(X1)" ) ) ),
				SendToByGroup(
					{:By1 == "By1 Variable 10", Platform Index( 2 )},
					Y( :Name( "Mean(X2)" ) )
				),
				SendToByGroup(
					{:By1 == "By1 Variable 10", Platform Index( 3 )},
					Y( :Name( "Mean(X3)" ) )
				),
				X( :Name( "Mean(Y)" ) ),
				Fit Line( {Line Color( {212, 73, 88} )} ),
				By( :By1 )
			)
		)	
	)
);

Report ( Biv[1] ) ["Parameter Estimates"][Table Box(1)] << Make Combined Data Table;
dt3 = current data table ();
obj2 = dt3 << Split(
	Split By( :Term ),
	Split( :Y, :By1, :Estimate ),
	Remaining Columns( Drop All ),
	Sort by Column Property
);
New Column( "By2", Numeric, Continuous );
:"By2" << Format( "Percent", ,2 );
:"Estimate Mean(Y)" << Set Name ("Estimate Mean");

Close (dt3);

dt4 = current data table();
col =Column(dt4, "By2");
col << Set Formula (:Estimate Mean() / :Estimate Intercept);
obj3 = dt4 << Tabulate(
	Add Table(
		Column Table(
			Grouping Columns( :By1 Intercept ),
			Analysis Columns( :By2 )
		),
		Row Table( Grouping Columns( :Y Intercept ) )
	)
);

obj 3 << Make Into Data Table;
Close (dt4);

dt = current data table();
If( dt << Save( "" ),
	Write( "\!nsaved to " || (dt << GetPath) ),
	Write( "\!nsave canceled" )
);

View solution in original post

1 REPLY 1
jnikkel
Level II

Re: Making my script more user-friendly

I figured out the open and close functions, but I am still having trouble figuring out how to auto-populate the By1 variable in the Fit Group section from the data in the opened files By1 column.

 

Any Suggestions? updated script below

 

dt1 = Open(
	Pick File("Select JMP File",
	"$Documents",
	{"JMP Files|jmp", "All Files|*"},
	1,
	0 
	)
);

obj1 = dt1 << Tabulate(
	Add Table(
		Column Table(
			Analysis Columns( :X1, :Y, :X2, :X3 ),
			Statistics( Mean )
		),
		Row Table( Grouping Columns( :By1, :By2 ) )
	)
);	

obj1 << Make into Data Table;
dt2 = current data table();
Close (dt1);

nw1 = New Window ("Bivarate Fit",
	V List Box(
		Fit Group(
			Biv = Bivariate(
				SendToByGroup( {:By1 == "Series-1"} ),
				SendToByGroup( {:By1 == "Series-1"}, Y( :Name( "Mean(X1)" ) ) ),
				SendToByGroup(
					{:By1 == "Series-1", Platform Index( 2 )},
					Y( :Name( "Mean(X2)" ) )
				),
				SendToByGroup(
					{:By1 == "Series-1", Platform Index( 3 )},
					Y( :Name( "Mean(X3)" ) )
				),
				SendToByGroup( {:By1 == "By1 Variable 2"}, Y( :Name( "Mean(X1)" ) ) ),
				SendToByGroup(
					{:By1 == "By1 Variable 2", Platform Index( 2 )},
					Y( :Name( "Mean(X2)" ) )
				),
				SendToByGroup(
					{:By1 == "By1 Variable 2", Platform Index( 3 )},
					Y( :Name( "Mean(X3)" ) )
				),
				SendToByGroup( {:By1 == "By1 Variable 3"}, Y( :Name( "Mean(X1)" ) ) ),
				SendToByGroup(
					{:By1 == "By1 Variable 3", Platform Index( 2 )},
					Y( :Name( "Mean(X2)" ) )
				),
				SendToByGroup(
					{:By1 == "By1 Variable 3", Platform Index( 3 )},
					Y( :Name( "Mean(X3)" ) )
				),
				SendToByGroup( {:By1 == "By1 Variable 4"}, Y( :Name( "Mean(X1)" ) ) ),
				SendToByGroup(
					{:By1 == "By1 Variable 4", Platform Index( 2 )},
					Y( :Name( "Mean(X2)" ) )
				),
				SendToByGroup(
					{:By1 == "By1 Variable 4", Platform Index( 3 )},
					Y( :Name( "Mean(X3)" ) )
				),
				SendToByGroup( {:By1 == "By1 Variable 5"}, Y( :Name( "Mean(X1)" ) ) ),
				SendToByGroup(
					{:By1 == "By1 Variable 5", Platform Index( 2 )},
					Y( :Name( "Mean(X2)" ) )
				),
				SendToByGroup(
					{:By1 == "By1 Variable 5", Platform Index( 3 )},
					Y( :Name( "Mean(X3)" ) )
				),
				SendToByGroup( {:By1 == "By1 Variable 6"}, Y( :Name( "Mean(X1)" ) ) ),
				SendToByGroup(
					{:By1 == "By1 Variable 6", Platform Index( 2 )},
					Y( :Name( "Mean(X2)" ) )
				),
				SendToByGroup(
					{:By1 == "By1 Variable 6", Platform Index( 3 )},
					Y( :Name( "Mean(X3)" ) )
				),
				SendToByGroup( {:By1 == "By1 Variable 7"}, Y( :Name( "Mean(X1)" ) ) ),
				SendToByGroup(
					{:By1 == "By1 Variable 7", Platform Index( 2 )},
					Y( :Name( "Mean(X2)" ) )
				),
				SendToByGroup(
					{:By1 == "By1 Variable 7", Platform Index( 3 )},
					Y( :Name( "Mean(X3)" ) )
				),
				SendToByGroup( {:By1 == "By1 Variable 8"}, Y( :Name( "Mean(X1)" ) ) ),
				SendToByGroup(
					{:By1 == "By1 Variable 8", Platform Index( 2 )},
					Y( :Name( "Mean(X2)" ) )
				),
				SendToByGroup(
					{:By1 == "By1 Variable 8", Platform Index( 3 )},
					Y( :Name( "Mean(X3)" ) )
				),
				SendToByGroup( {:By1 == "By1 Variable 9"}, Y( :Name( "Mean(X1)" ) ) ),
				SendToByGroup(
					{:By1 == "By1 Variable 9", Platform Index( 2 )},
					Y( :Name( "Mean(X2)" ) )
				),
				SendToByGroup(
					{:By1 == "By1 Variable 9", Platform Index( 3 )},
					Y( :Name( "Mean(X3)" ) )
				),
				SendToByGroup( {:By1 == "By1 Variable 10"}, Y( :Name( "Mean(X1)" ) ) ),
				SendToByGroup(
					{:By1 == "By1 Variable 10", Platform Index( 2 )},
					Y( :Name( "Mean(X2)" ) )
				),
				SendToByGroup(
					{:By1 == "By1 Variable 10", Platform Index( 3 )},
					Y( :Name( "Mean(X3)" ) )
				),
				X( :Name( "Mean(Y)" ) ),
				Fit Line( {Line Color( {212, 73, 88} )} ),
				By( :By1 )
			)
		)	
	)
);

Report ( Biv[1] ) ["Parameter Estimates"][Table Box(1)] << Make Combined Data Table;
dt3 = current data table ();
obj2 = dt3 << Split(
	Split By( :Term ),
	Split( :Y, :By1, :Estimate ),
	Remaining Columns( Drop All ),
	Sort by Column Property
);
New Column( "By2", Numeric, Continuous );
:"By2" << Format( "Percent", ,2 );
:"Estimate Mean(Y)" << Set Name ("Estimate Mean");

Close (dt3);

dt4 = current data table();
col =Column(dt4, "By2");
col << Set Formula (:Estimate Mean() / :Estimate Intercept);
obj3 = dt4 << Tabulate(
	Add Table(
		Column Table(
			Grouping Columns( :By1 Intercept ),
			Analysis Columns( :By2 )
		),
		Row Table( Grouping Columns( :Y Intercept ) )
	)
);

obj 3 << Make Into Data Table;
Close (dt4);

dt = current data table();
If( dt << Save( "" ),
	Write( "\!nsaved to " || (dt << GetPath) ),
	Write( "\!nsave canceled" )
);