你好。 我在修改 JSL 中的某些分布平台选项时遇到一些问题(例如离群值箱线图、正态分位数图等)。 我正在编写一个脚本,允许用户为任意列列表创建分布。 此外,我想让用户能够指定是否为所有图启用离群值箱线图或正态分位数图。 虽然遇到了一些问题,希望有人能提供一些见解。
郑重声明,我在 Mac 上运行 JMP Pro 14.3.0。
首先我尝试了这个:
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
tcol_lis = {"height", "weight"};
//First approach
nqplopt = 1; //This is meant to turn on the Normal Quantile Plot option
Distribution(
Column(EvalList(tcol_lis)),
Normal Quantile Plot(nqplopt),
);
nqplopt = 0; //But it has no effect
Distribution(
Column(EvalList(tcol_lis)),
Normal Quantile Plot(nqplopt),
);看起来应该有效,但是将“nqplopt”设置为 1 或 0 没有效果。 就我而言,分位数图是两次生成的。 有趣的是,因为这个选项在我的偏好中是关闭的。
接下来,我尝试在创建后向发行版发送消息。
//Second approach - send the Normal Quantile option as a message
nqplopt = 1;
dist = Distribution(
Column(EvalList(tcol_lis))
);
dist << Normal Quantile Plot(nqplopt);
nqplopt = 0;
dist = Distribution(
Column(EvalList(tcol_lis))
);
dist << Normal Quantile Plot(nqplopt); //No difference from when nqplopt = 1
和以前一样,当 nqplopt 为 1 或 0 时没有区别。我怀疑这对我是否有效,因为对象“dist”指的是多个发行版,并且我不确定 JSL 将如何处理向其发送消息。
最后,我转到我的首选解决方案,使用 JSL Quote 强制进行我想要的替换:
//Third approach - make substitutions via JSL Quote
nqplopt = 0;
dist_jst = JSL Quote(
Distribution(
Column(EvalList(tcol_lis)),
Normal Quantile Plot(nqplopt_ph),
);
);
SubstituteInto(dist_jst,
Expr(nqplopt_ph), nqplopt
);
Show(dist_jst); //The "nqplopt_ph" remains unchanged for some reason.
Eval(Parse(dist_jst)); //Dist. created with a Normal Quantile Plot, as if nqplopt = 1
不过,就像失业的荷官一样,没有骰子。 当我显示修改后的 dist_jst 字符串时,就好像从未发出 SubstituteInto 命令一样。 我很好奇这是为什么? 我以前多次使用过JSL Quote,但我不明白为什么它似乎无法进行此修改?
有什么想法或解决方法吗?
@尼克尔斯,
恭喜您找到适合您的解决方案。下面是一个替代方案。
EvalExpr() 将每个 Expr(变量) 替换为它的值,并返回一个包含值的表达式。因此,Eval( EvalExpr() ) 用值替换变量并运行结果表达式。注意我添加并注释掉了忽略平台首选项(1)。 如果用户与脚本编写者具有不同的首选项,则报告可能会有所不同。 忽略平台首选项(1) 会关闭此分析的所有首选项,因此脚本编写者必须指定所有应可见的首选项。但是,它确保用户将看到与其他用户相同的分析。
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
tcol_lis = {"height", "weight"};
//First approach
nqplopt = 1; //This is meant to turn on the Normal Quantile Plot option
Eval(EvalExpr(Distribution( //Ignore Platform Preferences(1),
Column( EvalList(tcol_lis)),
Normal Quantile Plot(nqplopt),
)));
nqplopt = 0; //But it has no effect
Eval( Eval Expr(Distribution(//Ignore Platform Preferences(1),
Column(EvalList(tcol_lis)),
Normal Quantile Plot(Expr(nqplopt)),
)) );
嗯...我可能已经找到了我自己问题的答案。 我仍然很好奇为什么 JSL Quote 路由不起作用,但我采用的解决方案是使用文字引用字符串。 如图所示:
//Fourth approach - make substitutions via a literal string quote
nqplopt = 0;
dist_str =
"Distribution(
Column(EvalList(tcol_lis)),
Normal Quantile Plot(nqplopt_ph),
)";
SubstituteInto(dist_str,
"nqplopt_ph", Char(nqplopt)
);
Show(dist_str); //The "nqplopt_ph" is successfully changed to 0.
Eval(Parse(dist_jst)); //Finally, it works.
我被告知这通常不被认为是“良好实践”(将整个命令放在引号中),但是嗯......它有效。