557067_zh-CN
添加响应本地数据过滤器更改的汇总统计图参考线
创建一个带有数据平均值参考线的运行图。 添加本地数据过滤器并在选择类别时更改平均值。 具有平均荣誉排除行。
脚步:- 启动脚本名称默认为此处(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