为分类变量的所有级别编写相同的输出脚本你好,
我有一个脚本,它可以执行一些计算、运行一些平台并提取特定输出,然后在新的窗口中创建一个选项卡框。我希望针对用户在对话框中指定的某个分类变量的每个级别执行所有这些操作。
目前,我根据分组变量创建数据的各个子集,然后遍历每个数据集:
dtSubset = dt << Subset( By( Eval( groupVar ) ), Linked, Selected Columns Only( 0 ), All Rows( 1 ), Invisible );
For( i = 1, i <= N Items( unique_groups ), i++,
dt_i = dtSubset[i];
...some code to do stuff
<BR />...append output as a new tab box in my window
);
Essentially all I am doing is coding up my own analysis and wanting a 'By' variable. I am wondering if there is a better or more efficient way to go about this? The main thing I want with the code is to have the output I create be specific for each level, while also still maintaining a connection to the original data table (meaning the plots in my output are interactive still).
如您所见,我将子集创建为不可见的,然后在我的代码中,在每次循环迭代结束时关闭它们。
谢谢,
罗伯特
自动化和脚本编写回复:为分类变量的所有级别编写相同的输出脚本平台内不使用 By 变量的原因是什么?
回复:为分类变量的所有级别编写相同的输出脚本这里提供了三种使用分组列从数据表创建选项卡框的方法。如果您使用的是 JMP18 或更高版本(我认为),最后一种方法无疑是最简单的。
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
// Using subsets
dt_subsets = dt << Subset(
By(:age),
Linked,
Selected Columns Only(0),
All Rows(1),
Invisible
);
nw = New Window("Subsets",
tb = tab box()
);
dists = {};
For Each({dt_subset}, dt_subsets,
tb << Insert(Tab Page Box(Title(dt_subset << get name),
dt_subset << Distribution(
Continuous Distribution(Column(:weight)),
Nominal Distribution(Column(:age))
);
));
);
tb << Set Selected(1);
// Using Where in platform
nw = New Window("Where",
tb = tab box()
);
groups = Associative Array(Column(dt, "age")) << get keys;
dists = {};
For Each({group}, groups,
tb << Insert(Tab Page Box(Title("age=" || Char(group)),
dist = dt << Distribution(
Continuous Distribution(Column(:weight)),
Nominal Distribution(Column(:age)),
Where(:age == group)
);
));
(Report(dist) << Top Parent)[TextBox(1)] << Visibility("Collapse"); // to hide Where(... textbox
);
tb << Set Selected(1);
// Using By in platform
dist = dt << Distribution(
Group Options(Layout("Arrange in Tabs")),
Continuous Distribution(Column(:weight)),
Nominal Distribution(Column(:age)),
By(:age)
);
回复:为分类变量的所有级别编写相同的输出脚本在 Jarmo 的“按组”示例的基础上,这里提供一个创建输出中所示的选项卡窗口的示例。
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
// Using By in platform
dist = dt << Distribution(Invisible,
Group Options(Layout("Arrange in Tabs")),
Continuous Distribution(Column(:weight)),
Nominal Distribution(Column(:age)),
By(:age)
);
// Create a new window and add tabs for each age
nw = New Window( "Tabs",
tabb = Tab Box();
);
For( i = 1, i <= N Items( dist ), i++,
display = Report( dist[i] );
theByGroup = display[Outline Box( 1 )] << get title;
tabb << append( Tab Page Box( Title( theByGroup ), display ) );
);

回复:为分类变量的所有级别编写相同的输出脚本主要原因是,我发现遍历变量的不同层级并逐个构建标签页窗口,然后再进行追加操作,这样更简单。因为对于每个层级,我都需要进行表格计算、使用图形生成器构建图形、从 Dist 平台提取 QQ 图、从拟合模型平台提取学生化残差图等等。
回复:为分类变量的所有级别编写相同的输出脚本感谢二位的建议,提供的代码运行良好。我需要补充一点,我正在开发一个相当复杂的插件,它会从许多不同的平台提取数据,并生成一些新的输出。我真正想要的是确保通常与数据表关联的图表保持这种关联。我还希望每个标签页看起来都完全一样,所以循环似乎是个简单的解决方案。
您认为最好的方法是在所有我使用的平台上都使用“按”选项,然后遍历我的变量的各个级别,使用不同的路径调用每个组件,并将它们附加到我想要的位置吗?
回复:为分类变量的所有级别编写相同的输出脚本如果像 Jim 演示的那样将它们附加在一起,最终会失去交互性。子集/Where 子句都很好用,但在某些情况下,你无法轻松地使用 Where 子句,例如创建汇总表(它使用本地数据筛选器而不是简单的 Where 子句)。而且,使用子集可能会导致生成大量数据表,因为它们可能不会像你预期的那样关闭(在关闭主表时)。有时,使用本地数据筛选器也值得考虑,因为你可以使用数据筛选上下文框在多个平台上使用同一个筛选器。