如何防止 Run in Fit Model 生成报告?我正在编写一个执行以下操作的脚本:
- 打开“拟合模型”窗口,
- 允许用户使用“拟合模型”窗口中的宏和其他功能来填充它,
- 允许用户单击“运行”,此时将执行可能耗时的计算并生成报告。
单击“运行”时执行的计算由存储在“运行”按钮中的脚本生成。该脚本会生成一份报告,这是用户的内容应该看。但是,由于脚本已添加到“运行”按钮,因此会出现所需的报告,但随后会出现“运行”自行生成的“拟合最小二乘法”报告。拟合最小二乘报告对用户来说毫无意义。
下面的脚本说明了这个问题。 在该脚本中,“运行”按钮中的表达式“runExpr”仅创建一个克隆数据表;这是为了简化说明。在实际脚本中,该表达式 (runExpr) 根据“拟合模型”窗口中输入的效果执行大量分析。 此外,在实际脚本中,用户以交互方式填充“拟合模型”窗口;为了方便起见,我在下面的脚本中填充了“拟合模型”窗口。
Names Default To Here( 1 );
runExpr = Expr(
// Creates a clone data table for illustration;
dt << Subset( Output Table( "Clone Table" ), All rows );
);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
fmSLS = Fit Model(
Y( :weight ),
Effects( :age, :height, :age * :height ),
Personality( "Standard Least Squares" ),
Emphasis( "Minimal Report" ),
);
r = fmSLS << Report;
r[Button Box( 9 )] << Set Script( runExpr);
当您像用户一样单击“运行”时,会出现克隆表,但顶部的窗口是“运行”命令生成的“拟合最小二乘法”报告。我想阻止该报告出现。
为此:
- 我尝试在 runExpr 中使用 Throw() 和 Stop(),但没有成功。
- 我考虑过使用模态窗口,但我需要“拟合模型”窗口中的宏功能,并且我看不到如何使模态窗口帮助。
- 我能想到的解决“拟合最小二乘法”报告的唯一方法是向脚本添加一个定时循环,如下所示。 但这充满了危险。无法知道 runExpr 需要多长时间才能完成,并且如果用户决定不单击“运行”,脚本将继续运行直到超时。
任何想法或帮助将不胜感激!
Names Default To Here( 1 );
runExpr = Expr(
// Creates a clone data table for illustration;
dt << Subset( Output Table( "Clone Table" ), All rows );
fm_Flag = 1
);
fm_Flag = 0; // Sets flag for timing
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
fmSLS = Fit Model(
Y( :weight ),
Effects( :age, :height, :age * :height ),
Personality( "Standard Least Squares" ),
Emphasis( "Minimal Report" ),
);
r = fmSLS << Report;
r[Button Box( 9 )] << Set Script( runExpr; fm_Flag = 1 );
For( i = 1, i <= 100, i++,
If(fm_Flag < 1, Wait(0.5), windowsopen = Get Window List(); windowsopen[nItems(windowsopen)] << Close Window; Stop() )
);
大规模定制回复:如何防止 Run in Fit Model 生成报告?哦,天哪,太棒了!!!多么完美的“开箱即用”解决方案!
我计划今天晚些时候尝试放置自定义按钮,但我不知道我是否会尝试放置它超过运行按钮。这是一个很好的解决方案,我想我也可以在其他地方使用这个概念。我敢打赌很多用户会发现它很有用!
太感谢了!!!
回复:如何防止 Run in Fit Model 生成报告?啊哈!删除或修改“运行”按钮似乎很困难,但您可以将新按钮放在它的正上方(至少在 Windows 上使用 JMP 15.2.1...):
Names Default to Here( 1 );
run expr = Expr(
// desired report
personality = Report( fm )[ComboBox(1)] << Get Selected;
Show( personality );
);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
fm = dt << Fit Model(
Y( :weight ),
Effects( :age, :sex, :height ),
Personality( "Standard Least Squares" ),
Emphasis( "Minimal Report" )
);
// New button the user should click on
(((fm << XPath("//ButtonBox[@title='Run']"))[1] << parent) ) << prepend(
bb = Button Box("Launch custom script", run expr; fm << Close Window;) );
//make sure it is right on top of the old one
bb << set property("Margin", {Left(0), Right(0), Bottom(0), Top(0)});
// Rename old button in case it isn't hidden, and show error if user clicks it
(fm << XPath("//ButtonBox[@title='Run']"))[1] << Set Script( New Window( "Use other button",
Text Box("Woops...\!n\!nPlease use the button at the bottom of the fit model dialog to launch this script.")));
(fm << XPath("//ButtonBox[@title='Run']"))[1] << Set Button Name( "Do Not Use");回复:如何防止 Run in Fit Model 生成报告?马克,你提出了一个很好的问题,并且提出了一个很好的观点。也许有更好的方法来实现我的目标。请参阅我上面对“ih”的回复。我需要“拟合模型”窗口只是因为它允许用户灵活地构造效果。 我正在编写的脚本使用这些效果来使用分数引导权重构建模型。(无论如何,上面对“ih”的回复中有更多详细信息。)
我知道有一些脚本函数可以帮助构建模型效果,但确实需要复制“拟合模型”窗口中存在的许多功能。我希望人们可以使用该窗口来构建效果,而无需拟合模型!
回复:如何防止 Run in Fit Model 生成报告?非常感谢这个建议——这不是我考虑过的事情,但它可能是最好的建议。但是,如果用户单击“运行”(这必然会发生),那么拟合模型就会运行,并且用户必须再次运行脚本。这不是最佳的。但也许我可以利用这个想法。
您和马克都提出了一个很好的问题,即为什么我坚持使用“拟合模型”窗口。这是因为我需要允许用户访问宏和交叉功能。用户将添加他们认为重要的效果,在许多情况下,这些效果将包括完整的阶乘模型以及一些额外的三向交互项。我考虑过创建一个模式对话框,允许用户输入模型的“类型”,但此功能会限制用户。因此,我不断地回到需要有一个具有 Fit Model 大部分功能的窗口。此外,用户熟悉使用“拟合模型”输入效果,因此从这个角度来看,使用该对话框是有意义的。(我很欣赏您提供的链接,但是它没有解决效果的构建问题。复制拟合模型中存在的“交叉”、“全阶乘”、“阶乘阶乘”和“多项式阶数”功能需要编写大量脚本。其实我觉得我没有这个能力!)
现在,我为什么不想跑步适合模型吗?因为我需要的只是反应和效果;我只需要“拟合模型”的功能来构建效果。自定义脚本使用这些与分数随机加权引导程序一起使用模型平均来创建模型。创建这些模型和摘要报告的脚本当前是放置在“运行”按钮中的表达式。因此,单击“运行”将创建该自定义报告。一切都很好,除了当用户单击“运行”时,拟合模型生成的不相关的报告出现在自定义报告上。
再次感谢您的帮助。我肯定会尝试自定义按钮的想法。
回复:如何防止 Run in Fit Model 生成报告?如果您不需要“拟合最小二乘”平台,为什么要使用“拟合模型”对话框? 可能还有另一种方法可以实现您想要的目标。
回复:如何防止 Run in Fit Model 生成报告?您需要多少“模型规格”对话框? 我忍不住认为,用满足您确切需求的新窗口替换该步骤会更好。这篇文章中的示例可能会有所帮助:
完全模态提示列
如果您想使用模型规范窗口,您可以为用户提供一个新按钮以供单击:
Names Default to Here( 1 );
run expr = Expr(
// desired report
personality = Report( fm )[ComboBox(1)] << Get Selected;
Show( personality );
);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
fm = dt << Fit Model(
Y( :weight ),
Effects( :age, :sex, :height ),
Personality( "Standard Least Squares" ),
Emphasis( "Minimal Report" )
);
// Show error if user clicks the wrong button
(fm << XPath("//ButtonBox[@title='Run']"))[1] << Set Script( New Window( "Use other bottom",
Text Box("Woops...\!n\!nPlease use the button at the bottom of the fit model dialog to launch this script.")));
// Button the user should click on
(fm << XPath("//OutlineBox"))[1] << Append(Button Box("Launch custom script", run expr; fm << Close Window;));<BR />
回复:如何防止 Run in Fit Model 生成报告?是的,按钮框中的脚本似乎在执行“运行”按钮的内置行为之前运行。
这个小问题真让人烦恼啊! 必须有一种方法可以推迟脚本的执行,直到发生某个操作(例如按“运行”按钮)。 或者,阻止执行内置行为(但正如我所说,将 Throw 和 Stop 放在 runExpr 中不起作用)。
感谢您的帮助,马克。回复:如何防止 Run in Fit Model 生成报告?你是对的。 我尝试修改我的插图,但在创建“拟合最小二乘法”报告之前会评估附加到按钮框的脚本,因此它无效。
Names Default to Here( 1 );
run expr = Expr(
// desired report
personality = Report( fm )[ComboBox(1)] << Get Selected;
Show( personality );
// undesired report
window = Get Window List();
For( w = 1, w <= N Items( window ), w++,
If( Contains( window[w] << Get Window Title, "Fit Least Squares" ),
window[w] << Close Window;
Break();
);
);
);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
fm = dt << Fit Model(
Y( :weight ),
Effects( :age, :sex, :height ),
Personality( "Standard Least Squares" ),
Emphasis( "Minimal Report" )
);
Report( fm )[ButtonBox(9)] << Set Script( run expr );
// nothing after this point
回复:如何防止 Run in Fit Model 生成报告?马克,谢谢你,但我认为这不适合我的情况。用户需要填充“拟合模型”窗口。如果我将窗口组件添加到我的脚本中,它会在用户填充“拟合模型”窗口之前运行。因此,当用户单击“运行”时,脚本的该部分就会“消失”。请参阅我的帖子中的第二个脚本,以了解我按照您建议的方式提出的非常不优雅的解决方法。必须考虑用户填充“拟合模型”所需的时间,以及在“运行”按钮中运行脚本所需的时间。
回复:如何防止 Run in Fit Model 生成报告?我不知道如何修改附加到“运行”按钮框的脚本,但您可以随后找到并关闭该窗口。 参见此图:
fm = Current data Table() << Fit Model(
Y( :weight ),
Effects( :age, :sex, :height ),
Personality( "Standard Least Squares" ),
Emphasis( "Effect Leverage" )
);
fls = fm << Run;
window = Get Window List();
For( w = 1, w <= N Items( window ), w++,
If( Contains( window[w] << Get Window Title, "Fit Least Squares" ),
window[w] << Close Window;
Break();
);
);