Random number without duplicates/without replacement

Dear all,

I need to sample 20 households based on a household list. I was thinking I
could sample them using ODK and the household rank number. Hence, I was
looking for a way to generate 20 random numbers on ODK. I did the following
1+int(once(random())*${total number of households in the village}) but this
give me a random number with replacement and hence possibly with
duplicates. I am looking to a way to do the same without replacement. Any
idea?

Thanks

It's a bit tricky, but can be done. Attached is a SurveyCTO sample form
that demonstrates all of the mechanics. I don't believe that it uses any
SurveyCTO-specific functions, but please note that it's very sensitive to
the dynamics of repeat-group creation and calculation evaluation; it could
be that SurveyCTO's JavaRosa engine differs enough from ODK's that this
form doesn't work well on ODK Collect. So please test it thoroughly before
relying on it.

Best,

Chris

P.S. Sorry, looking at it now, I see that it does use "index()", which can
be changed to "position(..)" for ODK. But then it also uses the
de-duplicate() function, and I don't know that ODK has that. If not, we're
happy to contribute it. Perhaps you'll be inspired by the approach, though,
and you can find a pure-ODK way to accomplish the same goal. The trick is
to keep drawing as many draws as you need to get x unique ones. It is a
common need for SurveyCTO users, and probably for many ODK users more
broadly. So would be great to have a working example here in this forum..!

Sample Form - Random draws without duplicates.xlsx (69.5 KB)

··· --- Christopher Robert Dobility, Inc. (SurveyCTO) http://www.surveycto.com/ http://blog.surveycto.com/

On Wed, Dec 7, 2016 at 9:00 AM, Bouguen Adrien adbouguen@gmail.com wrote:

Dear all,

I need to sample 20 households based on a household list. I was thinking I
could sample them using ODK and the household rank number. Hence, I was
looking for a way to generate 20 random numbers on ODK. I did the following
1+int(once(random())*${total number of households in the village}) but this
give me a random number with replacement and hence possibly with
duplicates. I am looking to a way to do the same without replacement. Any
idea?

Thanks

--

Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en


You received this message because you are subscribed to the Google Groups
"ODK Community" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

I tried the example provided by Chris Robert and, as suspected, Collect (1.4.12) did not like the function 'de-duplicate()'. This would be a great contribution as I've run into this problem as well.

Best,

Chris Corey

We're working on contributing that and other extended functions just now.
Stay tuned. And sorry that it didn't work out of the box. I hope that the
technique might still inspire a related solution that doesn't require
de-duplicate for now.

Best,

Chris

··· --- Christopher Robert Dobility, Inc. (SurveyCTO) http://www.surveycto.com/ http://blog.surveycto.com/sneak-peek-surveycto-2-20- supercharges-data-visibility/

On Wed, Dec 7, 2016 at 2:18 PM, mydogpearls@gmail.com wrote:

I tried the example provided by Chris Robert and, as suspected, Collect
(1.4.12) did not like the function 'de-duplicate()'. This would be a great
contribution as I've run into this problem as well.

Best,

Chris Corey

--

Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en


You received this message because you are subscribed to the Google Groups
"ODK Community" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

And for those who want to track progress on this issue, it's been filed at
https://github.com/opendatakit/collect/issues/292.

Yaw

··· On Fri, Dec 9, 2016 at 12:32 PM, Christopher Robert wrote:

We're working on contributing that and other extended functions just now.
Stay tuned. And sorry that it didn't work out of the box. I hope that the
technique might still inspire a related solution that doesn't require
de-duplicate for now.

Best,

Chris


Christopher Robert
Dobility, Inc. (SurveyCTO)
http://www.surveycto.com/
http://blog.surveycto.com/sneak-peek-surveycto-2-20-supercha
rges-data-visibility/

On Wed, Dec 7, 2016 at 2:18 PM, mydogpearls@gmail.com wrote:

I tried the example provided by Chris Robert and, as suspected, Collect
(1.4.12) did not like the function 'de-duplicate()'. This would be a great
contribution as I've run into this problem as well.

Best,

Chris Corey

--

Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en


You received this message because you are subscribed to the Google Groups
"ODK Community" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--

Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en


You received this message because you are subscribed to the Google Groups
"ODK Community" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.