Hi all,
I'm stuck with the following issue: I create a Distribution platform for several variables (using a column switcher), and I would like to fit a Normal distribution if possible (i.e. if I have at least two distinct values for a given variable), but I don't want to get an error message in other cases.
I tried several things (script below), essentially by attaching scripts to the column switcher (let's call this script "ScriptExpr"). But I realized that none of this would work because "ScriptExpr" is actually not called immediately when the variable changes.
Indeed, the column switcher first tries to update the distribution graph, using the options used with the previous variable.
So if my very 1st variable is "unvalid" (VPM1 here), it's ok because I put a "try()", so the Normal fit won't be executed and I will get a message in the log ("The Normal distribution requires at least 2 distinct observations. No fit available."), which is fine.
Then if I select a "valid" variable (NPN1 for instance), "ScriptExpr" will be called and the Normal fit will be successfully applied (which is what I want).
But if I now select an "unvalid" variable (VPM1 or VPM2), I will get an error message because it will automatically try to fit a normal distribution, as it was activated with the previous variable. This is my problem.
So here is my question: is there a way of:
- sending this error message to the log (I tried to put "Batch Interactive" at other places, but nothing seems to work)
- or disabling the automatic reuse of the last activated options, so that they would be only activated (or not) afterwards by the call to "ScriptExpr"?
Thanks for your help!
/* Function to get unique values from a list */
Get_unique_values_list = Function( {in_list}, {Default Local},
tmp = [=> 0];
Insert Into( tmp, in_list );
tmp << get keys;
);
/* Open data table */
dtData = Open( "$SAMPLE_DATA/Semiconductor Capability.jmp" );
/* Create a report with a Distribution platform */
custRpt = New Window( "Analysis",
distObj = dtData<<Distribution(
Automatic Recalc( 1 ),
Continuous Distribution(
Column("VPM1"),
Always use column properties( 1 ),
//Fit Distribution( Normal )
),
)
);
/* Try to fit Normal distribution for the first variable (unvalid here) */
try(distObj<<Fit Distribution( Normal( Goodness of Fit( 1 ) ) ));
/* Add a column switcher to the distribution platform */
csObj = distObj << Column Switcher(
:VPM1,
{:NPN1, :PNP1, :VPM1, :VPM2, :VPM3, :PMS1, :SNM1}
);
/* Get reference to listbox of variables from column switcher */
myListOfCols=custRpt[ColumnSwitcherContextOutlineBox(1)][ListBoxBox(1)];
/* Different attempts to NOT get a warning popup when a variable without at least two distinct values is selected,
but to still fit my data in other cases. */
myListOfCols<<set script(
eval(ScriptExpr);
);
/* 1st idea: use Batch Interactive(1) in order to send the message to the log.
Doesn't work */
ScriptExpr=expr(
Batch Interactive(1);
distObj<<Fit Distribution( Normal( Goodness of Fit( 1 ) ) );
Batch Interactive(0);
);
/* 2nd idea: use a try().
Doesn't work */
ScriptExpr=expr(
try(distObj<<Fit Distribution( Normal( Goodness of Fit( 1 ) ) ));
);
/* 3rd idea: first test whether there enough distinct values, and ask for the fit only in this case.
Doesn't work */
ScriptExpr=expr(
currValue=(myListOfCols<<get selected)[1];
uniqueVal=Get_unique_values_list(Column(currValue)<<get values);
if(nitems(uniqueVal)!=1,
distObj<<Fit Distribution( Normal( Goodness of Fit( 1 ) ) );
);
);