创建具有 byVar 的统计自定义(公式)函数与我创建的愿望清单项目相关:添加归一化和稳健的统计函数(和矩阵函数) 。 我想我现在可以尝试将这些编写为自定义函数(尽管我知道不可能共享它们并为每个人更新它们),但我几乎立即遇到了我的第一个问题:如何引用列...... 使用自定义公式时,我坚持使用行级计算或将列引用为字符串而不是 :colname,这会阻止我直接从公式编辑器使用它们。
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
my_min = New Custom Function(
"custom",
"My Min1",
Function({x, y},
As Constant(
vals = Column(x) << get values;
groups = Column(y) << get values;
);
cur_group = Loc(groups, As Column(y));
vals[cur_group[Loc Min(vals[cur_group])]];
),
<< Formula Category("Statistical")
);
Add Custom Functions(my_min);
my_min = New Custom Function(
"custom",
"My Min2",
Function({x, y},
Col Minimum(Column(x), Column(y));
),
<< Formula Category("Statistical")
);
Add Custom Functions(my_min);
my_min = New Custom Function(
"custom",
"My Min3",
Function({x, y},
Col Minimum(x, y);
),
<< Formula Category("Statistical")
);
Add Custom Functions(my_min);
dt << New Column("ColMin", Numeric, Continuous, Formula(Col Minimum(:height, :sex)));
dt << New Column("MyMin1_str", Numeric, Continuous, Formula(custom:My Min1("height", "sex")));
dt << New Column("MyMin2_str", Numeric, Continuous, Formula(custom:My Min2("height", "sex")));
dt << New Column("MyMin3_str", Numeric, Continuous, Formula(custom:My Min3("height", "sex")));
dt << New Column("MyMin1_ref", Numeric, Continuous, Formula(custom:My Min1(:height, :sex)));
dt << New Column("MyMin2_ref", Numeric, Continuous, Formula(custom:My Min2(:height, :sex)));
dt << New Column("MyMin3_ref", Numeric, Continuous, Formula(custom:My Min3(:height, :sex)));数据混合和清理数据探索和可视化大规模定制回复:创建具有 byVar 的统计自定义(公式)函数我相信愿望清单项目会让这变得容易得多:
用于立即计算自定义列公式或缓存行之间的值的选项或函数
回复:创建具有 byVar 的统计自定义(公式)函数两条评论:
- 我似乎找不到对它的引用,但我确实记得有人明确告诉我,没有办法编写一个自定义列公式来像内部公式那样在行之间缓存其值。因此,您需要编写一个在每行上下文中进行计算的函数,这意味着它一次返回一个值。(如果可能的话,我希望有人能在这里纠正我。)
- JMP 在将列引用传递给函数之前对其进行评估(热切评估),这意味着您将获得该行的值而不是整个列的值。您需要告诉 JMP 传递对该列的引用,您可以使用 Expr 来完成此操作。
我相信这可以解决这两个问题,但我不确定它是否非常直观或用户友好。
更新:自定义函数可以访问行上下文,因此您可以跳过将当前行的值传递到函数中的需要,如 Test2 中所示。
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
my_min = New Custom Function(
"custom",
"Test1",
Function({x,y,yval},
show(yval);
show(Name Expr(x)<< get values);
show(Loc(Name Expr(y) << Get Values, yval));
Min((Name Expr(x)<< get values)[Loc(Name Expr(y) << Get Values, yval)]);
),
<< Formula Category("Statistical")
);
Add Custom Functions(my_min);
custom:Test1(Expr(:age),Expr(:sex),"F");
dt << New Column("Test1", Numeric, Continuous, Formula(custom:Test1(Expr(:height), Expr(:sex), :sex)));
my_min = New Custom Function(
"custom",
"Test2",
Function({x,y},
xvals = Name Expr(x)<< get values;
yvals = Name Expr(y) << Get Values;
Min(xvals[Loc(yvals, yvals[row()])]);
),
<< Formula Category("Statistical")
);
Add Custom Functions(my_min);
dt << New Column("Test2", Numeric, Continuous, Formula(custom:Test2(Expr(:height), Expr(:sex))));回复:创建具有 byVar 的统计自定义(公式)函数好点子!我非常专注于获取要评估的列引用,我什至没有注意到这些值是无意义的。我会再考虑一下。
回复:创建具有 byVar 的统计自定义(公式)函数这似乎没有提供正确的答案,因为它很可能“逐行”而不是按列评估它们

回复:创建具有 byVar 的统计自定义(公式)函数这是你想要的吗?如果您希望函数参数是列引用,那么您似乎需要显式评估它们。
my_min = New Custom Function(
"custom",
"My Min4",
Function({x, y},
EvalExpr(Col Minimum(Expr(x), Expr(y)));
),
<< Formula Category("Statistical")
);
Add Custom Functions(my_min);