在第一列中,我模拟一个随机变量来创建一个总体(例如,具有正态分布的 10000 条线)。
然后,我想在另一列中获取一个大小为 n 的随机样本,该样本是固定的,并从上一列创建的总体中提取的。最好的方法是同时在并列的列中获取多个样本。
仅供参考,我只发现 JMP 几个星期(我已经使用 Minitab 多年了),除了在创建图表时进行抽样外,我还没有找到自己的解决方案。
先感谢您。
有多种方法可以做到这一点。
最简单的方法是使用 Subset 平台的内置功能
表=>子集
给定一个包含 1000 行数据的表

表格=>子集允许您创建给定百分比或给定样本大小的随机样本

这将为你提供一个包含 100 行的新表

然后就可以简单地使用以下方法将该表与原始表连接起来
表=>连接

这将满足您的要求

这种方法的主要问题是它在某种程度上违反了 JMP 数据表的假设。
另一种方法是使用列公式。我想出的公式会生成一个随机样本,但它不会将选定的数据放入前 100 行,而是将值放入选定数据所在的行。
公式如下
As Constant(
rowCount = N Rows( Current Data Table() );
sampleMatrix = [];
For( i = 1, i <= 100, i++,
found = 0;
While( found == 0,
row = Random Integer( 1, rowCount );
If( N Rows( Loc( sampleMatrix, row ) ) == 0,
found = 1;
sampleMatrix = sampleMatrix || Matrix( row );
);
);
);
);
If( N Cols( Loc( sampleMatrix, Row() ) ) != 0,
:Column 1,
.
);
产生

现在,如果将样本生成移至 JSL,那么创建所需数量的样本将变得相当容易
Names Default To Here( 1 );
dt = Current Data Table();
rowCount = N Rows( dt );
// Create 5 Random Samples of 100
For( k = 1, k <= 5, k++,
dt << New Column( "Random" || Char( k ) );
sampleMatrix = [];
For( i = 1, i <= 100, i++,
found = 0;
While( found == 0,
row = Random Integer( 1, rowCount );
If( N Rows( Loc( sampleMatrix, row ) ) == 0,
found = 1;
sampleMatrix = sampleMatrix || Matrix( row );
);
);
);
// Write the values to the new column
For Each( {row}, sampleMatrix,
Column( "Random" || Char( k ) )[row] = :Column 1[row]
);
);
这创造了

稍加修改,随机样本生成就可以采用无放回抽样
Names Default To Here( 1 );
dt = Current Data Table();
rowCount = N Rows( dt );
masterSampleMatrix = [];
// Create 5 Random Samples of 100
For( k = 1, k <= 5, k++,
dt << New Column( "Random" || Char( k ) );
sampleMatrix = [];
For( i = 1, i <= 100, i++,
found = 0;
While( found == 0,
row = Random Integer( 1, rowCount );
If( N Rows( Loc( masterSampleMatrix, row ) ) == 0,
found = 1;
sampleMatrix = sampleMatrix || Matrix( row );
masterSampleMatrix = masterSampleMatrix || Matrix( row );
);
);
);
// Write the values to the new column
For Each( {row}, sampleMatrix,
Column( "Random" || Char( k ) )[row] = :Column 1[row]
);
);
