Subscribe Bookmark RSS Feed

Send error messages to the log in column switcher Distribution

heloiseheraud

Community Trekker

Joined:

Feb 14, 2016

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 ) ) );

      );

);

6 REPLIES
Phil_Brown

Super User

Joined:

Mar 20, 2012

hi heloiseheraud,

try:


eval( ​name expr​​​(ScriptExpr) )


Phil​

PDB
heloiseheraud

Community Trekker

Joined:

Feb 14, 2016

Hi PBZ​,

thanks for the suggestion. I tried, but I get the same result as without using name expr()...

Héloïse

Phil_Brown

Super User

Joined:

Mar 20, 2012

heloiseheraud,


After a closer look at your script, I would approach this slightly differently:

1. First get the valid columns using your Get_unique_values_list() function.

2. Launch Distribution platform with Normal Fit option.

3. Add column switcher using the valid columns found in step 1.

/* 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;

);

/* Get all numeric/continuous columns in data table */

colList = dtData << get column names( numeric, continuous );

/* Find columns with more than 1 unique value and store in the list "validCols" */

validCols = {};

For( i = 1, i <= N Items( colList ), i++,

     uniqueVal = Get_unique_values_list( colList << get values );

     If( N Items( uniqueVal ) != 1,

          Insert Into( validCols, colList )

     );

);

/* Generate Distribution analysis with Normal Distribution fit. Include column switcher with validCols list */

custRpt =

Eval(

     Eval Expr(

          New Window( "Analysis",

               distObj = dtData << Distribution(

                    Continuous Distribution( Column( Expr( validCols[1] ) ), Always use column properties( 1 ), Fit Distribution( Normal ) ));

             

               distObj << Column Switcher( Expr( validCols[1] ), Expr( validCols[2 :: N Items( validCols )] ) );

          )

     )

);

PDB
heloiseheraud

Community Trekker

Joined:

Feb 14, 2016

Hi PBZ

Sorting the valid columns beforehand would be indeed the best way of not getting any error message.

The problem is I really want to have all of my variables in the column switcher, because in my actual "ScriptExpr", I do lots of other things that I didn't mention here but which will work with every variable, and which the final user needs. I know there are many constraints, sorry!

All of this makes me realize that maybe the solution for me would be not to use a column switcher but rather a list box, and attach the script to this list box for doing at once a Distribution platform (with or without continuous fit according to the data) and the rest of my operations. I guess it will be slightly slower, but should work in any case.

Thanks for looking into the situation!

Héloïse

txnelson

Super User

Joined:

Jun 22, 2012

I have used list boxes for what you are proposing, and they work well. 

However, I find that using Table Boxes as the selection tool provide a better solution.  Besides having sort tools for the users, they also let you specify the displaying of more than one list.

Jim
heloiseheraud

Community Trekker

Joined:

Feb 14, 2016

txnelson

I usually use list boxes as well, and this works fine. I just thought column switcher would be more efficient in this case, and then I forgot that it was not the only way to obtain what I wanted (focusing too much on sending this message to the log!).

I've never used table boxes as a selection tool, because I find them more complicated to create and I don't quite see what they could bring to the user. I find that sort tools are very basic, and even if you can display several lists, you can't select different rows in different columns. So I prefer to have 2 linked list boxes (selecting an item in the first one determining the content of the second one).

But I might be missing something and I would be curious to see an example of a situation when it is a better tool than list boxes, if you have one in mind.

Héloïse