Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

How can I achieve this kind of randomisation? 

  • AurélienULB
  • AurélienULB's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 10 months ago #241756 by AurélienULB
Please help us help you and fill where relevant:
Your LimeSurvey version: [see right hand bottom of your LimeSurvey admin screen]
Own server or LimeSurvey hosting:
Survey theme/template:
==================
(Write here your question/remark)Please help us help you and fill where relevant:
Your LimeSurvey version: Version 3.28.42+221213
Own server or LimeSurvey hosting:
Survey theme/template: Fruity 
==================
Hello !
I am asked to do a certain task in limesurvey but I'm not sure if it's possible; I have two conditions with 12 questions each, for which respectively, 6 questions have to be selected randomly to be first presented in the beginning of my questionnaire. Then, later in the questionnaire, I would like the remaining questions of each conditions (that were not selected in the first part) to be presented. (so that participant are not presented with the same stimuli in part 1 and 2)

How can I achieve this kind of "randomisation"? 

I would greatly appreciate it if you could help me out ! Thank you. 

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 10 months ago #241758 by Joffm
Hi,
unfortunately you did not provide a lss export of this.

The buzzword is "randomization group name"
Put the first 6 questions at the beginning and the rest at the end.
ALL questions get the same "randomization group name". 
Result: All 12 questions are shuffled, six are displayed at the beginning, six at the end.

But I do not understand where there are the two conditions.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

More
1 year 10 months ago #241761 by jelo

But I do not understand where there are the two conditions.
 
Looks like there are two groups of 12 questions (2x12). But that would still work with the solution you provided.
 

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users

Please Log in to join the conversation.

  • AurélienULB
  • AurélienULB's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 10 months ago - 1 year 10 months ago #241813 by AurélienULB
Replied by AurélienULB on topic How can I achieve this kind of randomisation? 
The following might convey more accurately the problem I'm facing: 
I have a group of questions that contains 24 images divided into two conditions: 12 images belonging to condition 1 and 12 images belonging to condition 2. At the beginning of my questionnaire I would like LimeSurvey to randomly select and present 6 images from condition 1 and 6 images from condition 2. At the end of my questionnaire I present this group of questions again, and I would like LimeSurvey to present 6 images from condition 1 and 6 images from condition 2 again, but the 12 images that will be presented cannot be the same as the ones that were presented at the beginning of the questionnaire.
Last edit: 1 year 10 months ago by AurélienULB.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 10 months ago - 1 year 10 months ago #241824 by Joffm
Well, now we understand.
But that's easy, too

In a question of type "multiple short text" (QImage) insert this javascript 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 arrays
    var arrA = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"];
    var arrB = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"];
    // Shuffle the arrays
    arrA = shuffle(arrA);
    arrB = shuffle(arrB);
 
    // Take the first 6 elements from both arrays, concat them and shuffle again
    var arrA1 = arrA.slice(0,6);
    var arrB1 = arrB.slice(0,6);
    var arr1 = arrA1.concat(arrB1);
    arr1 = shuffle(arr1).join('');;
 
    // Take the last 6 elements from both arrays, concat them and shuffle again
    arrA1 = arrA.slice(6,6);
    arrB1 = arrB.slice(6,6);
    var arr2 = arrA1.concat(arrB1);   
    arr2 = shuffle(arr2).join('');
 
    // Fill the text question
    $('#question{QID} input[type="text"]:eq(0)').val(arr1);
    $('#question{QID} input[type="text"]:eq(1)').val(arr2);
 
    // Remove the slashes in the next line 
//    $('#question{QID}').hide();
 });
</script>


You get something like this
 
Each subquestion contains six capital letters (Image Pool 1) and six small letters (Image Pool 2) ind randomized order.

Now you can address your images with
<img src="Image{substr(QImage_1,0,1)}.jpg" >
<img src="Image{substr(QImage_1,1,1)}.jpg" >
...
and for the second part
<img src="Image{substr(QImage_2,0,1)}.jpg" >
...

Meaning, you should rename your images to "imageA.jpg", "imageB.jpg",... "imagea.jpg", "imageb.jpg"

Joffm

If you have further questions, please send a lss export of your survey (these relevant questions / groups)

 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 year 10 months ago by Joffm.

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 10 months ago #241837 by tpartner
One small addition to Joffm's solution - if you need it dynamic within a page, you may need to trigger ExpressionScript like this:

Code:
$('#question{QID} input[type="text"]:eq(0)').val(arr1).trigger('keyup');

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: Joffm

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 10 months ago #241841 by Joffm
You can display the images in a different way, which may be better to analyze later-

1. Change these lines in the javascript  (and with tpartner's addition)
$('#question{QID} input[type="text"]:eq(0)').val(arr1);
$('#question{QID} input[type="text"]:eq(1)').val(arr2);


to
$('#question{QID} input[type="text"]:eq(0)').val('#'+arr1).trigger('keyup');
$('#question{QID} input[type="text"]:eq(1)').val('#'+arr2).trigger('keyup');


2a. Create questions for all 24 images at the beginning; all get the same "randomization group name"
2b. Create questions for all 24 images at the end; all get the same "randomization group name", but different from the first one.

3. Now you use the function "strpos" to decide if an image is displayed or not.
So the conditions for images at the beginning are
1st image: strpos(QImage_SQ001,"A")>0
2nd image: strpos(QImage_SQ001,"B")>0
...
12th image: strpos(QImage_SQ001,"L")>0
13th image: strpos(QImage_SQ001,"a")>0
...
24th image: strpos(QImage_SQ001,"l")>0

Only if QImage_SQ001 contains the character the image is displayed.
At the end the same, but with QImage_SQ002.

The advantage is:
Each images is always in the sae column of the database.
Disadvantage:
You waste 24 columns.

Why did I add the '#' at the beginning?
Without this, the result of "strpos(QImage_SQ002,"H")" - using the distribution of the previous screenshot - would be "0" (the function starts at "0")
But unfortunately "strpos(QImage_SQ002,"X")" also returns "0". Here it means "not found".

Therefore I make sure that the first valid index is "1".

Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • AurélienULB
  • AurélienULB's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 10 months ago #241887 by AurélienULB
Replied by AurélienULB on topic How can I achieve this kind of randomisation? 
Hello everyone ! Thank you for your answers ! 

The problem with your solution is that we cannot use "multiple short text" as we are working with slider values. Will it work with the same code? I linked the group of questions as you suggested, so you can see what we are working with. 

We are new to limesurvey and don't know much about coding, so I thank you very much for your patience ! 
 

Please Log in to join the conversation.

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 10 months ago #241900 by holch
Always provide LSS files, not LSG or LSQ (except if specificially requested).

Why? Because it is a lot more work for the volunteer helpers in the forum, who do this in their spare time.

A LSS file can be just imported and is ready. Now for LSG and LSQ files we need to first create a survey, hope that it is in the correct base language. And it is also lacking all the other survey wide settings that might have an impact.

Help us to help you.

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 10 months ago - 1 year 10 months ago #241902 by Joffm
As @holch.
but these are conditons/relevance equations on question/group level.

So the type of questions is irrelevant.

Send a lss export.

Joffm 

I had a look at your "lsg".
And:
You did not insert the question "QImage" with the javascript snippet.
I called it QImage because you talked about "images"

I have a group of questions that contains 24 images divided into two conditions: 12 images belonging to condition 1 and 12 images belonging to condition

Your questions do not have a "randomization group name"

2a. Create questions for all 24 images at the beginning; all get the same "randomization group name"
2b. Create questions for all 24 images at the end; all get the same "randomization group name", but different from the first one.


Your questions do not have a "relevance equation" or "condition" (the wording differs in LS versions)

3. Now you use the function "strpos" to decide if an image is displayed or not.
So the conditions for images at the beginning are
1st image: strpos(QImage_SQ001,"A")>0
2nd image: strpos(QImage_SQ001,"B")>0

Do it and send this lss.



 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 year 10 months ago by Joffm.

Please Log in to join the conversation.

  • AurélienULB
  • AurélienULB's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 9 months ago #242031 by AurélienULB
Replied by AurélienULB on topic How can I achieve this kind of randomisation? 
Hello Joffm, 

Thank you for your reply, 

Here is the lss file. 

I did what you suggested: 

- A different "randomization group name" for the questions at the beginning and at the end. 
- Insert the javascript snippet for the two first qestions named "ATT1" and "ATT2" - is it correctly done? 
I want to be sure that I'm modifying the rights things before applying it to all the questions..

Where do I have to apply the "strpos" function exactly?

Thank you for your time, 

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 9 months ago - 1 year 9 months ago #242035 by Joffm
Hi,
I assume that Scalar 1 and Scalar 2 are the interesting groups.

So, you still did not
You did not insert the question "QImage" with the javascript snippet.
I wrote

In a question of type "multiple short text" (QImage) insert this javascript snippet

NOT in the questions you want to filter. Best you insert it into your first group.

Your questions do not have a "randomization group name". 
ALL questions of the group get this name. I think you want to display them in random order.

Where do I have to apply the "strpos" function exactly?

Your questions do not have a "relevance equation" or "condition" (the wording differs in LS versions)

3. Now you use the function "strpos" to decide if an image is displayed or not.
So the conditions for images at the beginning are
1st image: strpos(QImage_SQ001,"A")>0

 

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 year 9 months ago by Joffm.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose