Select randomly a member

Hi,
I have to select randomly a member in a household survey. fisrt of all, I Ask
for basic demographics in a repeat group.

begin repeat member roster calculate CR360 Member ID number text CR361 Member's
Name select_one gender CR371 Member's gender integer CR381 Member's age
date CR391 Date of birth end repeat member

Then have a series of calculated field that produce a space-separated list
of the indices into that repeat group that are within the designated age
range.
calculate ageok1 if(/data/member[1]/CR381 >= 5 and /data/member[1]/CR381
<= 15, ' 1', '') calculate ageok2 if(/data/member[2]/CR381 >= 5 and
/data/member[2]/CR381 <= 15, ' 2', '') calculate ageok3 if(/data/member[3]/CR381

= 5 and /data/member[3]/CR381 <= 15, ' 3', '') calculate ageok4 if(/data/member[4]/CR381
= 5 and /data/member[4]/CR381 <= 15, ' 4', '') calculate ageok5 if(/data/member[5]/CR381
= 5 and /data/member[5]/CR381 <= 15, ' 5', '') calculate membersinrange
substr(concat(${ageok1},${ageok2},${ageok3},${ageok4},${ageok5}),1)

And this function once to compute the chosen member once. But in my
program , the note1 display nothing and the member chosen is 0. Can
somebody help me?
note note1 ${membersinrange} calculate chosenmember once(if(count-selected(/data/membersinrange)
= 0, 0, int(1.0+count-selected(/data/membersinrange)*random()))) note Child child's
name is ${chosenmember}

HI MITCH,
Please can you tell me what wrong with my program? Sure,i forget something
important, byt idon't identify it.

thanks a lot

··· 2014-07-13 10:09 GMT-04:00 Legarraudien :

Hi,
I have to select randomly a member in a household survey. fisrt of all, I Ask
for basic demographics in a repeat group.

begin repeat member roster calculate CR360 Member ID number text CR361 Member's
Name select_one gender CR371 Member's gender integer CR381 Member's age
date CR391 Date of birth end repeat member

Then have a series of calculated field that produce a space-separated list
of the indices into that repeat group that are within the designated age
range.
calculate ageok1 if(/data/member[1]/CR381 >= 5 and
/data/member[1]/CR381 <= 15, ' 1', '') calculate ageok2 if(/data/member[2]/CR381

= 5 and /data/member[2]/CR381 <= 15, ' 2', '') calculate ageok3 if(/data/member[3]/CR381
= 5 and /data/member[3]/CR381 <= 15, ' 3', '') calculate ageok4 if(/data/member[4]/CR381
= 5 and /data/member[4]/CR381 <= 15, ' 4', '') calculate ageok5 if(/data/member[5]/CR381
= 5 and /data/member[5]/CR381 <= 15, ' 5', '') calculate membersinrange
substr(concat(${ageok1},${ageok2},${ageok3},${ageok4},${ageok5}),1)

And this function once to compute the chosen member once. But in my
program , the note1 display nothing and the member chosen is 0. Can
somebody help me?
note note1 ${membersinrange} calculate chosenmember once(if(count-selected(/data/membersinrange)
= 0, 0, int(1.0+count-selected(/data/membersinrange)*random()))) note
Child child's name is ${chosenmember}

--

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.

Dear Mitch, I have a problem that relates to this thread. I am trying to create a form that generates a random number which the enumerator will use to select a household from x number of Households they see in front of them.

I'm trying to create this without the random number changing after saving the form, the random number also has to be an integer for which i used the 'round()' function and added +1 so that '0' is not returned, and also so the last household has a chance of being selected. To generate the random number I used a decimal field with calculation 'once(random())', and default value 'random()'. This may not be the best way I realize, but it stops the numbers from recalculating ones the form is saved.

The closest I have come is in the attached file. However there are two problems I still have:

  1. The random value returned is sometimes higher than the number of households entered (due to the +1).

  2. The 'random_value' field (used to generate default random value) needs to be 'readonly' or hidden completely if possible?

I would really appreciate your help as I have been stuck on this for a while.

Thanking you in advance,

Henri

random13.xlsx (35.1 KB)

Hi Pierre,

Please note that Mitch (and really everyone else on this list) provides
free support in their spare time.

If you can't wait for a response, then I encourage you to hire one of the
many ODK companies available at http://opendatakit.org/help/help-for-hire/

Thanks,

Yaw

··· -- Need ODK services? http://nafundi.com provides form design, server setup, professional support, and software development for ODK.

On Mon, Jul 14, 2014 at 11:35 AM, Pierre Anthony Garraud < pagarraud1@gmail.com> wrote:

HI MITCH,
Please can you tell me what wrong with my program? Sure,i forget something
important, byt idon't identify it.

thanks a lot

2014-07-13 10:09 GMT-04:00 Legarraudien pagarraud1@gmail.com:

Hi,

I have to select randomly a member in a household survey. fisrt of all,
I Ask for basic demographics in a repeat group.

begin repeat member roster calculate CR360 Member ID number text
CR361 Member's Name select_one gender CR371 Member's gender integer
CR381 Member's age date CR391 Date of birth end repeat member

Then have a series of calculated field that produce a space-separated
list of the indices into that repeat group that are within the designated
age range.
calculate ageok1 if(/data/member[1]/CR381 >= 5 and
/data/member[1]/CR381 <= 15, ' 1', '') calculate ageok2 if(/data/member[2]/CR381

= 5 and /data/member[2]/CR381 <= 15, ' 2', '') calculate ageok3 if(/data/member[3]/CR381
= 5 and /data/member[3]/CR381 <= 15, ' 3', '') calculate ageok4 if(/data/member[4]/CR381
= 5 and /data/member[4]/CR381 <= 15, ' 4', '') calculate ageok5 if(/data/member[5]/CR381
= 5 and /data/member[5]/CR381 <= 15, ' 5', '') calculate membersinrange
substr(concat(${ageok1},${ageok2},${ageok3},${ageok4},${ageok5}),1)

And this function once to compute the chosen member once. But in my
program , the note1 display nothing and the member chosen is 0. Can
somebody help me?
note note1 ${membersinrange} calculate chosenmember once(if(count-selected(/data/membersinrange)
= 0, 0, int(1.0+count-selected(/data/membersinrange)*random()))) note
Child child's name is ${chosenmember}

--

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.

Henri,

See https://groups.google.com/d/msg/opendatakit/DtOpSBaHa8I/7BJTK4-MQFUJ
and https://groups.google.com/d/msg/opendatakit/DtOpSBaHa8I/g4MKzNNxOaEJ

Yaw

··· -- Need ODK services? http://nafundi.com provides form design, server setup, professional support, and software development for ODK.

On Mon, Oct 13, 2014 at 11:26 AM, hvandenidsert@altaiconsulting.com wrote:

Dear Mitch, I have a problem that relates to this thread. I am trying to create a form that generates a random number which the enumerator will use to select a household from x number of Households they see in front of them.

I'm trying to create this without the random number changing after saving the form, the random number also has to be an integer for which i used the 'round()' function and added +1 so that '0' is not returned, and also so the last household has a chance of being selected. To generate the random number I used a decimal field with calculation 'once(random())', and default value 'random()'. This may not be the best way I realize, but it stops the numbers from recalculating ones the form is saved.

The closest I have come is in the attached file. However there are two problems I still have:

  1. The random value returned is sometimes higher than the number of households entered (due to the +1).

  2. The 'random_value' field (used to generate default random value) needs to be 'readonly' or hidden completely if possible?

I would really appreciate your help as I have been stuck on this for a while.

Thanking you in advance,

Henri

--

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.

Ok, I didn't know that. I wait for a response

··· 2014-07-14 16:01 GMT-04:00 Yaw Anokwa :

Hi Pierre,

Please note that Mitch (and really everyone else on this list) provides
free support in their spare time.

If you can't wait for a response, then I encourage you to hire one of the
many ODK companies available at http://opendatakit.org/help/help-for-hire/

Thanks,

Yaw

Need ODK services? http://nafundi.com provides form design, server setup,
professional support, and software development for ODK.

On Mon, Jul 14, 2014 at 11:35 AM, Pierre Anthony Garraud < pagarraud1@gmail.com> wrote:

HI MITCH,
Please can you tell me what wrong with my program? Sure,i forget
something important, byt idon't identify it.

thanks a lot

2014-07-13 10:09 GMT-04:00 Legarraudien pagarraud1@gmail.com:

Hi,

I have to select randomly a member in a household survey. fisrt of all,
I Ask for basic demographics in a repeat group.

begin repeat member roster calculate CR360 Member ID number text
CR361 Member's Name select_one gender CR371 Member's gender integer
CR381 Member's age date CR391 Date of birth end repeat member

Then have a series of calculated field that produce a space-separated
list of the indices into that repeat group that are within the designated
age range.
calculate ageok1 if(/data/member[1]/CR381 >= 5 and
/data/member[1]/CR381 <= 15, ' 1', '') calculate ageok2 if(/data/member[2]/CR381

= 5 and /data/member[2]/CR381 <= 15, ' 2', '') calculate ageok3 if(/data/member[3]/CR381
= 5 and /data/member[3]/CR381 <= 15, ' 3', '') calculate ageok4 if(/data/member[4]/CR381
= 5 and /data/member[4]/CR381 <= 15, ' 4', '') calculate ageok5 if(/data/member[5]/CR381
= 5 and /data/member[5]/CR381 <= 15, ' 5', '') calculate
membersinrange
substr(concat(${ageok1},${ageok2},${ageok3},${ageok4},${ageok5}),1)

And this function once to compute the chosen member once. But in my
program , the note1 display nothing and the member chosen is 0. Can
somebody help me?
note note1 ${membersinrange} calculate chosenmember once(if(count-selected(/data/membersinrange)
= 0, 0, int(1.0+count-selected(/data/membersinrange)*random()))) note
Child child's name is ${chosenmember}

--

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.

--

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.

Thank you for the post and response Yaw. I have two questions:

  1. Do you know if it is possible to substitute the modulo output with the
    value of a previously entered integer field?

e.g: once( concat(( round(random() * 100, 0) mod ${structures} ), " "))

  1. I'm not sure that concatenate is relevant for my example, nor if
    multiplying the random() function by 100 is relevant? Could you please
    explain what those two functions do in this particular equation?

Your help is much appreciated,

Thank you

··· On Tuesday, October 14, 2014 7:45:08 AM UTC+3, Yaw Anokwa wrote: > > Henri, > > See https://groups.google.com/d/msg/opendatakit/DtOpSBaHa8I/7BJTK4-MQFUJ > and https://groups.google.com/d/msg/opendatakit/DtOpSBaHa8I/g4MKzNNxOaEJ > > Yaw > -- > Need ODK services? http://nafundi.com provides form design, server > setup, professional support, and software development for ODK. > > On Mon, Oct 13, 2014 at 11:26 AM, <hvande...@altaiconsulting.com > wrote: > > Dear Mitch, I have a problem that relates to this thread. I am trying to > create a form that generates a random number which the enumerator will use > to select a household from x number of Households they see in front of > them. > > > > I'm trying to create this without the random number changing after > saving the form, the random number also has to be an integer for which i > used the 'round()' function and added +1 so that '0' is not returned, and > also so the last household has a chance of being selected. To generate the > random number I used a decimal field with calculation 'once(random())', and > default value 'random()'. This may not be the best way I realize, but it > stops the numbers from recalculating ones the form is saved. > > > > The closest I have come is in the attached file. However there are two > problems I still have: > > > > 1) The random value returned is sometimes higher than the number of > households entered (due to the +1). > > > > 2) The 'random_value' field (used to generate default random value) > needs to be 'readonly' or hidden completely if possible? > > > > I would really appreciate your help as I have been stuck on this for a > while. > > > > Thanking you in advance, > > > > Henri > > > > -- > > -- > > Post: opend...@googlegroups.com > > Unsubscribe: opendatakit...@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...@googlegroups.com . > > For more options, visit https://groups.google.com/d/optout. >

The once() should contain just the random number.

I.e., create a field "random_pick" calculate = "once(random())"

Then have the computed expression, "chosen_member":

if(count-selected(/data/membersinrange) = 0, 0,
int(1.0+count-selected(/data/membersinrange)**/data/random_pick*))
The problem is that after the first time through the loop, javarosa detects
that /data/membersinrange has changed, which triggers the evaluation of
chosen_member, which assigns 1 to chosen_member.
The second time through the loop, you add a 2nd member, javarosa detects
that /data/membersinrange has changed, and triggers a re-evaluation of
chosen_member, but because of the once() function, the re-computation is
prevented and remains 1.

This does mean that if you edit the form and delete or add more members,
you will end up with a different chosen member. Only if the number of
members is unchanged, will the chosen_member value also be unchanged.

··· On Mon, Jul 14, 2014 at 1:05 PM, Pierre Anthony Garraud < pagarraud1@gmail.com> wrote:

Ok, I didn't know that. I wait for a response

2014-07-14 16:01 GMT-04:00 Yaw Anokwa yanokwa@nafundi.com:

Hi Pierre,

Please note that Mitch (and really everyone else on this list) provides
free support in their spare time.

If you can't wait for a response, then I encourage you to hire one of the
many ODK companies available at
http://opendatakit.org/help/help-for-hire/

Thanks,

Yaw

Need ODK services? http://nafundi.com provides form design, server
setup, professional support, and software development for ODK.

On Mon, Jul 14, 2014 at 11:35 AM, Pierre Anthony Garraud < pagarraud1@gmail.com> wrote:

HI MITCH,
Please can you tell me what wrong with my program? Sure,i forget
something important, byt idon't identify it.

thanks a lot

2014-07-13 10:09 GMT-04:00 Legarraudien pagarraud1@gmail.com:

Hi,

I have to select randomly a member in a household survey. fisrt of
all, I Ask for basic demographics in a repeat group.

begin repeat member roster calculate CR360 Member ID number text
CR361 Member's Name select_one gender CR371 Member's gender integer
CR381 Member's age date CR391 Date of birth end repeat member

Then have a series of calculated field that produce a space-separated
list of the indices into that repeat group that are within the designated
age range.
calculate ageok1 if(/data/member[1]/CR381 >= 5 and
/data/member[1]/CR381 <= 15, ' 1', '') calculate ageok2 if(/data/member[2]/CR381

= 5 and /data/member[2]/CR381 <= 15, ' 2', '') calculate ageok3 if(/data/member[3]/CR381
= 5 and /data/member[3]/CR381 <= 15, ' 3', '') calculate ageok4 if(/data/member[4]/CR381
= 5 and /data/member[4]/CR381 <= 15, ' 4', '') calculate ageok5 if(/data/member[5]/CR381
= 5 and /data/member[5]/CR381 <= 15, ' 5', '') calculate
membersinrange
substr(concat(${ageok1},${ageok2},${ageok3},${ageok4},${ageok5}),1)

And this function once to compute the chosen member once. But in my
program , the note1 display nothing and the member chosen is 0. Can
somebody help me?
note note1 ${membersinrange} calculate chosenmember once(if(count-selected(/data/membersinrange)
= 0, 0, int(1.0+count-selected(/data/membersinrange)*random()))) note
Child child's name is ${chosenmember}

--

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.

--

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.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

Henri,

Try both these things yourself and see what happens.

In the case of the random() * 100, try doing a calculate prompt (say
with a name of test_calculate) with random() as the calculate. Then
add a text prompt with ${test_calculate} as the label see what it
returns.

Yaw

··· -- Need ODK services? http://nafundi.com provides form design, server setup, professional support, and software development for ODK.

On Mon, Oct 13, 2014 at 10:21 PM, Henri Van den Idsert hvandenidsert@altaiconsulting.com wrote:

Thank you for the post and response Yaw. I have two questions:

  1. Do you know if it is possible to substitute the modulo output with the
    value of a previously entered integer field?

e.g: once( concat(( round(random() * 100, 0) mod ${structures} ), " "))

  1. I'm not sure that concatenate is relevant for my example, nor if
    multiplying the random() function by 100 is relevant? Could you please
    explain what those two functions do in this particular equation?

Your help is much appreciated,

Thank you

On Tuesday, October 14, 2014 7:45:08 AM UTC+3, Yaw Anokwa wrote:

Henri,

See https://groups.google.com/d/msg/opendatakit/DtOpSBaHa8I/7BJTK4-MQFUJ
and https://groups.google.com/d/msg/opendatakit/DtOpSBaHa8I/g4MKzNNxOaEJ

Yaw

Need ODK services? http://nafundi.com provides form design, server
setup, professional support, and software development for ODK.

On Mon, Oct 13, 2014 at 11:26 AM, hvande...@altaiconsulting.com wrote:

Dear Mitch, I have a problem that relates to this thread. I am trying to
create a form that generates a random number which the enumerator will use
to select a household from x number of Households they see in front of them.

I'm trying to create this without the random number changing after
saving the form, the random number also has to be an integer for which i
used the 'round()' function and added +1 so that '0' is not returned, and
also so the last household has a chance of being selected. To generate the
random number I used a decimal field with calculation 'once(random())', and
default value 'random()'. This may not be the best way I realize, but it
stops the numbers from recalculating ones the form is saved.

The closest I have come is in the attached file. However there are two
problems I still have:

  1. The random value returned is sometimes higher than the number of
    households entered (due to the +1).

  2. The 'random_value' field (used to generate default random value)
    needs to be 'readonly' or hidden completely if possible?

I would really appreciate your help as I have been stuck on this for a
while.

Thanking you in advance,

Henri

--

Post: opend...@googlegroups.com
Unsubscribe: opendatakit...@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...@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.

Hi Mitch,
Thanks a lot, I' ll try it

··· 2014-07-15 16:23 GMT-07:00 Mitch Sundt :

The once() should contain just the random number.

I.e., create a field "random_pick" calculate = "once(random())"

Then have the computed expression, "chosen_member":

if(count-selected(/data/membersinrange) = 0, 0,
int(1.0+count-selected(/data/membersinrange)**/data/random_pick*))
The problem is that after the first time through the loop, javarosa
detects that /data/membersinrange has changed, which triggers the
evaluation of chosen_member, which assigns 1 to chosen_member.
The second time through the loop, you add a 2nd member, javarosa detects
that /data/membersinrange has changed, and triggers a re-evaluation of
chosen_member, but because of the once() function, the re-computation is
prevented and remains 1.

This does mean that if you edit the form and delete or add more members,
you will end up with a different chosen member. Only if the number of
members is unchanged, will the chosen_member value also be unchanged.

On Mon, Jul 14, 2014 at 1:05 PM, Pierre Anthony Garraud < pagarraud1@gmail.com> wrote:

Ok, I didn't know that. I wait for a response

2014-07-14 16:01 GMT-04:00 Yaw Anokwa yanokwa@nafundi.com:

Hi Pierre,

Please note that Mitch (and really everyone else on this list) provides
free support in their spare time.

If you can't wait for a response, then I encourage you to hire one of
the many ODK companies available at
http://opendatakit.org/help/help-for-hire/

Thanks,

Yaw

Need ODK services? http://nafundi.com provides form design, server
setup, professional support, and software development for ODK.

On Mon, Jul 14, 2014 at 11:35 AM, Pierre Anthony Garraud < pagarraud1@gmail.com> wrote:

HI MITCH,
Please can you tell me what wrong with my program? Sure,i forget
something important, byt idon't identify it.

thanks a lot

2014-07-13 10:09 GMT-04:00 Legarraudien pagarraud1@gmail.com:

Hi,

I have to select randomly a member in a household survey. fisrt of
all, I Ask for basic demographics in a repeat group.

begin repeat member roster calculate CR360 Member ID number text
CR361 Member's Name select_one gender CR371 Member's gender integer
CR381 Member's age date CR391 Date of birth end repeat member

Then have a series of calculated field that produce a space-separated
list of the indices into that repeat group that are within the designated
age range.
calculate ageok1 if(/data/member[1]/CR381 >= 5 and
/data/member[1]/CR381 <= 15, ' 1', '') calculate ageok2 if(/data/member[2]/CR381

= 5 and /data/member[2]/CR381 <= 15, ' 2', '') calculate ageok3 if(/data/member[3]/CR381
= 5 and /data/member[3]/CR381 <= 15, ' 3', '') calculate ageok4 if(/data/member[4]/CR381
= 5 and /data/member[4]/CR381 <= 15, ' 4', '') calculate ageok5 if(/data/member[5]/CR381
= 5 and /data/member[5]/CR381 <= 15, ' 5', '') calculate
membersinrange
substr(concat(${ageok1},${ageok2},${ageok3},${ageok4},${ageok5}),1)

And this function once to compute the chosen member once. But in my
program , the note1 display nothing and the member chosen is 0. Can
somebody help me?
note note1 ${membersinrange} calculate chosenmember once(if(count-selected(/data/membersinrange)
= 0, 0, int(1.0+count-selected(/data/membersinrange)*random()))) note
Child child's name is ${chosenmember}

--

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.

--

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.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

--

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.

Hi,

I found this very useful - thank you!

I am trying to adapt Legarraudien's program to select multiple household
members at random by generating a number of different random numbers. The
problem I have is that I cannot guarantee the same member is not picked
twice, since int(0.5+${total_number_in_household}*{random_number})) rounds
to the same integer for a range of random numbers. To work around this for
selecting two household members, I used the following code for chosen
member 2:

if(int(0.5+${total_number_in_household}{random_number2}) !=
(0.5+${total_number_in_household}
{random_number1}),
int(0.5+${total_number_in_household}{random_number2}),if(int(0.5+${total_number_in_household}{random_number2})=${total_number_in_household},1,int(0.5+${total_number_in_household}*{random_number2})+1))

In other words, if the second selected member is the same as the first
selected member, pick the next person on the list *unless *the selected
person is the last person on the list, in which case pick the first. This
seems to work, but it is very cumbersome and will get a lot worse when I
want to select 3 or more household members.

The other idea I had was to assign each household member a random number
and then only show a household member if the random number corresponding to
that member is greater than a certain threshold value (following this
thread:
https://groups.google.com/forum/#!msg/formhub-users/ndcyBG3I-og/2IiO0DlDYaEJ).
But if I did that, I would not be able to ensure that the "right" number of
household members is selected (i.e. if I want to select 4 household
members, I will sometimes get 3, sometimes 5 etc). Unlike the OP on that
thread, I do not know in advance the number of members on the roster so I
can't generate the members to select in advance.

Is there another possibility? For example, could I assign each household
member a random number, then pick the highest, second highest up to kth
highest random numbers (where k is my sample size). That's what I would do
in Stata - but I can't figure out a way of doing it here!

I didn't attach a mock xlsform since my problem is so related to the
earlier one in the thread but I could attach one if that would be helpful.

Thanks a lot,
Sam

··· On Tuesday, 15 July 2014 19:23:34 UTC-4, Mitch Sundt wrote: > > The once() should contain just the random number. > > I.e., create a field "random_pick" calculate = "once(random())" > > Then have the computed expression, "chosen_member": > > if(count-selected(/data/membersinrange) = 0, 0, > int(1.0+count-selected(/data/membersinrange)**/data/random_pick*)) > The problem is that after the first time through the loop, javarosa > detects that /data/membersinrange has changed, which triggers the > evaluation of chosen_member, which assigns 1 to chosen_member. > The second time through the loop, you add a 2nd member, javarosa detects > that /data/membersinrange has changed, and triggers a re-evaluation of > chosen_member, but because of the once() function, the re-computation is > prevented and remains 1. > > This does mean that if you edit the form and delete or add more members, > you will end up with a different chosen member. Only if the number of > members is unchanged, will the chosen_member value also be unchanged. > > > > > On Mon, Jul 14, 2014 at 1:05 PM, Pierre Anthony Garraud < pagar...@gmail.com > wrote: > >> Ok, I didn't know that. I wait for a response >> >> >> 2014-07-14 16:01 GMT-04:00 Yaw Anokwa <yan...@nafundi.com >: >> >> Hi Pierre, >>> >>> Please note that Mitch (and really everyone else on this list) provides >>> free support in their spare time. >>> >>> If you can't wait for a response, then I encourage you to hire one of >>> the many ODK companies available at >>> http://opendatakit.org/help/help-for-hire/ >>> >>> Thanks, >>> >>> Yaw >>> -- >>> Need ODK services? http://nafundi.com provides form design, server >>> setup, professional support, and software development for ODK. >>> >>> >>> On Mon, Jul 14, 2014 at 11:35 AM, Pierre Anthony Garraud < pagar...@gmail.com > wrote: >>> >>>> HI MITCH, >>>> Please can you tell me what wrong with my program? Sure,i forget >>>> something important, byt idon't identify it. >>>> >>>> thanks a lot >>>> >>>> >>>> >>>> >>>> 2014-07-13 10:09 GMT-04:00 Legarraudien >>> >: >>>> >>>> Hi, >>>>> I have to select randomly a member in a household survey. fisrt of >>>>> all, I Ask for basic demographics in a repeat group. >>>>> >>>>> begin repeat member roster calculate CR360 Member ID number text >>>>> CR361 Member's Name select_one gender CR371 Member's gender integer >>>>> CR381 Member's age date CR391 Date of birth end repeat member >>>>> >>>>> Then have a series of calculated field that produce a space-separated >>>>> list of the indices into that repeat group that are within the designated >>>>> age range. >>>>> calculate ageok1 if(/data/member[1]/CR381 >= 5 and >>>>> /data/member[1]/CR381 <= 15, ' 1', '') calculate ageok2 if(/data/member[2]/CR381 >>>>> >= 5 and /data/member[2]/CR381 <= 15, ' 2', '') calculate ageok3 if(/data/member[3]/CR381 >>>>> >= 5 and /data/member[3]/CR381 <= 15, ' 3', '') calculate ageok4 if(/data/member[4]/CR381 >>>>> >= 5 and /data/member[4]/CR381 <= 15, ' 4', '') calculate ageok5 if(/data/member[5]/CR381 >>>>> >= 5 and /data/member[5]/CR381 <= 15, ' 5', '') calculate >>>>> membersinrange >>>>> substr(concat(${ageok1},${ageok2},${ageok3},${ageok4},${ageok5}),1) >>>>> >>>>> >>>>> And this function once to compute the chosen member once. But in my >>>>> program , the note1 display nothing and the member chosen is 0. Can >>>>> somebody help me? >>>>> note note1 ${membersinrange} calculate chosenmember once(if(count-selected(/data/membersinrange) >>>>> = 0, 0, int(1.0+count-selected(/data/membersinrange)*random()))) note >>>>> Child child's name is ${chosenmember} >>>>> >>>>> -- >>>>> -- >>>>> Post: opend...@googlegroups.com >>>>> Unsubscribe: opendatakit...@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...@googlegroups.com . >>>>> For more options, visit https://groups.google.com/d/optout. >>>>> >>>> >>>> -- >>>> -- >>>> Post: opend...@googlegroups.com >>>> Unsubscribe: opendatakit...@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...@googlegroups.com . >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> >>> -- >>> -- >>> Post: opend...@googlegroups.com >>> Unsubscribe: opendatakit...@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...@googlegroups.com . >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> -- >> -- >> Post: opend...@googlegroups.com >> Unsubscribe: opendatakit...@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...@googlegroups.com . >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > Mitch Sundt > Software Engineer > University of Washington > mitche...@gmail.com >

Hi Mitch,
Sorry for all. This programm is very important for me. I count on Your
support to resolve this problem

I have an issue,I don't know how to referance the child's name. when I
use "/data/member[/data/chosenmember]/name" i Have an error message like
this: There is no survey element with this name.
And i don't know which field has this relevant="/data/chosenmenber > 0"

Thanks a lot

··· 2014-07-15 17:34 GMT-07:00 Pierre Anthony Garraud :

Hi Mitch,
Thanks a lot, I' ll try it

2014-07-15 16:23 GMT-07:00 Mitch Sundt mitchellsundt@gmail.com:

The once() should contain just the random number.

I.e., create a field "random_pick" calculate = "once(random())"

Then have the computed expression, "chosen_member":

if(count-selected(/data/membersinrange) = 0, 0,
int(1.0+count-selected(/data/membersinrange)**/data/random_pick*))
The problem is that after the first time through the loop, javarosa
detects that /data/membersinrange has changed, which triggers the
evaluation of chosen_member, which assigns 1 to chosen_member.
The second time through the loop, you add a 2nd member, javarosa detects
that /data/membersinrange has changed, and triggers a re-evaluation of
chosen_member, but because of the once() function, the re-computation is
prevented and remains 1.

This does mean that if you edit the form and delete or add more members,
you will end up with a different chosen member. Only if the number of
members is unchanged, will the chosen_member value also be unchanged.

On Mon, Jul 14, 2014 at 1:05 PM, Pierre Anthony Garraud < pagarraud1@gmail.com> wrote:

Ok, I didn't know that. I wait for a response

2014-07-14 16:01 GMT-04:00 Yaw Anokwa yanokwa@nafundi.com:

Hi Pierre,

Please note that Mitch (and really everyone else on this list) provides
free support in their spare time.

If you can't wait for a response, then I encourage you to hire one of
the many ODK companies available at
http://opendatakit.org/help/help-for-hire/

Thanks,

Yaw

Need ODK services? http://nafundi.com provides form design, server
setup, professional support, and software development for ODK.

On Mon, Jul 14, 2014 at 11:35 AM, Pierre Anthony Garraud < pagarraud1@gmail.com> wrote:

HI MITCH,
Please can you tell me what wrong with my program? Sure,i forget
something important, byt idon't identify it.

thanks a lot

2014-07-13 10:09 GMT-04:00 Legarraudien pagarraud1@gmail.com:

Hi,

I have to select randomly a member in a household survey. fisrt of
all, I Ask for basic demographics in a repeat group.

begin repeat member roster calculate CR360 Member ID number text
CR361 Member's Name select_one gender CR371 Member's gender integer
CR381 Member's age date CR391 Date of birth end repeat member

Then have a series of calculated field that produce a space-separated
list of the indices into that repeat group that are within the designated
age range.
calculate ageok1 if(/data/member[1]/CR381 >= 5 and
/data/member[1]/CR381 <= 15, ' 1', '') calculate ageok2 if(/data/member[2]/CR381

= 5 and /data/member[2]/CR381 <= 15, ' 2', '') calculate ageok3 if(/data/member[3]/CR381
= 5 and /data/member[3]/CR381 <= 15, ' 3', '') calculate ageok4 if(/data/member[4]/CR381
= 5 and /data/member[4]/CR381 <= 15, ' 4', '') calculate ageok5 if(/data/member[5]/CR381
= 5 and /data/member[5]/CR381 <= 15, ' 5', '') calculate
membersinrange
substr(concat(${ageok1},${ageok2},${ageok3},${ageok4},${ageok5}),1)

And this function once to compute the chosen member once. But in my
program , the note1 display nothing and the member chosen is 0. Can
somebody help me?
note note1 ${membersinrange} calculate chosenmember once(if(count-selected(/data/membersinrange)
= 0, 0, int(1.0+count-selected(/data/membersinrange)*random())))
note Child child's name is ${chosenmember}

--

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.

--

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.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

--

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.

All instances of "0.5" in the formulae below should be "1". Sorry about
that; I've been working sometimes with int() and sometimes with round().

Sam

··· On Saturday, 15 November 2014 20:52:38 UTC-5, Samantha Burn wrote: > > Hi, > > I found this very useful - thank you! > > I am trying to adapt Legarraudien's program to select multiple household > members at random by generating a number of different random numbers. The > problem I have is that I cannot guarantee the same member is not picked > twice, since int(0.5+${total_number_in_household}*{random_number})) rounds > to the same integer for a range of random numbers. To work around this for > selecting two household members, I used the following code for chosen > member 2: > > if(int(0.5+${total_number_in_household}*{random_number2}) != > (0.5+${total_number_in_household}*{random_number1}), > int(0.5+${total_number_in_household}*{random_number2}),if(int(0.5+${total_number_in_household}*{random_number2})=${total_number_in_household},1,int(0.5+${total_number_in_household}*{random_number2})+1)) > > In other words, if the second selected member is the same as the first > selected member, pick the next person on the list *unless *the selected > person is the last person on the list, in which case pick the first. This > seems to work, but it is very cumbersome and will get a lot worse when I > want to select 3 or more household members. > > The other idea I had was to assign each household member a random number > and then only show a household member if the random number corresponding to > that member is greater than a certain threshold value (following this > thread: > https://groups.google.com/forum/#!msg/formhub-users/ndcyBG3I-og/2IiO0DlDYaEJ). > But if I did that, I would not be able to ensure that the "right" number of > household members is selected (i.e. if I want to select 4 household > members, I will sometimes get 3, sometimes 5 etc). Unlike the OP on that > thread, I do not know in advance the number of members on the roster so I > can't generate the members to select in advance. > > Is there another possibility? For example, could I assign each household > member a random number, then pick the highest, second highest up to kth > highest random numbers (where k is my sample size). That's what I would do > in Stata - but I can't figure out a way of doing it here! > > I didn't attach a mock xlsform since my problem is so related to the > earlier one in the thread but I could attach one if that would be helpful. > > Thanks a lot, > Sam > > On Tuesday, 15 July 2014 19:23:34 UTC-4, Mitch Sundt wrote: >> >> The once() should contain just the random number. >> >> I.e., create a field "random_pick" calculate = "once(random())" >> >> Then have the computed expression, "chosen_member": >> >> if(count-selected(/data/membersinrange) = 0, 0, >> int(1.0+count-selected(/data/membersinrange)**/data/random_pick*)) >> The problem is that after the first time through the loop, javarosa >> detects that /data/membersinrange has changed, which triggers the >> evaluation of chosen_member, which assigns 1 to chosen_member. >> The second time through the loop, you add a 2nd member, javarosa detects >> that /data/membersinrange has changed, and triggers a re-evaluation of >> chosen_member, but because of the once() function, the re-computation is >> prevented and remains 1. >> >> This does mean that if you edit the form and delete or add more members, >> you will end up with a different chosen member. Only if the number of >> members is unchanged, will the chosen_member value also be unchanged. >> >> >> >> >> On Mon, Jul 14, 2014 at 1:05 PM, Pierre Anthony Garraud < pagar...@gmail.com> wrote: >> >>> Ok, I didn't know that. I wait for a response >>> >>> >>> 2014-07-14 16:01 GMT-04:00 Yaw Anokwa : >>> >>> Hi Pierre, >>>> >>>> Please note that Mitch (and really everyone else on this list) provides >>>> free support in their spare time. >>>> >>>> If you can't wait for a response, then I encourage you to hire one of >>>> the many ODK companies available at >>>> http://opendatakit.org/help/help-for-hire/ >>>> >>>> Thanks, >>>> >>>> Yaw >>>> -- >>>> Need ODK services? http://nafundi.com provides form design, server >>>> setup, professional support, and software development for ODK. >>>> >>>> >>>> On Mon, Jul 14, 2014 at 11:35 AM, Pierre Anthony Garraud < pagar...@gmail.com> wrote: >>>> >>>>> HI MITCH, >>>>> Please can you tell me what wrong with my program? Sure,i forget >>>>> something important, byt idon't identify it. >>>>> >>>>> thanks a lot >>>>> >>>>> >>>>> >>>>> >>>>> 2014-07-13 10:09 GMT-04:00 Legarraudien : >>>>> >>>>> Hi, >>>>>> I have to select randomly a member in a household survey. fisrt of >>>>>> all, I Ask for basic demographics in a repeat group. >>>>>> >>>>>> begin repeat member roster calculate CR360 Member ID number text >>>>>> CR361 Member's Name select_one gender CR371 Member's gender integer >>>>>> CR381 Member's age date CR391 Date of birth end repeat member >>>>>> >>>>>> Then have a series of calculated field that produce a space-separated >>>>>> list of the indices into that repeat group that are within the designated >>>>>> age range. >>>>>> calculate ageok1 if(/data/member[1]/CR381 >= 5 and >>>>>> /data/member[1]/CR381 <= 15, ' 1', '') calculate ageok2 if(/data/member[2]/CR381 >>>>>> >= 5 and /data/member[2]/CR381 <= 15, ' 2', '') calculate ageok3 if(/data/member[3]/CR381 >>>>>> >= 5 and /data/member[3]/CR381 <= 15, ' 3', '') calculate ageok4 if(/data/member[4]/CR381 >>>>>> >= 5 and /data/member[4]/CR381 <= 15, ' 4', '') calculate ageok5 if(/data/member[5]/CR381 >>>>>> >= 5 and /data/member[5]/CR381 <= 15, ' 5', '') calculate >>>>>> membersinrange >>>>>> substr(concat(${ageok1},${ageok2},${ageok3},${ageok4},${ageok5}),1) >>>>>> >>>>>> >>>>>> And this function once to compute the chosen member once. But in my >>>>>> program , the note1 display nothing and the member chosen is 0. Can >>>>>> somebody help me? >>>>>> note note1 ${membersinrange} calculate chosenmember once(if(count-selected(/data/membersinrange) >>>>>> = 0, 0, int(1.0+count-selected(/data/membersinrange)*random()))) >>>>>> note Child child's name is ${chosenmember} >>>>>> >>>>>> -- >>>>>> -- >>>>>> Post: opend...@googlegroups.com >>>>>> Unsubscribe: opendatakit...@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...@googlegroups.com. >>>>>> For more options, visit https://groups.google.com/d/optout. >>>>>> >>>>> >>>>> -- >>>>> -- >>>>> Post: opend...@googlegroups.com >>>>> Unsubscribe: opendatakit...@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...@googlegroups.com. >>>>> For more options, visit https://groups.google.com/d/optout. >>>>> >>>> >>>> -- >>>> -- >>>> Post: opend...@googlegroups.com >>>> Unsubscribe: opendatakit...@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...@googlegroups.com. >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> >>> -- >>> -- >>> Post: opend...@googlegroups.com >>> Unsubscribe: opendatakit...@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...@googlegroups.com. >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> >> >> -- >> Mitch Sundt >> Software Engineer >> University of Washington >> mitche...@gmail.com >> >

typo

chosenmenber

vs

chosenmember

··· On Tue, Jul 15, 2014 at 7:20 PM, Pierre Anthony Garraud < pagarraud1@gmail.com> wrote:

Hi Mitch,
Sorry for all. This programm is very important for me. I count on Your
support to resolve this problem

I have an issue,I don't know how to referance the child's name. when I
use "/data/member[/data/chosenmember]/name" i Have an error message like
this: There is no survey element with this name.
And i don't know which field has this relevant="/data/chosenmenber > 0"

Thanks a lot

2014-07-15 17:34 GMT-07:00 Pierre Anthony Garraud pagarraud1@gmail.com:

Hi Mitch,

Thanks a lot, I' ll try it

2014-07-15 16:23 GMT-07:00 Mitch Sundt mitchellsundt@gmail.com:

The once() should contain just the random number.

I.e., create a field "random_pick" calculate = "once(random())"

Then have the computed expression, "chosen_member":

if(count-selected(/data/membersinrange) = 0, 0,
int(1.0+count-selected(/data/membersinrange)**/data/random_pick*))
The problem is that after the first time through the loop, javarosa
detects that /data/membersinrange has changed, which triggers the
evaluation of chosen_member, which assigns 1 to chosen_member.
The second time through the loop, you add a 2nd member, javarosa detects
that /data/membersinrange has changed, and triggers a re-evaluation of
chosen_member, but because of the once() function, the re-computation is
prevented and remains 1.

This does mean that if you edit the form and delete or add more members,
you will end up with a different chosen member. Only if the number of
members is unchanged, will the chosen_member value also be unchanged.

On Mon, Jul 14, 2014 at 1:05 PM, Pierre Anthony Garraud < pagarraud1@gmail.com> wrote:

Ok, I didn't know that. I wait for a response

2014-07-14 16:01 GMT-04:00 Yaw Anokwa yanokwa@nafundi.com:

Hi Pierre,

Please note that Mitch (and really everyone else on this list)
provides free support in their spare time.

If you can't wait for a response, then I encourage you to hire one of
the many ODK companies available at
http://opendatakit.org/help/help-for-hire/

Thanks,

Yaw

Need ODK services? http://nafundi.com provides form design, server
setup, professional support, and software development for ODK.

On Mon, Jul 14, 2014 at 11:35 AM, Pierre Anthony Garraud < pagarraud1@gmail.com> wrote:

HI MITCH,
Please can you tell me what wrong with my program? Sure,i forget
something important, byt idon't identify it.

thanks a lot

2014-07-13 10:09 GMT-04:00 Legarraudien pagarraud1@gmail.com:

Hi,

I have to select randomly a member in a household survey. fisrt of
all, I Ask for basic demographics in a repeat group.

begin repeat member roster calculate CR360 Member ID number text
CR361 Member's Name select_one gender CR371 Member's gender
integer CR381 Member's age date CR391 Date of birth end repeat
member

Then have a series of calculated field that produce a
space-separated list of the indices into that repeat group that are within
the designated age range.
calculate ageok1 if(/data/member[1]/CR381 >= 5 and
/data/member[1]/CR381 <= 15, ' 1', '') calculate ageok2 if(/data/member[2]/CR381

= 5 and /data/member[2]/CR381 <= 15, ' 2', '') calculate ageok3 if(/data/member[3]/CR381
= 5 and /data/member[3]/CR381 <= 15, ' 3', '') calculate ageok4 if(/data/member[4]/CR381
= 5 and /data/member[4]/CR381 <= 15, ' 4', '') calculate ageok5 if(/data/member[5]/CR381
= 5 and /data/member[5]/CR381 <= 15, ' 5', '') calculate
membersinrange
substr(concat(${ageok1},${ageok2},${ageok3},${ageok4},${ageok5}),1)

And this function once to compute the chosen member once. But in
my program , the note1 display nothing and the member chosen is 0. Can
somebody help me?
note note1 ${membersinrange} calculate chosenmember once(if(count-selected(/data/membersinrange)
= 0, 0, int(1.0+count-selected(/data/membersinrange)*random())))
note Child child's name is ${chosenmember}

--

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.

--

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.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

--

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.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

Yes, in one of my earlier posts, I tested against 1 vs. 0 to avoid handling
the rounding-down that round() does. You need to be careful with rounding
vs. truncating.

Forgot to clarify that at that time.

··· On Sat, Nov 15, 2014 at 6:39 PM, Samantha Burn wrote:

All instances of "0.5" in the formulae below should be "1". Sorry about
that; I've been working sometimes with int() and sometimes with round().

Sam

On Saturday, 15 November 2014 20:52:38 UTC-5, Samantha Burn wrote:

Hi,

I found this very useful - thank you!

I am trying to adapt Legarraudien's program to select multiple household
members at random by generating a number of different random numbers. The
problem I have is that I cannot guarantee the same member is not picked
twice, since int(0.5+${total_number_in_household}*{random_number}))
rounds to the same integer for a range of random numbers. To work around
this for selecting two household members, I used the following code for
chosen member 2:

if(int(0.5+${total_number_in_household}{random_number2}) !=
(0.5+${total_number_in_household}
{random_number1}),
int(0.5+${total_number_in_household}{random_number2}),
if(int(0.5+${total_number_in_household}
{random_number2})=$
{total_number_in_household},1,int(0.5+${total_number_in_
household}*{random_number2})+1))

In other words, if the second selected member is the same as the first
selected member, pick the next person on the list *unless *the selected
person is the last person on the list, in which case pick the first. This
seems to work, but it is very cumbersome and will get a lot worse when I
want to select 3 or more household members.

The other idea I had was to assign each household member a random number
and then only show a household member if the random number corresponding to
that member is greater than a certain threshold value (following this
thread: https://groups.google.com/forum/#!msg/formhub-users/
ndcyBG3I-og/2IiO0DlDYaEJ). But if I did that, I would not be able to
ensure that the "right" number of household members is selected (i.e. if I
want to select 4 household members, I will sometimes get 3, sometimes 5
etc). Unlike the OP on that thread, I do not know in advance the number of
members on the roster so I can't generate the members to select in advance.

Is there another possibility? For example, could I assign each household
member a random number, then pick the highest, second highest up to kth
highest random numbers (where k is my sample size). That's what I would do
in Stata - but I can't figure out a way of doing it here!

I didn't attach a mock xlsform since my problem is so related to the
earlier one in the thread but I could attach one if that would be helpful.

Thanks a lot,
Sam

On Tuesday, 15 July 2014 19:23:34 UTC-4, Mitch Sundt wrote:

The once() should contain just the random number.

I.e., create a field "random_pick" calculate = "once(random())"

Then have the computed expression, "chosen_member":

if(count-selected(/data/membersinrange) = 0, 0,
int(1.0+count-selected(/data/membersinrange)**/data/random_pick*))
The problem is that after the first time through the loop, javarosa
detects that /data/membersinrange has changed, which triggers the
evaluation of chosen_member, which assigns 1 to chosen_member.
The second time through the loop, you add a 2nd member, javarosa detects
that /data/membersinrange has changed, and triggers a re-evaluation of
chosen_member, but because of the once() function, the re-computation is
prevented and remains 1.

This does mean that if you edit the form and delete or add more members,
you will end up with a different chosen member. Only if the number of
members is unchanged, will the chosen_member value also be unchanged.

On Mon, Jul 14, 2014 at 1:05 PM, Pierre Anthony Garraud < pagar...@gmail.com> wrote:

Ok, I didn't know that. I wait for a response

2014-07-14 16:01 GMT-04:00 Yaw Anokwa yan...@nafundi.com:

Hi Pierre,

Please note that Mitch (and really everyone else on this list)
provides free support in their spare time.

If you can't wait for a response, then I encourage you to hire one of
the many ODK companies available at http://opendatakit.org/help/
help-for-hire/

Thanks,

Yaw

Need ODK services? http://nafundi.com provides form design, server
setup, professional support, and software development for ODK.

On Mon, Jul 14, 2014 at 11:35 AM, Pierre Anthony Garraud < pagar...@gmail.com> wrote:

HI MITCH,
Please can you tell me what wrong with my program? Sure,i forget
something important, byt idon't identify it.

thanks a lot

2014-07-13 10:09 GMT-04:00 Legarraudien pagar...@gmail.com:

Hi,

I have to select randomly a member in a household survey. fisrt of
all, I Ask for basic demographics in a repeat group.

begin repeat member roster calculate CR360 Member ID number text
CR361 Member's Name select_one gender CR371 Member's gender
integer CR381 Member's age date CR391 Date of birth end repeat
member

Then have a series of calculated field that produce a
space-separated list of the indices into that repeat group that are within
the designated age range.
calculate ageok1 if(/data/member[1]/CR381 >= 5 and
/data/member[1]/CR381 <= 15, ' 1', '') calculate ageok2 if(/data/member[2]/CR381

= 5 and /data/member[2]/CR381 <= 15, ' 2', '') calculate ageok3 if(/data/member[3]/CR381
= 5 and /data/member[3]/CR381 <= 15, ' 3', '') calculate ageok4 if(/data/member[4]/CR381
= 5 and /data/member[4]/CR381 <= 15, ' 4', '') calculate ageok5 if(/data/member[5]/CR381
= 5 and /data/member[5]/CR381 <= 15, ' 5', '') calculate
membersinrange substr(concat(${ageok1},${
ageok2},${ageok3},${ageok4},${ageok5}),1)

And this function once to compute the chosen member once. But in
my program , the note1 display nothing and the member chosen is 0. Can
somebody help me?
note note1 ${membersinrange} calculate chosenmember
once(if(count-selected(/data/membersinrange) = 0, 0,
int(1.0+count-selected(/data/membersinrange)*random()))) note Child child's
name is ${chosenmember}

--

Post: opend...@googlegroups.com
Unsubscribe: opendatakit...@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...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--

Post: opend...@googlegroups.com
Unsubscribe: opendatakit...@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...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--

Post: opend...@googlegroups.com
Unsubscribe: opendatakit...@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...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--

Post: opend...@googlegroups.com
Unsubscribe: opendatakit...@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...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
Mitch Sundt
Software Engineer
University of Washington
mitche...@gmail.com

--
--
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.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

All instances of "0.5" in the formulae below should be "1". Sorry about that; I've been working sometimes with int() and sometimes with round().

Sam

Hi,

I found this very useful - thank you!

I am trying to adapt Legarraudien's program to select multiple household members at random by generating a number of different random numbers. The problem I have is that I cannot guarantee the same member is not picked twice, since int(0.5+${total_number_in_household}*{random_number})) rounds to the same integer for a range of random numbers. To work around this for selecting two household members, I used the following code for chosen member 2:

if(int(0.5+${total_number_in_household}{random_number2}) != (0.5+${total_number_in_household}{random_number1}), int(0.5+${total_number_in_household}{random_number2}),if(int(0.5+${total_number_in_household}{random_number2})=${total_number_in_household},1,int(0.5+${total_number_in_household}*{random_number2})+1))

In other words, if the second selected member is the same as the first selected member, pick the next person on the list unless the selected person is the last person on the list, in which case pick the first. This seems to work, but it is very cumbersome and will get a lot worse when I want to select 3 or more household members.

The other idea I had was to assign each household member a random number and then only show a household member if the random number corresponding to that member is greater than a certain threshold value (following this thread: https://groups.google.com/forum/#!msg/formhub-users/ndcyBG3I-og/2IiO0DlDYaEJ). But if I did that, I would not be able to ensure that the "right" number of household members is selected (i.e. if I want to select 4 household members, I will sometimes get 3, sometimes 5 etc). Unlike the OP on that thread, I do not know in advance the number of members on the roster so I can't generate the members to select in advance.

Is there another possibility? For example, could I assign each household member a random number, then pick the highest, second highest up to kth highest random numbers (where k is my sample size). That's what I would do in Stata - but I can't figure out a way of doing it here!

I didn't attach a mock xlsform since my problem is so related to the earlier one in the thread but I could attach one if that would be helpful.

Thanks a lot,
Sam

The once() should contain just the random number.

I.e., create a field "random_pick" calculate = "once(random())"

Then have the computed expression, "chosen_member":

if(count-selected(/data/membersinrange) = 0, 0,
int(1.0+count-selected(/data/membersinrange)*/data/random_pick))

The problem is that after the first time through the loop, javarosa detects that /data/membersinrange has changed, which triggers the evaluation of chosen_member, which assigns 1 to chosen_member.

The second time through the loop, you add a 2nd member, javarosa detects that /data/membersinrange has changed, and triggers a re-evaluation of chosen_member, but because of the once() function, the re-computation is prevented and remains 1.

This does mean that if you edit the form and delete or add more members, you will end up with a different chosen member. Only if the number of members is unchanged, will the chosen_member value also be unchanged.

Ok, I didn't know that. I wait for a response

Hi Pierre,

Please note that Mitch (and really everyone else on this list) provides free support in their spare time.

If you can't wait for a response, then I encourage you to hire one of the many ODK companies available at http://opendatakit.org/help/help-for-hire/

Thanks,

Yaw

--
Need ODK services? http://nafundi.com provides form design, server setup, professional support, and software development for ODK.

HI MITCH,
Please can you tell me what wrong with my program? Sure,i forget something important, byt idon't identify it.

thanks a lot

Hi,
I have to select randomly a member in a household survey. fisrt of all, I Ask for basic demographics in a repeat
group.

begin
repeat
member
roster

calculate
CR360
Member ID number

text
CR361
Member's Name

select_one
gender
CR371
Member's gender

integer
CR381
Member's age

date
CR391
Date of birth

end repeat
member

Then have a series of calculated field
that produce a space-separated list of the indices into that repeat group that
are within the designated age range.

calculate
ageok1

if(/data/member[1]/CR381 >= 5
and /data/member[1]/CR381 <= 15, ' 1', '')

calculate
ageok2

if(/data/member[2]/CR381 >= 5 and /data/member[2]/CR381
<= 15, ' 2', '')

calculate
ageok3

if(/data/member[3]/CR381 >= 5 and /data/member[3]/CR381
<= 15, ' 3', '')

calculate
ageok4

if(/data/member[4]/CR381 >= 5 and /data/member[4]/CR381
<= 15, ' 4', '')

calculate
ageok5

if(/data/member[5]/CR381 >= 5 and /data/member[5]/CR381
<= 15, ' 5', '')

calculate
membersinrange

substr(concat(${ageok1},${ageok2},${ageok3},${ageok4},${ageok5}),1)

And this function once to compute the chosen member once. But in my program , the note1 display nothing and the member chosen is 0. Can somebody help me?

note
note1
${membersinrange}

calculate
chosenmember

once(if(count-selected(/data/membersinrange) = 0, 0,
int(1.0+count-selected(/data/membersinrange)*random())))

note
Child
child's name is
${chosenmember}

--

--

Post: opend...@googlegroups.com

Unsubscribe: opendatakit...@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...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--

--

Post: opend...@googlegroups.com

Unsubscribe: opendatakit...@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...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--

--

Post: opend...@googlegroups.com

Unsubscribe: opendatakit...@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...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--

--

Post: opend...@googlegroups.com

Unsubscribe: opendatakit...@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...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
Mitch Sundt
Software Engineer
University of Washington
mitche...@gmail.com

Hi Sam,
Please, did you eventually figure out how to randomly select a subset of households, by I assigning each household member a random number, then picking the highest, second highest up to kth highest random numbers? I am trying to create a questionnaire that randomly generates a list of 5 villages from a group of villages being served by a primary health center.

I can't see how it was resolved from the thread.

Many thanks,
Yemi

··· On Saturday, November 15, 2014 at 9:39:48 PM UTC-5, Samantha Burn wrote: > On Saturday, 15 November 2014 20:52:38 UTC-5, Samantha Burn wrote: > On Tuesday, 15 July 2014 19:23:34 UTC-4, Mitch Sundt wrote: > On Mon, Jul 14, 2014 at 1:05 PM, Pierre Anthony Garraud wrote: > 2014-07-14 16:01 GMT-04:00 Yaw Anokwa : > On Mon, Jul 14, 2014 at 11:35 AM, Pierre Anthony Garraud wrote: > 2014-07-13 10:09 GMT-04:00 Legarraudien :

Hi Mitch,
I don't understand this
typo

chosenmenber

vs

chosenmember

··· 2014-07-17 10:52 GMT-07:00 Mitch Sundt :

typo

chosenmenber

vs

chosenmember

On Tue, Jul 15, 2014 at 7:20 PM, Pierre Anthony Garraud < pagarraud1@gmail.com> wrote:

Hi Mitch,
Sorry for all. This programm is very important for me. I count on Your
support to resolve this problem

I have an issue,I don't know how to referance the child's name. when I
use "/data/member[/data/chosenmember]/name" i Have an error message like
this: There is no survey element with this name.
And i don't know which field has this relevant="/data/chosenmenber > 0"

Thanks a lot

2014-07-15 17:34 GMT-07:00 Pierre Anthony Garraud pagarraud1@gmail.com:

Hi Mitch,

Thanks a lot, I' ll try it

2014-07-15 16:23 GMT-07:00 Mitch Sundt mitchellsundt@gmail.com:

The once() should contain just the random number.

I.e., create a field "random_pick" calculate = "once(random())"

Then have the computed expression, "chosen_member":

if(count-selected(/data/membersinrange) = 0, 0,
int(1.0+count-selected(/data/membersinrange)**/data/random_pick*))
The problem is that after the first time through the loop, javarosa
detects that /data/membersinrange has changed, which triggers the
evaluation of chosen_member, which assigns 1 to chosen_member.
The second time through the loop, you add a 2nd member, javarosa
detects that /data/membersinrange has changed, and triggers a re-evaluation
of chosen_member, but because of the once() function, the re-computation is
prevented and remains 1.

This does mean that if you edit the form and delete or add more
members, you will end up with a different chosen member. Only if the number
of members is unchanged, will the chosen_member value also be unchanged.

On Mon, Jul 14, 2014 at 1:05 PM, Pierre Anthony Garraud < pagarraud1@gmail.com> wrote:

Ok, I didn't know that. I wait for a response

2014-07-14 16:01 GMT-04:00 Yaw Anokwa yanokwa@nafundi.com:

Hi Pierre,

Please note that Mitch (and really everyone else on this list)
provides free support in their spare time.

If you can't wait for a response, then I encourage you to hire one of
the many ODK companies available at
http://opendatakit.org/help/help-for-hire/

Thanks,

Yaw

Need ODK services? http://nafundi.com provides form design, server
setup, professional support, and software development for ODK.

On Mon, Jul 14, 2014 at 11:35 AM, Pierre Anthony Garraud < pagarraud1@gmail.com> wrote:

HI MITCH,
Please can you tell me what wrong with my program? Sure,i forget
something important, byt idon't identify it.

thanks a lot

2014-07-13 10:09 GMT-04:00 Legarraudien pagarraud1@gmail.com:

Hi,

I have to select randomly a member in a household survey. fisrt of
all, I Ask for basic demographics in a repeat group.

begin repeat member roster calculate CR360 Member ID number
text CR361 Member's Name select_one gender CR371 Member's gender
integer CR381 Member's age date CR391 Date of birth end repeat
member

Then have a series of calculated field that produce a
space-separated list of the indices into that repeat group that are within
the designated age range.
calculate ageok1 if(/data/member[1]/CR381 >= 5 and
/data/member[1]/CR381 <= 15, ' 1', '') calculate ageok2 if(/data/member[2]/CR381

= 5 and /data/member[2]/CR381 <= 15, ' 2', '') calculate ageok3 if(/data/member[3]/CR381
= 5 and /data/member[3]/CR381 <= 15, ' 3', '') calculate ageok4 if(/data/member[4]/CR381
= 5 and /data/member[4]/CR381 <= 15, ' 4', '') calculate ageok5 if(/data/member[5]/CR381
= 5 and /data/member[5]/CR381 <= 15, ' 5', '') calculate
membersinrange
substr(concat(${ageok1},${ageok2},${ageok3},${ageok4},${ageok5}),1)

And this function once to compute the chosen member once. But in
my program , the note1 display nothing and the member chosen is 0. Can
somebody help me?
note note1 ${membersinrange} calculate chosenmember once(if(count-selected(/data/membersinrange)
= 0, 0, int(1.0+count-selected(/data/membersinrange)*random())))
note Child child's name is ${chosenmember}

--

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.

--

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.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

--

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.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

--

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.

All instances of "0.5" in the formulae below should be "1". Sorry about that; I've been working sometimes with int() and sometimes with round().

Sam

Hi,

I found this very useful - thank you!

I am trying to adapt Legarraudien's program to select multiple household members at random by generating a number of different random numbers. The problem I have is that I cannot guarantee the same member is not picked twice, since int(0.5+${total_number_in_household}*{random_number})) rounds to the same integer for a range of random numbers. To work around this for selecting two household members, I used the following code for chosen member 2:

if(int(0.5+${total_number_in_household}{random_number2}) != (0.5+${total_number_in_household}{random_number1}), int(0.5+${total_number_in_household}{random_number2}),if(int(0.5+${total_number_in_household}{random_number2})=${total_number_in_household},1,int(0.5+${total_number_in_household}*{random_number2})+1))

In other words, if the second selected member is the same as the first selected member, pick the next person on the list unless the selected person is the last person on the list, in which case pick the first. This seems to work, but it is very cumbersome and will get a lot worse when I want to select 3 or more household members.

The other idea I had was to assign each household member a random number and then only show a household member if the random number corresponding to that member is greater than a certain threshold value (following this thread: https://groups.google.com/forum/#!msg/formhub-users/ndcyBG3I-og/2IiO0DlDYaEJ). But if I did that, I would not be able to ensure that the "right" number of household members is selected (i.e. if I want to select 4 household members, I will sometimes get 3, sometimes 5 etc). Unlike the OP on that thread, I do not know in advance the number of members on the roster so I can't generate the members to select in advance.

Is there another possibility? For example, could I assign each household member a random number, then pick the highest, second highest up to kth highest random numbers (where k is my sample size). That's what I would do in Stata - but I can't figure out a way of doing it here!

I didn't attach a mock xlsform since my problem is so related to the earlier one in the thread but I could attach one if that would be helpful.

Thanks a lot,
Sam

The once() should contain just the random number.

I.e., create a field "random_pick" calculate = "once(random())"

Then have the computed expression, "chosen_member":

if(count-selected(/data/membersinrange) = 0, 0,
int(1.0+count-selected(/data/membersinrange)*/data/random_pick))

The problem is that after the first time through the loop, javarosa detects that /data/membersinrange has changed, which triggers the evaluation of chosen_member, which assigns 1 to chosen_member.

The second time through the loop, you add a 2nd member, javarosa detects that /data/membersinrange has changed, and triggers a re-evaluation of chosen_member, but because of the once() function, the re-computation is prevented and remains 1.

This does mean that if you edit the form and delete or add more members, you will end up with a different chosen member. Only if the number of members is unchanged, will the chosen_member value also be unchanged.

Ok, I didn't know that. I wait for a response

Hi Pierre,

Please note that Mitch (and really everyone else on this list) provides free support in their spare time.

If you can't wait for a response, then I encourage you to hire one of the many ODK companies available at http://opendatakit.org/help/help-for-hire/

Thanks,

Yaw

--
Need ODK services? http://nafundi.com provides form design, server setup, professional support, and software development for ODK.

HI MITCH,
Please can you tell me what wrong with my program? Sure,i forget something important, byt idon't identify it.

thanks a lot

Hi,
I have to select randomly a member in a household survey. fisrt of all, I Ask for basic demographics in a repeat
group.

begin
repeat
member
roster

calculate
CR360
Member ID number

text
CR361
Member's Name

select_one
gender
CR371
Member's gender

integer
CR381
Member's age

date
CR391
Date of birth

end repeat
member

Then have a series of calculated field
that produce a space-separated list of the indices into that repeat group that
are within the designated age range.

calculate
ageok1

if(/data/member[1]/CR381 >= 5
and /data/member[1]/CR381 <= 15, ' 1', '')

calculate
ageok2

if(/data/member[2]/CR381 >= 5 and /data/member[2]/CR381
<= 15, ' 2', '')

calculate
ageok3

if(/data/member[3]/CR381 >= 5 and /data/member[3]/CR381
<= 15, ' 3', '')

calculate
ageok4

if(/data/member[4]/CR381 >= 5 and /data/member[4]/CR381
<= 15, ' 4', '')

calculate
ageok5

if(/data/member[5]/CR381 >= 5 and /data/member[5]/CR381
<= 15, ' 5', '')

calculate
membersinrange

substr(concat(${ageok1},${ageok2},${ageok3},${ageok4},${ageok5}),1)

And this function once to compute the chosen member once. But in my program , the note1 display nothing and the member chosen is 0. Can somebody help me?

note
note1
${membersinrange}

calculate
chosenmember

once(if(count-selected(/data/membersinrange) = 0, 0,
int(1.0+count-selected(/data/membersinrange)*random())))

note
Child
child's name is
${chosenmember}

--

--

Post: opend...@googlegroups.com

Unsubscribe: opendatakit...@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...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--

--

Post: opend...@googlegroups.com

Unsubscribe: opendatakit...@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...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--

--

Post: opend...@googlegroups.com

Unsubscribe: opendatakit...@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...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--

--

Post: opend...@googlegroups.com

Unsubscribe: opendatakit...@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...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
Mitch Sundt
Software Engineer
University of Washington
mitche...@gmail.com

Hi Sam,
Please, did you eventually figure out how to randomly select a subset of households, by I assigning each household member a random number, then picking the highest, second highest up to kth highest random numbers? I am trying to create a questionnaire that randomly generates a list of 5 villages from a group of villages being served by a primary health center.

I can't see how it was resolved from the thread.

Many thanks,
Yemi

Dear ODK'ers,
I am trying to create a questionnaire that randomly generates a list of 5 villages from a group of villages being served by a primary health center.

I can't see how it was resolved from this thread with a similar issue.

Does anyone know how to assign a random number to all villages and select the highest or lowest 5?

Or any other way to do this selection without replacement so that the same village is not selected more than once. So far, I can only select with replacement. My form is attached here if that will help.

Many thanks,
Yemi

villages.xlsx (22.8 KB)

··· On Monday, September 12, 2016 at 5:46:26 PM UTC-4, yemiok...@gmail.com wrote: > On Saturday, November 15, 2014 at 9:39:48 PM UTC-5, Samantha Burn wrote: > > On Saturday, 15 November 2014 20:52:38 UTC-5, Samantha Burn wrote: > > On Tuesday, 15 July 2014 19:23:34 UTC-4, Mitch Sundt wrote: > > On Mon, Jul 14, 2014 at 1:05 PM, Pierre Anthony Garraud wrote: > > 2014-07-14 16:01 GMT-04:00 Yaw Anokwa : > > On Mon, Jul 14, 2014 at 11:35 AM, Pierre Anthony Garraud wrote: > > 2014-07-13 10:09 GMT-04:00 Legarraudien :

"/data/member[/data/chosenmember]/name" i Have an error message like
this: There is no survey element with this name.
And i don't know which field has this relevant="/data/chosenmenber > 0"

··· On Thu, Jul 17, 2014 at 11:06 AM, Pierre Anthony Garraud < pagarraud1@gmail.com> wrote:

Hi Mitch,
I don't understand this
typo

chosenmenber

vs

chosenmember

2014-07-17 10:52 GMT-07:00 Mitch Sundt mitchellsundt@gmail.com:

typo

chosenmenber

vs

chosenmember

On Tue, Jul 15, 2014 at 7:20 PM, Pierre Anthony Garraud < pagarraud1@gmail.com> wrote:

Hi Mitch,
Sorry for all. This programm is very important for me. I count on Your
support to resolve this problem

I have an issue,I don't know how to referance the child's name. when I
use "/data/member[/data/chosenmember]/name" i Have an error message
like this: There is no survey element with this name.
And i don't know which field has this relevant="/data/chosenmenber > 0"

Thanks a lot

2014-07-15 17:34 GMT-07:00 Pierre Anthony Garraud pagarraud1@gmail.com
:

Hi Mitch,

Thanks a lot, I' ll try it

2014-07-15 16:23 GMT-07:00 Mitch Sundt mitchellsundt@gmail.com:

The once() should contain just the random number.

I.e., create a field "random_pick" calculate = "once(random())"

Then have the computed expression, "chosen_member":

if(count-selected(/data/membersinrange) = 0, 0,
int(1.0+count-selected(/data/membersinrange)**/data/random_pick*))
The problem is that after the first time through the loop, javarosa
detects that /data/membersinrange has changed, which triggers the
evaluation of chosen_member, which assigns 1 to chosen_member.
The second time through the loop, you add a 2nd member, javarosa
detects that /data/membersinrange has changed, and triggers a re-evaluation
of chosen_member, but because of the once() function, the re-computation is
prevented and remains 1.

This does mean that if you edit the form and delete or add more
members, you will end up with a different chosen member. Only if the number
of members is unchanged, will the chosen_member value also be unchanged.

On Mon, Jul 14, 2014 at 1:05 PM, Pierre Anthony Garraud < pagarraud1@gmail.com> wrote:

Ok, I didn't know that. I wait for a response

2014-07-14 16:01 GMT-04:00 Yaw Anokwa yanokwa@nafundi.com:

Hi Pierre,

Please note that Mitch (and really everyone else on this list)
provides free support in their spare time.

If you can't wait for a response, then I encourage you to hire one
of the many ODK companies available at
http://opendatakit.org/help/help-for-hire/

Thanks,

Yaw

Need ODK services? http://nafundi.com provides form design, server
setup, professional support, and software development for ODK.

On Mon, Jul 14, 2014 at 11:35 AM, Pierre Anthony Garraud < pagarraud1@gmail.com> wrote:

HI MITCH,
Please can you tell me what wrong with my program? Sure,i forget
something important, byt idon't identify it.

thanks a lot

2014-07-13 10:09 GMT-04:00 Legarraudien pagarraud1@gmail.com:

Hi,

I have to select randomly a member in a household survey. fisrt
of all, I Ask for basic demographics in a repeat group.

begin repeat member roster calculate CR360 Member ID number
text CR361 Member's Name select_one gender CR371 Member's gender
integer CR381 Member's age date CR391 Date of birth end repeat
member

Then have a series of calculated field that produce a
space-separated list of the indices into that repeat group that are within
the designated age range.
calculate ageok1 if(/data/member[1]/CR381 >= 5 and
/data/member[1]/CR381 <= 15, ' 1', '') calculate ageok2 if(/data/member[2]/CR381

= 5 and /data/member[2]/CR381 <= 15, ' 2', '') calculate ageok3 if(/data/member[3]/CR381
= 5 and /data/member[3]/CR381 <= 15, ' 3', '') calculate ageok4 if(/data/member[4]/CR381
= 5 and /data/member[4]/CR381 <= 15, ' 4', '') calculate ageok5 if(/data/member[5]/CR381
= 5 and /data/member[5]/CR381 <= 15, ' 5', '') calculate
membersinrange
substr(concat(${ageok1},${ageok2},${ageok3},${ageok4},${ageok5}),1)

And this function once to compute the chosen member once. But in
my program , the note1 display nothing and the member chosen is 0. Can
somebody help me?
note note1 ${membersinrange} calculate chosenmember once(if(count-selected(/data/membersinrange)
= 0, 0, int(1.0+count-selected(/data/membersinrange)*random())))
note Child child's name is ${chosenmember}

--

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.

--

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.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

--

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.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

--

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.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com