Re: Random sample selection without replacement (using IMSL_RANDOM_SAMPLE) [message #78013] |
Fri, 21 October 2011 09:14  |
Michael Galloy
Messages: 1114 Registered: April 2006
|
Senior Member |
|
|
On 10/21/11 3:59 AM, Patrick Leinenkugel wrote:
> Hello,
> I like to generate a random selection (eg. 5 samples) of a population
> without replacement from a one dimensional array with n samples (eg.
> n=100). I tried to use the IMSL_RANDOM_SAMPLE function which works
> fine if I have (k,n) dimensional arrays (k variables (e.g k=2), n
> samples( e.g n=100)).
> For one dimensional arrays, however, the command
>
> samp = IMSL_RANDOM_SAMPLE(5, pop)
>
> results in the error message: "IMSL Error: IMSL_RANDOM_SAMPLE:
> Terminal error: STAT_BAD_NROW_NSAMP: NROW = 1 and NSAMP = 5. Since
> there is only one invocation of this function, NROW must be greater
> than or equal to nsamp."
>
> Can anyone tell me what I do wrong or has a nother way to easily
> generate random selection without replacement.
> Thanks,
> Patrick
I use my own routine, MG_SAMPLE. Here is the code:
http://docs.idldev.com/idllib/analysis/mg_sample.pro
Docs here:
http://docs.idldev.com/idllib/analysis/mg_sample.html
It works by creating a random array of size n and finding the indices of
the smallest k elements (using a HISTOGRAM approach instead of SORTing
the entire array).
Mike
--
Michael Galloy
www.michaelgalloy.com
Modern IDL, A Guide to Learning IDL: http://modernidl.idldev.com
Research Mathematician
Tech-X Corporation
|
|
|
Re: Random sample selection without replacement (using IMSL_RANDOM_SAMPLE) [message #78089 is a reply to message #78013] |
Sun, 23 October 2011 23:40  |
Patrick Leinenkugel
Messages: 5 Registered: June 2011
|
Junior Member |
|
|
On 21 Okt., 18:14, Michael Galloy <mgal...@gmail.com> wrote:
> On 10/21/11 3:59 AM, Patrick Leinenkugel wrote:
>
>
>
>
>
>
>
>
>
>> Hello,
>> I like to generate a random selection (eg. 5 samples) of a population
>> without replacement from a one dimensional array with n samples (eg.
>> n=100). I tried to use the IMSL_RANDOM_SAMPLE function which works
>> fine if I have (k,n) dimensional arrays (k variables (e.g k=2), n
>> samples( e.g n=100)).
>> For one dimensional arrays, however, the command
>
>> samp = IMSL_RANDOM_SAMPLE(5, pop)
>
>> results in the error message: "IMSL Error: IMSL_RANDOM_SAMPLE:
>> Terminal error: STAT_BAD_NROW_NSAMP: NROW = 1 and NSAMP = 5. Since
>> there is only one invocation of this function, NROW must be greater
>> than or equal to nsamp."
>
>> Can anyone tell me what I do wrong or has a nother way to easily
>> generate random selection without replacement.
>> Thanks,
>> Patrick
>
> I use my own routine, MG_SAMPLE. Here is the code:
>
> http://docs.idldev.com/idllib/analysis/mg_sample.pro
>
> Docs here:
>
> http://docs.idldev.com/idllib/analysis/mg_sample.html
>
> It works by creating a random array of size n and finding the indices of
> the smallest k elements (using a HISTOGRAM approach instead of SORTing
> the entire array).
>
> Mike
> --
> Michael Galloywww.michaelgalloy.com
> Modern IDL, A Guide to Learning IDL:http://modernidl.idldev.com
> Research Mathematician
> Tech-X Corporation
Thank you very much Mike!
|
|
|