Welcome to the LimeSurvey Community Forum

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

Search Results (Searched for: random)

  • Maddie.Storm
  • Maddie.Storm's Avatar
13 Apr 2024 15:42
Replied by Maddie.Storm on topic Randomization 50:50
Hi! Thank you so much for responding. I just tried to do it, but I think I still have a problem. My questions are in array form and they have to stay that way. It is for the scale validity in our study, and it seems like the equation style would not work for the length and look of the array.
So, is there any way to randomize arrays 50:50? Is there a code for these? Where do I put each code?

Also, how do I do this: "You need to check if this random number already exists before you create it new."? How do I assign one question as 1 and the other as 2? Does this go into the condition box?

Thanks so much! I am very new to LimeSurvey. 
  • tpartner
  • tpartner's Avatar
12 Apr 2024 14:06
This should do it:

Code:
<script type="text/javascript">
    $(document).on('ready pjax:scriptcomplete',function(){
 
        function shuffleArray(array) {
            for (var i = array.length - 1; i > 0; i--) {
                var j = Math.floor(Math.random() * (i + 1));
                var temp = array[i];
                array[i] = array[j];
                array[j] = temp;
            }
            return array;
        }
 
        // Merge function
        function mergeArrays(array1, array2) {
            var mergedArray = [];
            var maxLength = Math.max(array1.length, array2.length);
 
            for (var i = 0; i < maxLength; i++) {
                if (i < array2.length) {
                    mergedArray.push(array2[i]);
                }
                if (i < array1.length) {
                    mergedArray.push(array1[i]);
                }
            }
 
            return mergedArray;
        }
 
        //Identify this question
        var thisQuestion = $('#question{QID}');
        var thisAnswerList = $('tr.answers-list:eq(0)', thisQuestion).parent();
        var thisTable = $('table.subquestion-list:eq(0)', thisQuestion);
 
        // Special codes appear after
        var afterCode = 4;
 
        //Array for K Codes
        var array_k = ["b","d","g","h","i","j","l"];
 
        //Array for N Codes
        var array_n = ["c","e","f","k","m","n"];
 
        //Array for Special K Codes
        var array_sk = [];
 
        //Array for Special N codes
        var array_sn = ["a"];
 
        //Array for super special codes
        var array_ss = ["p"];
 
        // Shuffle order of "normal" arrays
        shuffleArray(array_k);
        shuffleArray(array_n);
 
        // Slice "normal" arrays and merge second part to special codes
        array_sk = array_sk.concat(array_k.slice(afterCode));
        array_sn = array_sn.concat(array_n.slice(afterCode));
 
        // Save only first part of "normal" arrays
        array_k = array_k.slice(0, afterCode);
        array_n = array_n.slice(0, afterCode);
 
        // Shuffle special arrays
        shuffleArray(array_sk);
        shuffleArray(array_sn);
        shuffleArray(array_ss);
 
        // Combine normal and special arrays
        array_k = array_k.concat(array_sk);
        array_n = array_n.concat(array_sn);
 
        // Merge arrays in order n,k,n,k...
        var array_res = mergeArrays(array_k, array_n);
 
        //Add super special array to end of result array
        array_res = array_res.concat(array_ss);
 
        // Loop through the answer codes
        $.each(array_res, function(i, val) {
            // Move the answer item
            $(thisAnswerList).append($('tr.answers-list[id$="X{QID}'+val+'"]', thisQuestion));
        });
 
        // Fix up the row background colours
        $('tr.answers-list', thisQuestion). each (function(i){
            $(this).removeClass('ls-even ls-odd');
            if(i % 2 == 0) {
                $(this).addClass('ls-even');
            }
            else {
                $(this).addClass('ls-odd');
            }
        });
 
    });  
 
</script>

Sample survey: 

File Attachment:

File Name: limesurvey...3181.lss
File Size:41 KB
  • holch
  • holch's Avatar
11 Apr 2024 22:36
Replied by holch on topic Randomisierung auf zwei Ebenen
Genau so funktioniert es.
  • holch
  • holch's Avatar
11 Apr 2024 21:47
Replied by holch on topic Randomization 50:50
Creating a 50/50 chance is easy, there have been many posts about this in the forum. You basically create a random number between 1 and 2 within a equation type question and then use the relevance equation / condition of the question to show / hide it depending on the number that has been drawn.

However, to make sure you don't run into trouble, you shouldn't just create a random number via {rand(1,2)}, but you need to check if this random number already exists, before you create it new.

Why is this important? Because otherwise you are running the risk that the random number changes for the same participant. Because with {rand(1,2)} the "dice are rolled everytime this equation question is called.
Code:
{if(is_empty(randnumber),rand(1,2),randnumber.NAOK)}
  • Maddie.Storm
  • Maddie.Storm's Avatar
11 Apr 2024 18:45
Randomization 50:50 was created by Maddie.Storm
Hi!
I am looking to randomize the Modified GMSEX here and the Fully Modified GMSEX here. When participants get to this stage of the survey, I need it to be 50/50 chance of getting either one. 
How do I do this? Is there a code? If so, where does this go?

Thanks!
  • BBSR-SR5
  • BBSR-SR5's Avatar
11 Apr 2024 13:56
Hm I tried adding that to my code, but it doesn't seem to do anything.
Code:
<script type="text/javascript" data-author="Tony Partner">
  $(document).on('ready pjax:scriptcomplete',function(){
 
 
    function shuffleArray(array) {
    for (var i = array.length - 1; i > 0; i--) {
        var j = Math.floor(Math.random() * (i + 1));
        var temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    }
    return array;
}
 
    // Merge function
        function mergeArrays(array1, array2) {
            var mergedArray = [];
            var maxLength = Math.max(array1.length, array2.length);
 
            for (var i = 0; i < maxLength; i++) {
                if (i < array2.length) {
                    mergedArray.push(array2[i]);
                }
                if (i < array1.length) {
                    mergedArray.push(array1[i]);
                }
            }
 
            return mergedArray;
        }
 
    //Identify this question
    var thisQuestion = $('#question{QID}');
    var thisAnswerList = $('tr.answers-list:eq(0)', thisQuestion).parent();
    var thisTable = $('table.subquestion-list:eq(0)', thisQuestion);
 
    // Special codes appear after
        var afterCode = 4;
 
        //Array for K Codes
        var array_k = ["b","d","g","h","i","j","l"];
 
        //Array for N Codes
        var array_n = ["c","e","f","k","m","n"];
 
        //Array for Special K Codes
        var array_sk = [];
 
        //Array for Special N codes
        var array_sn = ["a"];
 
        //Array for super special codes
        var array_ss = ["p"];
 
    // Shuffle order of "normal" arrays
        shuffleArray(array_k);
        shuffleArray(array_n);
 
        // Slice "normal" arrays and merge second part to special codes
        array_sk = array_sk.concat(array_k.slice(afterCode));
        array_sn = array_sn.concat(array_n.slice(afterCode));
 
        // Save only first part of "normal" arrays
        array_k = array_k.slice(0, afterCode);
        array_n = array_n.slice(0, afterCode);
 
        // Shuffle special arrays
        shuffleArray(array_sk);
        shuffleArray(array_sn);
        shuffleArray(array_ss);
 
        // Combine normal and special arrays
        array_k = array_k.concat(array_sk);
        array_n = array_n.concat(array_sn);
 
        // Merge arrays in order n,k,n,k...
        var array_res = mergeArrays(array_k, array_n);
 
        //Add super special array to end of result array
        array_res = array_res.concat(array_ss);
 
 
 
 
    // Loop through the answer codes
    $.each(array_res, function(i, val) {
      // Move the answer item
      $(thisAnswerList).append($('tr.answers-list[id$="X{QID}'+val+'"]', thisQuestion));
    });
 
 
 
 
    // Fix up the row classes
        var rowClass = 1;
        $('tr.answers-list', thisTable).each(function(i) {
            $(this).addClass('array'+(2-(i%2)));
        });
 
 
    });
 
 
 
</script>

Do I need to adjust something I've missed?
  • BBSR-SR5
  • BBSR-SR5's Avatar
10 Apr 2024 18:20
Thank you, this works great. I managed to adjust it for our use case to make sure certain items are displayed in a certain order.

There is just one issue I've run into and that's how the matrix has an underlying color pattern which gets distributed in interesting ways:


Is there some way to redraw the coloration after the shuffling/randomisation process is finished?
  • ElsaBoulard
  • ElsaBoulard's Avatar
10 Apr 2024 17:00 - 10 Apr 2024 17:18
Actuellement, je travaille sur un questionnaire visant à évaluer différents aspects liés à 30 métiers. Chaque métier comporte plusieurs questions. Pour limiter le nombre de participants nécessaires à des fins statistiques, je voudrais que chaque participant évalue trois métiers.J'ai réussi à effectuer une première randomisation avec la fonction rand(1,30), où 30 représente le nombre de groupes de questions correspondant à chaque métier. Cependant, je rencontre des difficultés pour effectuer une deuxième randomisation (et encore plus pour la troisième).

J'ai essayé plusieurs approches, y compris l'insertion d'une question cachée nommée random2. Cependant, je ne parviens pas à appliquer l'équation conditionnelle "random == 1 AND random2 == 1" aux groupes de métiers, car cela entraîne un dysfonctionnement complet du questionnaire.

Je préférerais éviter de créer 30 nouveaux groupes avec des codes différents, car cela serait fastidieux à réorganiser, surtout que je souhaite obtenir TROIS évaluations pour chaque participant.Enfin, je me demande s'il est possible d'ajouter une fonctionnalité permettant aux participants de "recommencer" le questionnaire, afin qu'ils soient redirigés aléatoirement vers un autre groupe.
  • Joffm
  • Joffm's Avatar
09 Apr 2024 21:03
  • PabloSantos
  • PabloSantos's Avatar
09 Apr 2024 20:45
Randomization - Array - Subquestions was created by PabloSantos
Hi!
I am wondering if there is any way to randomize subquestions within an array. Is there a code for this I can put in to randomize them? I have 10 subquestions, and they need to be random every time a participant does the survey.



Thanks!
  • par.a.dis
  • par.a.dis's Avatar
09 Apr 2024 16:38
Replied by par.a.dis on topic Randomisierung auf zwei Ebenen
Danke für die schnelle Antwort!

Tatsächlich haben ich nicht an diese Differenzierung gedacht. Das ändert einiges, denn das bedeutet ja nun, dass es doch zwei verschiedene Vorgehensweisen sind.

Wäre dieses Vorgehen folglich richtig?:

Zunächst wird eine Fragegruppe erstellt, in der die Zufallsvariabel mittels der Gleichung if(is_empty(gleichung), rand(1, 2), gleichung) generiert wird.
Daraufhin erstelle ich 12 Fragegruppen (6 für Gruppe 1 und 6 für Gruppe 2) und bestimme die Zuteilung dieser Fragegruppen zu Gruppe 1 und 2 über das Ausfüllen der Relevanzgleichung mit entweder gleichung==1 oder gleichung==2.
Um die Fragegruppen innerhalb der zwei between-subject Gruppen zu randomisieren, gebe ich bei 6 zusammenhängenden Fragegruppen in der Zeile "Randomisierungsgruppe" einen identischen String ein und mache das gleiche auch für die anderen 6 zusammenhängenden Fragegruppen, nur hier mit einem anderen String.

Danke vielmals schonmal für das Feedback!
  • Joffm
  • Joffm's Avatar
09 Apr 2024 15:11
Replied by Joffm on topic Randomisierung auf zwei Ebenen
Hallo,
Du benutzt das Wort "randomisiert" in zwei völlig verschiedenen Bedeutungen; das fordert Missverständnisse heraus.

1. Du willst pro Teilnehmer 1 von 2 Gruppen auswählen
Bedeutet: Ein Element aus n wird zufällig ausgewählt
Hier ist das Stichwort "Zufallszahl"

2. Du willst Fragegruppen in unterschiedlicher Reihenfolge anzeigen
Bedeutet: Alle diese Elemente werden angezeigt, allerdings in zufälliger Reihenfolge
Hier ist das Stichwort "Randomisierungsgruppe"

Joffm
 
  • par.a.dis
  • par.a.dis's Avatar
09 Apr 2024 13:57
Randomisierung auf zwei Ebenen was created by par.a.dis
Bitte helfen Sie uns, Ihnen zu helfen und füllen Sie folgende Felder aus:
Ihre LimeSurvey-Version: 3.28.40+221129
Eigener Server oder LimeSurvey-Cloud: Cloud
Genutzte Designvorlage:fruity
==================
Liebe Community,

ich nutze LimeSurvey für die Umsetzung meiner Studie der Masterthesis. Bei der Studie handelt es sich um ein  Mixed-Design, also ein between-subject und within-subject design in einem. Das heißt, Teilnehmende werden zunächst zufällig! in zwei Gruppen aufgeteilt (between-subject). Jede*r Teilnehmer*in wird dann mit 6 Bildern und dazugehörigen Fragen konfrontiert (jedes Bild+Fragen ist eine eigenständige Fragegruppe). Nun soll die Reihenfolge, in der diese Fragegruppen (Bilder+Fragen) jeder Person gezeigt werden, auch randomisiert werden.
Wie die erste randomisierte Aufteilung erfolgt, kann ich völlig nachvollziehen. Allerdings fehlt mir der Weg, die voranschreitende Randomisierung nach bereits einer getätigten Randomisierung, einzubauen. Ich stehe vor einer kompletten Lösungsansatz-Blockade, die mich selbst am Herumprobieren hindert, da ich schlicht nicht weiß, wie ich im zweiten Schritt vorgehen könnte. 

Meine Frage lautet vereinfacht: Wie behalte ich die erste randomisierte Zuteilung - in Gruppe 1 oder 2 - bei, wenn daraufhin in den besagten Gruppen 1 und 2 nochmal mehrere randomisierte Präsentationen vorgenommen werden sollen. 

Ich hoffe sehr, das mein Anliegen einigermaßen nachvollziehbar beschrieben worden ist.
Ich bin für jede noch so kleine Hilfe oder einen Hinweis extrem dankbar und spreche jetzt schon ein großes Dankeschön dafür aus.

Viele Grüße,
Sara
  • Joffm
  • Joffm's Avatar
08 Apr 2024 11:58
Hi,
here I used the script originally thought for mantaining survey wide randomization.
Code:
<script type="text/javascript" data-author="Tony Partner">
  $(document).on('ready pjax:scriptcomplete',function(){
 
function shuffleArray(array) {
    for (var i = array.length - 1; i > 0; i--) {
        var j = Math.floor(Math.random() * (i + 1));
        var temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    }
    return array;
}
    
    
    //Identify this question
    var thisQuestion = $('#question{QID}');
    var thisAnswerList = $('tr.answers-list:eq(0)', thisQuestion).parent();
 
    // Special codes appear after
    var afterCode=4;
    
    // Fill the array with "normal" codes
    var array1=[1,3,4,5,7];
    
    // Fill the array with "special" codes
    var array2=[2,6];
    shuffleArray(array1);
    array2=array2.concat(array1.slice(afterCode));
    array1=array1.slice(0,afterCode);
    shuffleArray(array2);
    array1=array1.concat(array2);
 
    // Loop through the answer codes
    $.each(array1, function(i, val) {
      // Move the answer item
      $(thisAnswerList).append($('tr.answers-list[id$="X{QID}'+val+'"]', thisQuestion));
    });
  });
</script>





Joffm
  • Joffm
  • Joffm's Avatar
07 Apr 2024 18:15 - 07 Apr 2024 18:17

So, create a random number in a question of type "equation"
Like {if(is_empty(randnbr),rand(1,2),randnbr)}

Of course the question code has to be "randnbr".
Now your variable "randnbr" will be either equal 1 or equal 2.

and set the condition of your groups.
Either randnbr==1
or randnbr==2

What is a condition?
A condition os a logical term that can be TRUE or FALSE.
If TRUE the group / question / subquestion is displayed, if FALSE not.

Now if you set the condition of group 1 to "randnbr==1" this group is only displayed if "randnbr" has the value "1"

Joffm

 
Displaying 46 - 60 out of 653 results.

Lime-years ahead

Online-surveys for every purse and purpose