random scenarios within groups should not change

9 views
Skip to first unread message

Donato Pierno

unread,
Mar 12, 2025, 2:21:14 PM3/12/25
to LIONESS Lab help and discussion
Dear Lioness Lab Team,

I am developing my experiment, and after the matching is done, I would like to show the subjects in the same groups the same sequence of 26 scenarios(randomly drawn from another set between 1 and 56).

After the stage lobby, I wrote this js code that works well in some online console, but the result in LIONESS is not what I would like to achieve. In the screenshot, you can see how the two subjects in group 1 receive different values for the scenarios and the paid ones as well.

Could you please help me in fixing my mistakes?

The code I use is the following:

const subjectgroup = getValue('groupNr');
 
const range = (start, stop, step) =>
    Array.from(
        { length: Math.ceil((stop - start) / step) },
        (_, i) => start + i * step,
    );

const allScenarios = range(1, 57, 1);

const imageMap = new Map(allScenarios.map(scenario => [scenario, '']));

const generateGroupScenario = () => {
    const groupScenarioSet = new Set();

    while (groupScenarioSet.size < 26) {
        const scenario = Math.floor(Math.random() * allScenarios.length);
        const scenarioValue = allScenarios[scenario];
        if (scenarioValue !== 0 && !groupScenarioSet.has(scenarioValue)) {
            groupScenarioSet.add(scenarioValue);
        }
    }

    return groupScenarioSet;
};

(() => {
    const numberOfGroups = 3;
    const groupScenarios = [];
     // Dichiarazione di subjectgroup

    for (let i = 0; i < numberOfGroups; i++) {
        const gs = generateGroupScenario();
        const scenarioArray = Array.from(gs);
        const scenario = scenarioArray.map((s, index) => ({
            group: ` ${i + 1}`,
            name: `Scenario ${index + 1}`,
            id: s,
        }));

        // Aggiungi PayedScenario
        const payedScenarioIndex = Math.floor(Math.random() * 26);
        const payedScenarioId = scenarioArray[payedScenarioIndex];
        const payedScenario = {
            group: `${i + 1}`,
            name: 'PayedScenario',
            id: payedScenarioId,
        };

        scenario.push(payedScenario);
        groupScenarios.push(scenario);
    }
    //trova l'indice dell'array che corrisponde al subjectgroup
    const groupIndex = groupScenarios.findIndex(group => parseInt(group[0].group.split(" ")[1]) === subjectgroup);

    if (groupIndex !== -1) {
        //crea le variabili scenario
        const selectedGroup = groupScenarios[groupIndex];
var Scenario1 = selectedGroup[0].id;
var Scenario2 = selectedGroup[1].id;
var Scenario3 = selectedGroup[2].id;
var Scenario4 = selectedGroup[3].id;
var Scenario5 = selectedGroup[4].id;
var Scenario6 = selectedGroup[5].id;
var Scenario7 = selectedGroup[6].id;
var Scenario8 = selectedGroup[7].id;
var Scenario9 = selectedGroup[8].id;
var Scenario10 = selectedGroup[9].id;
var Scenario11 = selectedGroup[10].id;
var Scenario12 = selectedGroup[11].id;
var Scenario13 = selectedGroup[12].id;
var Scenario14 = selectedGroup[13].id;
var Scenario15 = selectedGroup[14].id;
var Scenario16 = selectedGroup[15].id;
var Scenario17 = selectedGroup[16].id;
var Scenario18 = selectedGroup[17].id;
var Scenario19 = selectedGroup[18].id;
var Scenario20 = selectedGroup[19].id;
var Scenario21 = selectedGroup[20].id;
var Scenario22 = selectedGroup[21].id;
var Scenario23 = selectedGroup[22].id;
var Scenario24 = selectedGroup[23].id;
var Scenario25 = selectedGroup[24].id;
var Scenario26 = selectedGroup[25].id;

        //crea la variabile payedscenario
        var payedscenario = selectedGroup[26].id;
        record('Payedscenario', payedscenario);
       
record('Scenario1', Scenario1);
record('Scenario2', Scenario2);
record('Scenario3', Scenario3);
record('Scenario4', Scenario4);
record('Scenario5', Scenario5);
record('Scenario6', Scenario6);
record('Scenario7', Scenario7);
record('Scenario8', Scenario8);
record('Scenario9', Scenario9);
record('Scenario10', Scenario10);
record('Scenario11', Scenario11);
record('Scenario12', Scenario12);
record('Scenario13', Scenario13);
record('Scenario14', Scenario14);
record('Scenario15', Scenario15);
record('Scenario16', Scenario16);
record('Scenario17', Scenario17);
record('Scenario18', Scenario18);
record('Scenario19', Scenario19);
record('Scenario20', Scenario20);
record('Scenario21', Scenario21);
record('Scenario22', Scenario22);
record('Scenario23', Scenario23);
record('Scenario24', Scenario24);
record('Scenario25', Scenario25);
record('Scenario26', Scenario26);
       
       
       
       
       
        //stampa le variabili create
        console.log(`scenario1: ${Scenario1}`);
        console.log(`scenario2: ${Scenario2}`);
        console.log(`scenario3: ${Scenario3}`);
        console.log(`scenario4: ${Scenario4}`);
        console.log(`scenario5: ${Scenario5}`);
        console.log(`scenario6: ${Scenario6}`);
        console.log(`scenario7: ${Scenario7}`);
        console.log(`scenario8: ${Scenario8}`);
        console.log(`scenario9: ${Scenario9}`);
        console.log(`scenario10: ${Scenario10}`);
        console.log(`scenario11: ${Scenario11}`);
        console.log(`scenario12: ${Scenario12}`);
        console.log(`scenario13: ${Scenario13}`);
        console.log(`scenario14: ${Scenario14}`);
        console.log(`scenario15: ${Scenario15}`);
        console.log(`scenario16: ${Scenario16}`);
        console.log(`scenario17: ${Scenario17}`);
        console.log(`scenario18: ${Scenario18}`);
        console.log(`scenario19: ${Scenario19}`);
        console.log(`scenario20: ${Scenario20}`);
        console.log(`scenario21: ${Scenario21}`);
        console.log(`scenario22: ${Scenario22}`);
        console.log(`scenario23: ${Scenario23}`);
        console.log(`scenario24: ${Scenario24}`);
        console.log(`scenario25: ${Scenario25}`);
        console.log(`scenario26: ${Scenario26}`);
        console.log(`payedscenario: ${payedscenario}`);
    }

    console.log(groupScenarios);
    console.log('ciao');
})();


Thanks in advance for your help.


Screenshot 2025-03-12 191340.png

in...@lioness-lab.org

unread,
Mar 13, 2025, 3:51:02 AM3/13/25
to Donato Pierno, LIONESS Lab help and discussion

Hi Donato,

 

You could use the groupNr to set a “seed” for the JavaScript random number generation. See, e.g., https://stackoverflow.com/questions/16801687/javascript-random-ordering-with-seed

 

Alternatively, you could retrieve the relevant scenario for all group members from a single group member:

 

relevantScenario = getValue(“decisions”, “groupNr=”+groupNr + “ and subjectNr=1”, “Scenario1”) and use that.

 

NB: it might be that long series of “setValue()” commands in your code make the experiment a bit slow. You could consider saving the series of scenarios as a comma separated string in a single variable (e.g., called “Scenarios”), retrieve that based on the above procedure, and parse it using string .split(‘,’).

 

Hope this helps.

 

Cheers,

Lucas

 

PS: note that my Outlook changes apostrophe characters (from straight to curly) so copying code into LIONESS Lab may require changing the curly apostrophes to straight ones.

--
You received this message because you are subscribed to the Google Groups "LIONESS Lab help and discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lioness-lab...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/lioness-lab/eb1c0bb9-5c82-483f-98aa-0b0b7d4f0ca7n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages