I am defining the basic matrix:
1 2 3 4
5 6 7 8
As follows:
PROC IML;
RESET NOPRINT;
matrix = {1 2 3 4, 5 6 7 8};
EXIT:
I’m looking to resample each row with replacement so we generate matrices like:
1 3 4 2
6 6 5 5
and
1 1 3 2
5 6 6 8
How can this be done?
Note that if you’re not aligned with stats, to resample with replacement means if we have a set of data:
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
and wish to resample with replacement, we randomly pick 10 objects from the set to form a new 10-element set, and we’re allowed to pick an element more than once (so the set {1, 1, 1, 1, 1, 1, 1, 1, 1, 1} is just as likely as any other.
I’m not great with IML, but the most efficient approach would be to generate a new matrix that has in each row an integer in
1,...,kwherekis the number of variables (4 in your case). You can then use this matrix to reshuffle the elements of your existing matrix.This approach is shown in this blog post, except you’ll have to modify it to work on your whole matrix — in his code, the input is a row vector.