- Posts: 1
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Show random subsample of groups
- lobster
- Topic Author
- Offline
- New Member
Less
More
4 years 3 months ago #192667
by lobster
Show random subsample of groups was created by lobster
Hi there,
I have a survey with 6 groups and want each participant to see randomly chosen 3 of them. I tried putting them all in the same randomization group and using a counter to limit the number shown to 3. However this counter does not behave like I would expect it to.
Anyone know a good solution on how to show a random sample of groups only?
I have a survey with 6 groups and want each participant to see randomly chosen 3 of them. I tried putting them all in the same randomization group and using a counter to limit the number shown to 3. However this counter does not behave like I would expect it to.
Anyone know a good solution on how to show a random sample of groups only?
The topic has been locked.
- Joffm
- Away
- LimeSurvey Community Team
Less
More
- Posts: 12933
- Thank you received: 3979
4 years 3 months ago #192670
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Show random subsample of groups
Hi, lobster,
1. with javascript
create a question of type "short text" and enter this snippet
You will get a string like
Now you can display your groups using the relevance equation:
group 1: strpos(Q1,"1")>0
group 2: strpos(Q1,"2")>0
...
Now you see the reason for the "#": To be able to distinguish between the index "0" and the result "0", meaning "not found".
2. Without javascript
There are only 20 different combination of 3 groups out of 6.
1: 1,2,3
2: 1,2,4
3: 1,2,5
4: 1,2,6
5: 1,3,4
6: 1,3,5
7: 1,3,6
8: 1,4,5
9: 1,4,6
10: 1,5,6
11: 2,3,4
12: 2,3,5
13: 2,3,6
14: 2,4,5
15: 2,4,6
16: 2,5,6
17: 3,4,5
18: 3,4,6
19: 3,5,6
20: 4,5,6
Create a random number 1-20 and display the groups accordingly.
Group 1: random<11
Group 2: (random<5) OR ((random>10) AND (random<17))
Group 3: (random==1) OR ((random>4) AND (random<) OR ((random>16) AND (random<20))
...
Joffm
1. with javascript
create a question of type "short text" and enter this snippet
Code:
<script type="text/javascript" charset="utf-8"> function shuffle(array) { var currentIndex = array.length, temporaryValue, randomIndex; // While there remain elements to shuffle... while (0 !== currentIndex) { // Pick a remaining element... randomIndex = Math.floor(Math.random() * currentIndex); currentIndex -= 1; // And swap it with the current element. temporaryValue = array[currentIndex]; array[currentIndex] = array[randomIndex]; array[randomIndex] = temporaryValue; } return array; } $(document).on('ready pjax:scriptcomplete',function(){ // Fill the array var arr = [1,2,3,4,5,6]; arr = shuffle(arr); anumbers = arr.slice(0,3).join(''); $('#question{QID} input[type="text"]').val("#"+anumbers); $('#question{QID}').hide(); }); </script>
You will get a string like
Now you can display your groups using the relevance equation:
group 1: strpos(Q1,"1")>0
group 2: strpos(Q1,"2")>0
...
Now you see the reason for the "#": To be able to distinguish between the index "0" and the result "0", meaning "not found".
2. Without javascript
There are only 20 different combination of 3 groups out of 6.
1: 1,2,3
2: 1,2,4
3: 1,2,5
4: 1,2,6
5: 1,3,4
6: 1,3,5
7: 1,3,6
8: 1,4,5
9: 1,4,6
10: 1,5,6
11: 2,3,4
12: 2,3,5
13: 2,3,6
14: 2,4,5
15: 2,4,6
16: 2,5,6
17: 3,4,5
18: 3,4,6
19: 3,5,6
20: 4,5,6
Create a random number 1-20 and display the groups accordingly.
Group 1: random<11
Group 2: (random<5) OR ((random>10) AND (random<17))
Group 3: (random==1) OR ((random>4) AND (random<) OR ((random>16) AND (random<20))
...
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: gabrieljenik
The topic has been locked.
- Joffm
- Away
- LimeSurvey Community Team
Less
More
- Posts: 12933
- Thank you received: 3979
4 years 3 months ago #192676
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Show random subsample of groups
3. Use QCode.gseq
manual.limesurvey.org/Expression_Manager...#Access_to_variables
Set the relevance equation of each group to
"G1Q1.gseq lt 4"
"G2Q1.gseq lt 4"
where GxQ1 is a question in this group which is aleays displayed.
...
As you read in the manual the count starts at "0". So you have to adapt the "4" of my example.
Joffm
I always take for granted that the groups have the same randomization group name.
manual.limesurvey.org/Expression_Manager...#Access_to_variables
Set the relevance equation of each group to
"G1Q1.gseq lt 4"
"G2Q1.gseq lt 4"
where GxQ1 is a question in this group which is aleays displayed.
...
As you read in the manual the count starts at "0". So you have to adapt the "4" of my example.
Joffm
I always take for granted that the groups have the same randomization group name.
Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
- okalmus
- Offline
- New Member
Less
More
- Posts: 1
- Thank you received: 0
4 years 3 months ago #192694
by okalmus
Replied by okalmus on topic Show random subsample of groups
Hi Joffm,
thank you very much for all your help. I went with the random number method, as it seemed the most straightforward to implement right away. I will look into the other options for future reference for sure.
Thanks again.
thank you very much for all your help. I went with the random number method, as it seemed the most straightforward to implement right away. I will look into the other options for future reference for sure.
Thanks again.
The topic has been locked.