Subscribe Bookmark RSS Feed

Parse information from the model table script

pauldeen

Community Trekker

Joined:

Oct 24, 2014

Hi, I'm trying to make a robust way to strip the model terms from the model script. So this is an example script (automatically created with custom DOE):

Fit Model(

  Y( :Thickness Removed ),

  Effects(

  :Name( "Gas Type{1&1-3}" ),

  :Name( "Gas Type{1-3}" ),

  :Temperature,

  :Plasma Power,

  :Plasma Time,

  :Etch Gas Flow,

  :Reactor Pressure,

  :Name( "Gas Type{1&2-3}" ) * :Temperature,

  :Name( "Gas Type{1&2-3}" ) * :Plasma Power,

  :Name( "Gas Type{1&2-3}" ) * :Plasma Time,

  :Name( "Gas Type{1&2-3}" ) * :Etch Gas Flow,

  :Name( "Gas Type{1&2-3}" ) * :Reactor Pressure,

  :Temperature * :Reactor Pressure,

  :Plasma Power * :Plasma Time,

  :Plasma Power * :Etch Gas Flow,

  :Temperature * :Temperature

  ),

  Personality( "Standard Least Squares" ),

  Emphasis( "Effect Leverage" )

)

I'm interested in getting a list of the factors that are present within the effects() section. And the list of model terms in the same part of the string. The problem is the total length of the string can vary, the number of parenthesis can vary and the order of Y(), Effects(), Personality(), Emphasis() can move around.

Things it thought of but don't know how to do:

  1. use words to split the string on "," but only on the highest level. Now find the word that starts with effects and then split that again on ",". The ones without "*" are the factors, the whole thing is the list of model terms.
  2. Find "Effects" then start counting, every "(" is +1 every ")" is -1 and when you get to 0 that was the last closing parenthesis belonging to Effects now use substr to strip out that part.

But it seems to me there should be an easier way to parse the script since that is what the scripting language does.

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

If you don't mind running the script, you could do something like:

NamesDefaultToHere(1);

dt = Open("$SAMPLE_DATA/Tiretread.jmp");

fm = dt << Fit Model(

Y( :SILICA ),

Effects(

:ABRASION & RS,

:MODULUS & RS,

:ELONG & RS,

:HARDNESS & RS,

:ABRASION * :ABRASION,

:ABRASION * :MODULUS,

:MODULUS * :MODULUS,

:ABRASION * :ELONG,

:MODULUS * :ELONG,

:ELONG * :ELONG,

:ABRASION * :HARDNESS,

:MODULUS * :HARDNESS,

:ELONG * :HARDNESS,

:HARDNESS * :HARDNESS

),

Personality( "Standard Least Squares" ),

Emphasis( "Effect Screening" ),

Run

);

effectNames = fm << getEffectNames;

Report(fm) << closeWindow;

mainEffectNames = {};

for(i=1, i<=NItems(effectNames), i++, if( NItems(Words(effectNames[i], "*")) == 1, InsertInto(mainEffectNames, effectNames[i]) ));

Print(effectNames, mainEffectNames);

The 'getEffectNames' message gives a simpler expression, but you still have to parse it to get only the main effects. There are other indirect ways to get the main effects from the 'FitModel' report.

But you said 'automatically created from custom DOE', in which case it might be simpler to get the list of factors from there.

5 REPLIES
Solution

If you don't mind running the script, you could do something like:

NamesDefaultToHere(1);

dt = Open("$SAMPLE_DATA/Tiretread.jmp");

fm = dt << Fit Model(

Y( :SILICA ),

Effects(

:ABRASION & RS,

:MODULUS & RS,

:ELONG & RS,

:HARDNESS & RS,

:ABRASION * :ABRASION,

:ABRASION * :MODULUS,

:MODULUS * :MODULUS,

:ABRASION * :ELONG,

:MODULUS * :ELONG,

:ELONG * :ELONG,

:ABRASION * :HARDNESS,

:MODULUS * :HARDNESS,

:ELONG * :HARDNESS,

:HARDNESS * :HARDNESS

),

Personality( "Standard Least Squares" ),

Emphasis( "Effect Screening" ),

Run

);

effectNames = fm << getEffectNames;

Report(fm) << closeWindow;

mainEffectNames = {};

for(i=1, i<=NItems(effectNames), i++, if( NItems(Words(effectNames[i], "*")) == 1, InsertInto(mainEffectNames, effectNames[i]) ));

Print(effectNames, mainEffectNames);

The 'getEffectNames' message gives a simpler expression, but you still have to parse it to get only the main effects. There are other indirect ways to get the main effects from the 'FitModel' report.

But you said 'automatically created from custom DOE', in which case it might be simpler to get the list of factors from there.

pauldeen

Community Trekker

Joined:

Oct 24, 2014

Hi Ian, thanks for your answer, it does solve my problem:

NamesDefaultToHere(1);

dt = current data table();

fm = dt << run script("Model");

try(fm = fm << run); //Because these scripts usually don't include the run command.

effectNames = fm << getEffectNames;

Report(fm) << closeWindow;

mainEffectNames = {};

for(i=1, i<=NItems(effectNames), i++, if( NItems(Words(effectNames, "*")) == 1, InsertInto(mainEffectNames, effectNames) ));

Print(effectNames, mainEffectNames);

However for my learning: is there a way to parse the information from the string where you can look for a closing parenthesis belonging to a certain opening parenthesis and get the piece of string between those parenthesis?

And how do you format scripts in this forum to look like scripts?

ian_jmp

Staff

Joined:

Jun 23, 2011

Not completely answering your question, but JMP scripts are actually expressions, and can be manipulated as such (look for 'Head()', 'Arg()' and 'NArg{}' in the Scripting Index or Guide). For example:

fm = Expr(

Fit Model(

Y( :SILICA ),

Effects(

:ABRASION & RS,

:MODULUS & RS,

:ELONG & RS,

:HARDNESS & RS,

:ABRASION * :ABRASION,

:ABRASION * :MODULUS,

:MODULUS * :MODULUS,

:ABRASION * :ELONG,

:MODULUS * :ELONG,

:ELONG * :ELONG,

:ABRASION * :HARDNESS,

:MODULUS * :HARDNESS,

:ELONG * :HARDNESS,

:HARDNESS * :HARDNESS

),

Personality( "Standard Least Squares" ),

Emphasis( "Effect Screening" ),

Run

)

);

effects = Arg(fm, 2);

for(i=1, i<=NArg(effects), i++, Print(Arg(effects, i)));


On the other hand, they can also be treated as text strings, in which case learn about 'RegEx()' for the most general and powerful approach.

Pasting code with formatting seems a little OS and Browser dependant - I use Safari on a Mac.

pauldeen

Community Trekker

Joined:

Oct 24, 2014

Thanks!

ms

Super User

Joined:

Jun 23, 2011

Here's a way, inspired by Ian's second example, to get the Effects when the number and order of the model arguments is unknown.


fm_expr = Expr(

    Fit Model(

        Y(:Thickness Removed),

        Effects(

            :Name("Gas Type{1&1-3}"),

            :Name("Gas Type{1-3}"),

            :Temperature,

            :Plasma Power,

            :Plasma Time,

            :Etch Gas Flow,

            :Reactor Pressure,

            :Name("Gas Type{1&2-3}") * :Temperature,

            :Name("Gas Type{1&2-3}") * :Plasma Power,

            :Name("Gas Type{1&2-3}") * :Plasma Time,

            :Name("Gas Type{1&2-3}") * :Etch Gas Flow,

            :Name("Gas Type{1&2-3}") * :Reactor Pressure,

            :Temperature * :Reactor Pressure,

            :Plasma Power * :Plasma Time,

            :Plasma Power * :Etch Gas Flow,

            :Temperature * :Temperature

        ),

        Personality("Standard Least Squares"),

        Emphasis("Effect Leverage")

    )

);

//Create list of Effects

i = 1;

While(!Is Empty(arg_i = Arg(fm_expr, i)),

    If(Starts With(Char(Name Expr(arg_i)), "Effects"),

        n = N Arg(arg_i);

        effects = Repeat(

            k = 0;

            {k++ ; Arg(arg_i, k)};,

            n

        );

        Break();

    ,

        i++

    )

);

   

Print(effects);