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?
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..!
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?
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.
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/
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.
···
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.
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.