Subscribe Bookmark RSS Feed

Access a platform in a script

sebastianhoffme

Community Trekker

Joined:

Mar 27, 2015

I'm writing a script that will add some additional information to an existing platform (e.g. adding RSquare Predicted to Fit model). I am able to add the pred.R2 to a platform that is created as part of my script. But how would I get a reference to a model that was fit by the user? I would like to create a user dialog, allowing the user to select the platform window the pred.R2 should be added to.

Of course I would prefer even more to just add my own menu entry to the main hotspot of the Fit-Model-plaftorm, but I have no idea if that is possible?

Thanks for any advice,

Sebastian

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

Usually, << Get Scriptable Object can give access to the platform. However, the Fit Model output is a bit peculiar and requires some digging into the report to find the top outlinebox of the platform.

If there is no By-role assigned, the below should work (assuming functions and definitions as above).

// Dialog

New Window("Select Regression Report",

    <<Modal,

    Panel Box("Select Regression Report to add Predicted R2 to",

        rb = Radio Box(windows),

        Button Box("OK",

            Window(rb << get selected) << Bring Window to Front;

            insertToReport(

                Current Report()[1, 1, 1] << get scriptable object()

            );

        )

    )

);

7 REPLIES
ian_jmp

Staff

Joined:

Jun 23, 2011

I think more details are required about the workflow you envisage, Sebastian. Am I correct in thinking that you want to use a modeling platform (like Neural) that allows multiple models in the same report? In which case, is there one such platform of specific interest?

sebastianhoffme

Community Trekker

Joined:

Mar 27, 2015

Hi Ian,

thanks for the reply. I would like to follow this workflow:

1. The users starts his analysis using "Fit Model (Standard Least Squares)".

2. Then the user runs my script to add the Predicted R2 to his report.

3. Predicted R2 is then attached to the "Fit Model" Report.

The problem is how I access the report that was created by the user in my script.

Currently my code looks like this. I basically want to replace the last section "Test it" with a user dialog where the user choses the report where the Pred. R2 should be added (especially in case there are multiple reports). I am just missing the part how I could reference an existing report.

// Extracts the PRESS statistic from a "Fit Model"-plattform

getPRESS = Function({plattform},

  plattform << Press(show=1);

  report = plattform << Report;

  press = (report[OutlineBox("Press")][1][1] << Get As Matrix)[1];

  press;

);

// Extracts the total sum of squares from a "Fit Model"-plattform

getTSS = Function({plattform},

  report = plattform << Report;

  ss = (report[OutlineBox("Analysis of Variance")][1][3] << Get As Matrix);

  tss = ss[Nrow(ss)];

  tss;

);

// Calculates the predicted R2 for a linear model calculated using the Fit-Model-plattform

predR2 = Function({plattform},

  press = getPRESS(plattform);

  tss = getTSS(plattform);

  pr2 = 1 - press/tss;

  pr2;

);

// Insert the pred R2 to the report

insertToReport = Function({plattform},

  lm.rep = plattform << Report;

  names = lm.rep[OutlineBox("Summary of Fit")][StringColBox(1)] << Get;

  values = lm.rep[OutlineBox("Summary of Fit")][Number Col Box(1)] << Get;

  Insert Into(names, "RSquare Predicted", 3);

  Insert Into(values, predR2(plattform), 3);

  lm.rep[OutlineBox("Summary of Fit")][StringColBox(1)] << Set Values(names);

  lm.rep[OutlineBox("Summary of Fit")][NumberColBox(1)] << Set Values(Matrix(values));

);

// Test it

dt = Open("$sample_data/Design Experiment/Coffee Data.jmp");

analysis  = Fit Model(

  Y( :Strength ),

  Effects( :Grind, :Temperature, :Time, :Charge, :Station ),

  Personality( "Standard Least Squares" ),

  Emphasis( "Minimal Report" ),

  Run(

  :Strength << {Lack of Fit( 0 ), Plot Actual by Predicted( 0 ),

  Plot Regression( 0 ), Plot Residual by Predicted( 0 ),

  Plot Effect Leverage( 0 )}

  )

);

InsertToReport(analysis);



Addition: This is what I tried but could not make work:

//-----------------------+

// User Dialog |

//-----------------------+

// Get all open windows

windows = {};

ref_windows = Window();

For(i = 1, i <= Length(ref_windows), i++,

  Insert Into(windows, ref_windows << Get Window Title);

);

// Dialog

New Window("Select Regression Report", << Modal,

  Panel Box("Select Regression Report to add Predicted R2 to", pf = Radio Box(windows));

);

lm_plattform  = Plattform(pf << Get);

lm_plattform << Bring to Front;

insertToReport(lm_plattform);


ian_jmp

Staff

Joined:

Jun 23, 2011

Many thanks, Sebastian. I've almost got it (I think), so let me recap . . .

Your user would have their JMP session in a state that your code does not know about. In other words, they could have multiple tables open, each with multiple windows. Some of these windows might contain a 'Fit Least Squares'; report. Your code should scan all open windows, identify the latter and, if there is more than one, let the user chose which one to append the additional report content to (if there is only one, there is no need to ask). The key point being that your code did not actually generate any of the reports.

Is that correct, please?

sebastianhoffme

Community Trekker

Joined:

Mar 27, 2015

Yes thats it exactly!

Solution

Usually, << Get Scriptable Object can give access to the platform. However, the Fit Model output is a bit peculiar and requires some digging into the report to find the top outlinebox of the platform.

If there is no By-role assigned, the below should work (assuming functions and definitions as above).

// Dialog

New Window("Select Regression Report",

    <<Modal,

    Panel Box("Select Regression Report to add Predicted R2 to",

        rb = Radio Box(windows),

        Button Box("OK",

            Window(rb << get selected) << Bring Window to Front;

            insertToReport(

                Current Report()[1, 1, 1] << get scriptable object()

            );

        )

    )

);

sebastianhoffme

Community Trekker

Joined:

Mar 27, 2015

Thank you very much MS! That did the trick. I did not know <<get scriptable object before!

hlrauch

Community Trekker

Joined:

Sep 19, 2014

Sebastian,

Just to build on MS's excellent reply... We've written a very similar script to add the R2 Predicted value to the Fit Model output. Instead of displaying a dialog box to select the appropriate report, you can run the script from the menu or a toolbar of the current report window (the script must be added to the menu or a toolbar). Then the Current Window() command provides a reference to the report window, and you can search the outline boxes within the report window. Here is a portion of our script.

curwin = Current Window();

For( i = 1, i < 10000, i++,

     Try(

          outlinebox = curwin[Outline Box( i )];

          Try(

               outlineboxobj = outlinebox << Get Scriptable Object;

               // DETAILS NOT SHOWN:

               // Check that the outline box is the top of a Fit Model analysis, with Standard Least Squares personality.

               // Pull the PRESS statistic and SS(treatment) to calculate R2-Predicted and append it to the Summary of Fit.

          );

     ,

          Break();  // If no more outline boxes are found, the first "Try()" goes here and forces an escape from the For() loop.

     );

);

    

Our script actually inserts the R2 Predicted value into every Fit Model analysis in that window (works for multiple Y's and by-variables). It does this by looking at every outline box in the report window.

Comments:

1. The JSL documentation does not do justice to the "<< Get Scriptable Object" message. I looked for a very long time for a method to access existing report windows (standard analyses that had already been created by a user, not by a script). This capability opens up a lot of scripting opportunities.

2. To keep all of us from re-inventing the wheel, it would be nice if JMP included the R2-Predicted value in the standard Fit Least Squares output.

Howard