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.
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=""></SET>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></MODAL>
Re: Trying get a fit model with user input.Not really, because of the second window
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")
);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 );
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=""></GET>