comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Random sample selection without replacement (using IMSL_RANDOM_SAMPLE)
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Random sample selection without replacement (using IMSL_RANDOM_SAMPLE) [message #78013] Fri, 21 October 2011 09:14 Go to previous message
Michael Galloy is currently offline  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
[Message index]
 
Read Message
Read Message
Previous Topic: Re: Clever Exception Handling?
Next Topic: REGION_GROW Syntax

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:59:57 PDT 2025

Total time taken to generate the page: 0.00421 seconds