- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
How to sample a column?
In a first column I simulate a random variable to create a population (for example, 10000 lines with a normal distribution).
Then, I would like, in another column, to obtain a random sample of size n to be fixed and extracted from the population created in the previous column. The best would be to obtain several samples simultaneously in juxtaposed columns.
FYI, I've only been discovering JMP for a few weeks (I've been working with Minitab for years), I haven't found the solution on my own, except for sampling when creating a graph.
Thank you in advance.
This post originally written in French and has been translated for your convenience. When you reply, it will also be translated back to French .
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Comment échantillonner une colonne ?
There are multiple ways to do this.
The simplest is to use the built in capability of the Subset platform
Tables=>Subset
Given a table with a column of data with 1000 rows
The Tables=>Subset allow you to create a random sample of either a given percentage or a given sample size
Which will give you a new table with 100 rows
it is then a simple matter to join this table with the original table using
Tables=>Join
Which will give you what you asked for
The main problem with this approach is that it is somewhat violating the assumptions of a JMP data table.
Another approach would be to use a column formula. The formula I came up with produces a random sample, but rather than placing the selected data into the first 100 rows, it places the values in the row the selected data comes from.
Here is the formula
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,
.
);
Which produces
Now if one moves the sample generation to JSL, it becomes a fairly easy task to create as many samples as needed
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]
);
);
Which creates
With a little modification, the random sample generation can be sampling without replacement
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]
);
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Comment échantillonner une colonne ?
There are multiple ways to do this.
The simplest is to use the built in capability of the Subset platform
Tables=>Subset
Given a table with a column of data with 1000 rows
The Tables=>Subset allow you to create a random sample of either a given percentage or a given sample size
Which will give you a new table with 100 rows
it is then a simple matter to join this table with the original table using
Tables=>Join
Which will give you what you asked for
The main problem with this approach is that it is somewhat violating the assumptions of a JMP data table.
Another approach would be to use a column formula. The formula I came up with produces a random sample, but rather than placing the selected data into the first 100 rows, it places the values in the row the selected data comes from.
Here is the formula
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,
.
);
Which produces
Now if one moves the sample generation to JSL, it becomes a fairly easy task to create as many samples as needed
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]
);
);
Which creates
With a little modification, the random sample generation can be sampling without replacement
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]
);
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How to sample a column?
Thank you so much.
JL
This post originally written in French and has been translated for your convenience. When you reply, it will also be translated back to French .