这里有几种方法可以做到这一点。但由于下面的示例实际上仅基于 JMP 的主要功能,因此我强烈建议您阅读 JMP 文档库中的发现 JMP 和使用 JMP 文档,这些文档位于“帮助”下拉菜单下。
Names Default To Here( 1 );
dt = Current Data Table();
dt << New Column( "Score Category",
character,
formula(
If(
:Score < .6, "0.50-0.59",
:Score < .8, "0.60-0.79",
:Score < .9, "0.80-0.89",
"0.90-1.00",
)
)
);
dtSum = dt << Summary(
Group( :Group, :Score Category ),
Sum( :Count ),
Freq( "None" ),
Weight( "None" ),
Link to original data table( 0 )
);
dtSum << delete columns( :N Rows );
dtSum:Name( "Sum(Count)" ) << set name( "Total_Count" );
// or
dt:score << set property(
"value labels",
{0.5 <= "0.50-0.59" < 0.6, 0.6 <= "0.60-0.79" < 0.8, 0.8 <= "0.80-0.89" < 0.9, 0.9
<= "0.90-1.00" <= 1}
);
dtSum = dt << Summary(
Group( :Group, :Score ),
Sum( :Count ),
Freq( "None" ),
Weight( "None" ),
Link to original data table( 0 )
);
dtSum << delete columns( :N Rows );
dtSum:Name( "Sum(Count)" ) << set name( "Total_Count" );我将使用交互式方法来捕获此脚本。 首先我们从数据表开始:

我把 Count 去掉了,因为我们不需要它,但如果它在那里也没什么坏处。
我选择了“分数”列,然后导航到“列”、“实用程序”、“创建分箱公式”:

并将 Offset 设置为 0.5,bin width 设置为 0.1:

右键单击新列(分箱得分)并复制列属性:

然后打开一个新的脚本窗口并粘贴 (ctrl-V),这会生成以下 JSL:
Add Column Properties(
Value Labels(
{-0.5 = "-0.5 — -0.4", -0.4 = "-0.4 — -0.3", -0.3 = "-0.3 — -0.2", -0.2 =
"-0.2 — -0.1", -0.1 = "-0.1 — 0", 0 = "0 — 0.1", 0.1 = "0.1 — 0.2", 0.2 =
"0.2 — 0.3", 0.3 = "0.3 — 0.4", 0.4 = "0.4 — 0.5", 0.5 = "0.5 — 0.6", 0.6 =
"0.6 — 0.7", 0.7 = "0.7 — 0.8", 0.8 = "0.8 — 0.9", 0.9 = "0.9 — 1", 1 =
"1 — 1.1", 1.1 = "1.1 — 1.2", 1.2 = "1.2 — 1.3", 1.3 = "1.3 — 1.4", 1.4 =
"1.4 — 1.5", 1.5 = "1.5 — 1.6", 1.6 = "1.6 — 1.7", 1.7 = "1.7 — 1.8", 1.8 =
"1.8 — 1.9", 1.9 = "1.9 — 2"}
),
Use Value Labels( 1 ),
Formula( 0.5 + 0.1 * Floor( (:Score - 0.5) / 0.1 ) )
)这里有两件事:我们不关心任何小于 0.5 的分数(它们在您的描述中不存在)或大于 1,因此我们可以稍微更改属性并编辑标签名称以匹配您想要的。 我还添加了一个 If 语句来捕获分数恰好为 1 的边缘情况
Add Column Properties(
Value Labels(
{0.5 = "0.5 — 0.59", 0.6 = "0.6 — 0.69", 0.7 = "0.7 — 0.79", 0.8 = "0.8 — 0.89", 0.9 =
"0.9 — 1"}
),
Use Value Labels( 1 ),
Formula(
If(
(0.5 + 0.1 * Floor( (:Score - 0.5) / 0.1 )) == 1, 0.9,
0.5 + 0.1 * Floor( (:Score - 0.5) / 0.1 )
)
)
);(顺便说一句,这些标签在技术上并不准确,因为 0.599 将被标记为 0.5 到 0.59 之间)
我们可以围绕此代码片段包装一些代码以使其可重用,其中我们使用当前数据表,添加一个名为 Score Binned 的新列,并将这些属性添加到该列:
dt = Current Data Table();
dt << New Column("Score Binned", Character);
dt:"Score Binned"n << Add Column Properties(
Value Labels(
{0.5 = "0.5 — 0.59", 0.6 = "0.6 — 0.69", 0.7 = "0.7 — 0.79", 0.8 = "0.8 — 0.89", 0.9 =
"0.9 — 1"}
),
Use Value Labels( 1 ),
Formula(
If(
(0.5 + 0.1 * Floor( (:Score - 0.5) / 0.1 )) == 1, 0.9,
0.5 + 0.1 * Floor( (:Score - 0.5) / 0.1 )
)
)
);现在,回到我们的表格,“表格”>“摘要”将我们带到我们想去的地方。 我们将 Group 和 Score Binned 放在 Group 中,这就是我们实际需要的:


现在,N Rows 就是我们想要的,它只是命名错误,所以让我们双击左侧的“Source”一词并复制表创建脚本,并将命名表引用替换为我们的工作表“dt”,并在变量“summ”中捕获新表:

dt = Current Data Table();
dt << New Column("Score Binned", Character);
dt:"Score Binned"n << Add Column Properties(
Value Labels(
{0.5 = "0.5 — 0.59", 0.6 = "0.6 — 0.69", 0.7 = "0.7 — 0.79", 0.8 = "0.8 — 0.89", 0.9 =
"0.9 — 1"}
),
Use Value Labels( 1 ),
Formula(
If(
(0.5 + 0.1 * Floor( (:Score - 0.5) / 0.1 )) == 1, 0.9,
0.5 + 0.1 * Floor( (:Score - 0.5) / 0.1 )
)
)
);
summ = dt << Summary(
Group( :Group, :Score Binned ),
Freq( "None" ),
Weight( "None" )
);最后,根据需要将 N Rows 重命名为“Total_Count”:
dt = Current Data Table();
dt << New Column("Score Binned", Character);
dt:"Score Binned"n << Add Column Properties(
Value Labels(
{0.5 = "0.5 — 0.59", 0.6 = "0.6 — 0.69", 0.7 = "0.7 — 0.79", 0.8 = "0.8 — 0.89", 0.9 =
"0.9 — 1"}
),
Use Value Labels( 1 ),
Formula(
If(
(0.5 + 0.1 * Floor( (:Score - 0.5) / 0.1 )) == 1, 0.9,
0.5 + 0.1 * Floor( (:Score - 0.5) / 0.1 )
)
)
);
summ = dt << Summary(
Group( :Group, :Score Binned ),
Freq( "None" ),
Weight( "None" )
);
summ:"N Rows"n << Set Name("Total_Count");现在,关闭汇总表,从源表中删除 Score Binned 列,然后测试脚本:

最后的 JSL 再次:
dt = Current Data Table();
dt << New Column("Score Binned", Character);
dt:"Score Binned"n << Add Column Properties(
Value Labels(
{0.5 = "0.5 — 0.59", 0.6 = "0.6 — 0.69", 0.7 = "0.7 — 0.79", 0.8 = "0.8 — 0.89", 0.9 =
"0.9 — 1"}
),
Use Value Labels( 1 ),
Formula(
If(
(0.5 + 0.1 * Floor( (:Score - 0.5) / 0.1 )) == 1, 0.9,
0.5 + 0.1 * Floor( (:Score - 0.5) / 0.1 )
)
)
);
summ = dt << Summary(
Group( :Group, :Score Binned ),
Freq( "None" ),
Weight( "None" )
);
summ:"N Rows"n << Set Name("Total_Count");对您附加的数据进行了测试,我确实注意到了:flushed_face:
