你好。 我在修改 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.
我被告知這通常不被認為是“良好實踐”(將整個命令放在引號中),但是嗯......它有效。