Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
vince_faller
Super User

Trying get a fit model with user input.

Let's say I want to help a user with a fit model, because I know what the Y is and I know that I want them to do gen reg.  So I give them this.  

 

Names default to here(1);
dt = open("$SAMPLE_DATA\Big Class.jmp");
fit  = dt << Fit Model(
	Y( :height ),
	Effects(),
	Center Polynomials( 0 ),
	Personality( "Generalized Regression" ),
	Generalized Distribution( "Normal" ),
);

Cool, fit = a model dialog.  But it's not modal, so the script keeps running.  Also, when they push run, fit is deleted.  

What I really want is for the user enter their stuff and then once the report  is up, I proceed.   

I'm trying to do something like this, but I've had no luck.  

while(
	obj = current report()[OutlineBox(1)] << Get Scriptable Object();
	!(char(obj) == "Fit Generalized[]" & try(obj[1] << Get Prediction Formula; 1, 0));
, 
	wait(.3);
);

I REALLY don't want to have to rebuild that whole UI with all of the options, especially since effects are not straight forward to put in.  

 

Vince Faller - Predictum
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
ian_jmp
Staff

Re: Trying get a fit model with user input.

I've used this kind of approach a few times previously:

Names default to here(1);

dt = open("$SAMPLE_DATA\Big Class.jmp");

fit  = dt << Fit Model(
	Y( :height ),
	Effects(),
	Center Polynomials( 0 ),
	Personality( "Generalized Regression" ),
	Generalized Distribution( "Normal" ),
);

// The 'Run' button
runButton = Report(fit)[ButtonBox(9)];

// Append to the in-built action of the button
runButton << setScript(doSomething);

// The 'Terms' shown in 'dt2' reflect the user selections made in teh launch dialog
doSomething =
Expr(
	Beep();
	fit2 = fit << run;
	dt2 = Report(fit2)[tableBox(5)] << makeCombinedDataTable;
	dt2 << setName("Parameter Estimates")
);

View solution in original post

6 REPLIES 6
Highlighted
vince_faller
Super User

Re: Trying get a fit model with user input.

I can do something like this, but I feel like there's a thousand ways to break this and am really hoping for something more robust. 

while(
	obj = current report()[OutlineBox(1)] << Get Scriptable Object();
	!(char(obj) == "Fit Generalized[]");
, 
	wait(.3);
);

btn_go_real = report(obj)[Buttonbox(1)];
report(obj)[1] << Append(Buttonbox("MyGo", 
	<<Set Function(
		Function({self}, 
			{DEFAULT LOCAL}, 
			((self << Parent)[Buttonbox(1)]) << Click;
			print("Found it");
		)
	)
));
btn_go_real << Visibility("Collapse");
Vince Faller - Predictum
Highlighted
txnelson
Super User

Re: Trying get a fit model with user input.

Does this do anything to help?  It is a modal window, and you can capture the output display tree.

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA\Big Class.jmp" );
nw = New Window( "example",
	<<modal,
	fit = dt << Fit Model(invisible,
		Y( :height ),
		Effects(),
		Center Polynomials( 0 ),
		Personality( "Generalized Regression" ),
		Generalized Distribution( "Normal" )
	),
buttonbox("OK", fit<<run; zippy=fit;)
);
fit=window("Big Class - Generalized Regression")<<child;
fit[OutlineBox(1)]<<close;
Jim
Highlighted
vince_faller
Super User

Re: Trying get a fit model with user input.

Not really, because of the second window 

Vince Faller - Predictum
Highlighted
ian_jmp
Staff

Re: Trying get a fit model with user input.

I've used this kind of approach a few times previously:

Names default to here(1);

dt = open("$SAMPLE_DATA\Big Class.jmp");

fit  = dt << Fit Model(
	Y( :height ),
	Effects(),
	Center Polynomials( 0 ),
	Personality( "Generalized Regression" ),
	Generalized Distribution( "Normal" ),
);

// The 'Run' button
runButton = Report(fit)[ButtonBox(9)];

// Append to the in-built action of the button
runButton << setScript(doSomething);

// The 'Terms' shown in 'dt2' reflect the user selections made in teh launch dialog
doSomething =
Expr(
	Beep();
	fit2 = fit << run;
	dt2 = Report(fit2)[tableBox(5)] << makeCombinedDataTable;
	dt2 << setName("Parameter Estimates")
);

View solution in original post

Highlighted
gzmorgan0
Super User

Re: Trying get a fit model with user input.

@vince_faller , @ian_jmp  beat me to it. Actually my script uses 2 features Keep Dialog Open and then Ian's trick to add a script to a run button that he provided a couple years ago (near August 21, 2018). My doSomething saves the model to the data table. 

 

Using this opportunity to thank Ian again for the useful trick and Keep Dialog Open (which Ian employs as well). I actually cut and paste his code and modified!

 

Names default to here(1);
dt = open("$SAMPLE_DATA\Big Class.jmp");
fit  = dt << Fit Model(
	Y( :height ),
	Effects(),
	Center Polynomials( 0 ),
	Personality( "Generalized Regression" ),
	Generalized Distribution( "Normal" ),
	Keep Dialog Open(1)
);

//  Define a sample script

doSomething = 

Expr(

	Beep();

//	For( i = 1, i <= N Table(), i++,
//		Print( i, Data Table( i ) << getName )
//	);
   
    fit << Save to Data Table;
	snames = dt << Get Table Script Names();
	s = dt << get script( snames[N Items( snames )] );
	Show( s );
);

// Assign the sample script to the button (JMP seems to prepend to the script that's already there?)

Report( fit )[Button Box( 9 )] << setScript( doSomething );

 

Highlighted
vince_faller
Super User

Re: Trying get a fit model with user input.

Thanks @ian_jmp and @gzmorgan0 , I built upon what y'all said and basically just did it twice because I really wanted my doSomething to do stuff after pressing Go in the Gen Reg Platform.  I also functionalized them just to make sure that local variables didn't break anything with this method.  

One more question that I haven't been able to get past, if I want my "My_Gen_Reg" function to return the value from the "doSomething". Again, trying not to use globals or heres.  

*Edit*, I have a stopgap solution that seems to work.  I still don't like the way it works though.  It's definitely better than recreating the UI though.  

 

Names default to here(1);

my_Gen_Reg = Function({dt}, 
	{fit, pf_get}, 
	fit  = dt << Fit Model(
		Y( :height ),
		Effects(),
		Center Polynomials( 0 ),
		Personality( "Generalized Regression" ),
		Generalized Distribution( "Normal" ),
		//Keep Dialog Open(1)
	);

	Report( fit )[Button Box( 9 )] << Set Function( 
		Function({self}, 
			{fit_self, fit2}, 
			fit_self = ((self << Top Parent)[OutlineBox(1)]<<Get Scriptable Object);
			fit2 = fit_self  << Run();
			report(fit2)[ButtonBox(1)] << Set Function(
				Function({self}, 
					{fit_self}, 
					fit_self = ((self << Top Parent)[OutlineBox(1)]<<Get Scriptable Object);
					// make sure the platform runs before I do something.  
					self << Click; 
					here:pf_get = doSomething(fit_self);
				)
			)

		)
	);
	
	while(isempty(here:pf_get), 
		wait(.3);
	);
	
	pf_get = nameexpr(here:pf_get);
	delete symbols(here:pf_get);
	return(nameexpr(pf_get));
);

doSomething = Function({ff}, 
	{pf},
	Beep();
	while(pf = ff << (fit[1] << Get Prediction Formula);
		char(nameexpr(pf)) == "Fit Generalized[]"
	, // while
		wait(1);
	);
	// I really want to return pf from My_Gen_Reg
	return(nameexpr(pf));
);

dt = open("$SAMPLE_DATA\Big Class.jmp");
pf2 = my_Gen_Reg(dt);
show(pf2);

 

Vince Faller - Predictum
Article Labels

    There are no labels assigned to this post.