557067_zh-TW
添加響應本地數據過濾器更改的匯總統計圖參考線
創建一個帶有數據平均值參考線的運行圖。 添加本地數據過濾器並在選擇類別時更改平均值。 具有平均榮譽排除行。
腳步:- 啟動腳本名稱默認為此處(1);
- 打開大班樣本數據表並提供參考dt .
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
- 隨機排除一些行。
dt << select randomly(sampling rate(0.2)) << exclude << clear select;
- 使用 Graph Builder 創建圖形並提供參考國標.
gb = Graph Builder(
Size( 621, 472 ),
Variables( Y( :height ) ),
Elements( Line( Y, Legend( 3 ), Row order( 1 ) ) ),
);
- 添加本地數據過濾器並給它一個參考df .
df = gb << local data filter(add filter(columns(:sex)));
- 這製作過濾器更改處理程序(f)發送給數據過濾器對象的消息將評估用戶函數參數F每次更改數據過濾器時。 創建函數以刪除參考線(如果存在),找到由本地數據過濾器選擇且未被排除的行的響應平均值,然後在 Y 軸的響應平均值處添加參考線行。 然後將消息發送到數據過濾器。
//user function to be called when filter is changed
f = function({a}, //a is not used
//remove the y axis reference line, if it exists
try(report(gb)[axisbox(2)] << remove ref line(meanHeight));
//get the where clause from the data filter
//it will look like Select Where(...)
txt = df << get where clause;
//get the argument, if it exists
arg = if(length(txt), arg(parse(txt), 1), txt);
//get row numbers of filtered rows
aaDf = if(length(txt),
associative array(dt << get rows where(arg)),
index(1, nrow(dt))
);
//find row numbers of non-excluded rows
vecEx = dt << select excluded
<< invert row selection
<< get selected rows
<< clear select;
aaEx = associative array(vecEx);
//get row numbers of both
aaEx << intersect(aaDf);
lstAll = aaEx << get keys;
//find the mean of filtered/non-excluded response
//if nothing is filtered, find the mean of non-excluded only
meanHeight = if(length(txt),
mean(column(dt, "height")[lstAll]),
mean(column(dt, "height")[aaEx << get keys])
);
//add reference line
report(gb)[axisbox(2)] << add ref line(meanHeight, "Solid", 19, 2);
);
rs = df << make filter change handler(f);
成功的提示
- 以交互方式創建 Graph Builder 和 Data Filter 對象,然後使用 Save script > to Script Window 或使用 Enhanced Log 複製它們的腳本。
- 使用腳本索引來了解數據過濾器等對象可以響應的消息。 運行示例以查看它們是如何工作的。 例如,在用戶函數 f 的參數 a 中返回了什麼?
- 從小處著手。 此示例是在未考慮排除行的情況下構建的。 僅在創建腳本後,才在包含排除行的表上進行了嘗試。 之後添加了具有排除行的表的特殊情況。 之後還添加了過濾器中未選擇的其他特殊情況。
自動化和腳本主修課
Comments
There are no comments yet