Assign participants to conditions in a specific order or counterbalance? (jsPsych)

369 views
Skip to first unread message

GJ

unread,
Oct 28, 2020, 3:49:18 AM10/28/20
to JATOS
Hello!

We're planning on running an online experiment through Prolific. The script was created in jsPsych and the experiment currently has 6 different possible timelines in the main bulk of the experiment. Originally, I've written a conditional statement within the script that generates a random integer (e.g. from 1-6) that corresponds to one of the 6 conditions and plays the appropriate trials for that condition. However, we want to actually counterbalance the conditions so there's an equal amount of participants run in each condition.

I saw an example file in the JATOS documentation that can basically assign and keeps track of which condition participants were placed in using the batchSession info from JATOS?. It provides the 'addCondition' file and the 3 possible conditions as separate experiment files (A, B or C). I'm pretty novice in understanding the workings of JATOS, so I'm a bit confused on how to modify it to work with my current experiment. I had a few starting questions regarding the logistics. I was wondering if it were possible to streamline it all into one file since I have all of the possible conditions written into my code already? Also, would it be possible to assign participants in a specific order (e.g. participant 1 gets condition 1, participant 2 gets condition 2 and so on until participant 7 gets condition 1 again and 8 gets condition 2, etc.)?

Any guidance would be appreciated! :) 

Elisa Filevich

unread,
Oct 28, 2020, 12:03:48 PM10/28/20
to JATOS
Hi, 

 I'm a bit confused on how to modify it to work with my current experiment. I had a few starting questions regarding the logistics. I was wondering if it were possible to streamline it all into one file since I have all of the possible conditions written into my code already?

The example you saw has two components (condition sorting: 1 and actual task: 2/3/4. The script in component 1 does two things:
- makes the decision to redirect to components 2/3/4 (i.e. tasks A/B/C) 
- does the actual redirect. 

If you want to use a single file containing all conditions that would also work. the easiest way is probably to:
- Add the component 1 from the example. That component-1 script will make the decision of which condition to assign
- Store the condition information on the Study session data (e.g. jatos.studySessionData = A”). This will make this information available to all components of the study
- Instead of redirecting to different components, Redirect always to the same one (jatos.startNextComponent)  
- In your jsPsych script, you must have some kind of if statement that evaluates the condition you’re in. Now, to get the value of that condition (determined by the previous component and transmitted through JATOS’ Study Session Data) simply get the value of  jatos.studySessionData. So
if(jatos.studySessionData == “A”){
Do your task under condition A;
}

Hope this helps, ask again if you need more clarification

Best
Elisa


Also, would it be possible to assign participants in a specific order (e.g. participant 1 gets condition 1, participant 2 gets condition 2 and so on until participant 7 gets condition 1 again and 8 gets condition 2, etc.)?
--
You received this message because you are subscribed to the Google Groups "JATOS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jatos+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jatos/363ba68e-f05a-4bca-bcc8-bad7fb0486dcn%40googlegroups.com.

Elisa Filevich

unread,
Oct 28, 2020, 1:01:36 PM10/28/20
to JATOS
Sorry, I didn’t answer your second question

On 28. Oct 2020, at 08:49, GJ <g-...@hotmail.com> wrote:

 Also, would it be possible to assign participants in a specific order (e.g. participant 1 gets condition 1, participant 2 gets condition 2 and so on until participant 7 gets condition 1 again and 8 gets condition 2, etc.)?

Sure, but you’d have to use the batch session data for this. It’s not super complex but if you say you have no experience with JS it might not be the best idea, a random assignment should work just fine. Right now the code does this randomly:

var randomIndex = Math.floor(Math.random() * conditions.length);
var randomCondition = conditions[randomIndex];

You’d have to modify the random selection to make it deterministic. You could do something along the following lines (in pseudocode):

For the first participant: (which you determine by seeing that the batch session data is empty)
conditionIndex = 0;
thisSubjsCondition = conditionIndex;
jatos.studySession.condition = thisSubjsCondition;
jatos.setBatchSessiondata = {‘lastConditionUsed' : thisSubjsCondition} #this will set a variable that is visible to all participants

For all other participants:
thisSubjsCondition = conditionIndex + 1; #and actually you should simply add 1, but instead make sure you’re cycling over your 7 conditions, probably by using the modulus operator
jatos.studySession.condition = thisSubjsCondition;
jatos.setBatchSessiondata = {‘lastConditionUsed' : thisSubjsCondition} #this will set a variable that is visible to all participants

Best
Elisa





GJ

unread,
Oct 29, 2020, 12:33:23 AM10/29/20
to JATOS
Hi Elisa,

Thanks for listing out all of the steps! I think we will just stick with the random assignment as I don't have sufficient JS knowledge at this time to try and code that. I just had another quick question about the random assignment. The example script basically just cycles through the conditions in random order while still assigning equal numbering to each condition, correct? Since the experiment will be run via Prolific, there will be multiple participants who start the study around the same time, but some will leave/not finish the study. Will the script account for unfinished study runs while assigning conditions for the following participants?

I've added the component containing that script as the first component in the study, separate from the main experiment. I've tried implementing the changes you mentioned, but I'm not sure if I've done it correctly -- do I need to change anything in the original script, other than the following:

- set "var randomCondition" as studySessionData?
Would I set it up like this at the end of the script after calling for the getNextCondition function?
var randomCondition = jatos.setStudySessionData(randomCondition);

- change jatos.startComponentbyPos to just jatos.startNextComponent;
jatos.submitResultData(resultData, function () {
jatos.startNextComponent();
});

- add the rest of the conditions (labelled as A-F for the 6 conditions) 
case "D":
nextComponentPosition = 4;
break;
case "E":
nextComponentPosition = 5;
break;
case "F":
nextComponentPosition = 6;
break;
}

Thanks for all of your help and patience! I really appreciate it. 

Elisa Filevich

unread,
Oct 29, 2020, 10:31:08 AM10/29/20
to JATOS
Hi, See my answers below. 

On 29. Oct 2020, at 5:33 AM, GJ <g-...@hotmail.com> wrote:

Hi Elisa,

Thanks for listing out all of the steps! I think we will just stick with the random assignment as I don't have sufficient JS knowledge at this time to try and code that. I just had another quick question about the random assignment. The example script basically just cycles through the conditions in random order while still assigning equal numbering to each condition, correct?
Yes

Since the experiment will be run via Prolific, there will be multiple participants who start the study around the same time, but some will leave/not finish the study. Will the script account for unfinished study runs while assigning conditions for the following participants?

No, it won't automatically account for that. You would have to change it yourself based on what a finished study constitutes. Is it completing all trials? Having a certain minimum accuracy?
This is tricky, though, because as you say many people might start at the same time. There's no real way out of that other than spreading people over time. 
 
I've added the component containing that script as the first component in the study, separate from the main experiment. I've tried implementing the changes you mentioned, but I'm not sure if I've done it correctly -- do I need to change anything in the original script, other than the following:

- set "var randomCondition" as studySessionData?
Would I set it up like this at the end of the script after calling for the getNextCondition function?
var randomCondition = jatos.setStudySessionData(randomCondition);
No, you would need two lines
var randomCondition = "A" (determined in some way)
jatos.studySessionData = randomCondition;


- change jatos.startComponentbyPos to just jatos.startNextComponent;
jatos.submitResultData(resultData, function () {
jatos.startNextComponent();
});

Yes, that's fine.
Better would be:
jatos.startNextComponent(resultData); #make sure that you are running JATOS v.3.3.1 or newer, otherwise leave it as you wrote it) 


- add the rest of the conditions (labelled as A-F for the 6 conditions) 
case "D":
nextComponentPosition = 4;
break;
case "E":
nextComponentPosition = 5;
break;
case "F":
nextComponentPosition = 6;
break;
}

I don't understand why you would need to have different component positions, as I thought that you wanted to have all conditions in a single component. 
What you would need to do is have *on the script of the second component* what (I presume) you already have

case "D":
#run your study under condition D
break;
case "E":
#run your study under condition E
break;
case "F":
#run your study under condition F
break;

etc

Best
Elisa


GJ

unread,
Oct 29, 2020, 1:39:01 PM10/29/20
to JATOS
Hi Elisa,

  • No, it won't automatically account for that. You would have to change it yourself based on what a finished study constitutes. Is it completing all trials? Having a certain minimum accuracy? This is tricky, though, because as you say many people might start at the same time. There's no real way out of that other than spreading people over time. 
Ah okay, I was thinking along the lines of someone starting the main part of the experiment, decide they do not want to participate any further and closing out of the experiment, therefore no result data would be published.

  • No, you would need two lines
    var randomCondition = "A" (determined in some way)
    jatos.studySessionData = randomCondition;
Sorry, I'm a bit confused here. Am I supposed to specify this for each possible condition at the end of the first script?

e.g.
var randomCondition = "A" 
jatos.studySessionData = randomCondition;
var randomCondition = "B"
jatos.studySessionData = randomCondition;

  • I don't understand why you would need to have different component positions, as I thought that you wanted to have all conditions in a single component. 
    What you would need to do is have *on the script of the second component* what (I presume) you already have
Ah okay. I do have an if-statement ready in my second script that looks like so far

if(jatos.studySessionData == “A”){
timeline.push(//run these trials);
} else if(jatos.studySessionData == “B”){
timeline.push(//run these trials);

Would I just keep that section in the first script like this then: 

$('#continueButton').click(function () {
var nextCondition = getNextCondition();
switch (nextCondition) {
case "A";
break;
case "B";
break;
case "C";
break;
case "D";
break;
case "E";
break;
case "F";
break;
}

with this section like so?

var conditions = [];
// Fill the array with conditions according to the counters
fillArrayWithValues(conditions, "A", conditionCounts.A);
fillArrayWithValues(conditions, "B", conditionCounts.B);
fillArrayWithValues(conditions, "C", conditionCounts.C);
fillArrayWithValues(conditions, "D", conditionCounts.D);
fillArrayWithValues(conditions, "E", conditionCounts.E);
fillArrayWithValues(conditions, "F", conditionCounts.F);

Thanks for your continued help (despite my novice skill in coding)! I appreciate you taking the time to help out.

Elisa Filevich

unread,
Oct 30, 2020, 10:33:26 AM10/30/20
to ja...@googlegroups.com
Hi, 

It's difficult to answer without the full context. If you send me a minimal version of your study (in -jzip format, with just the necessary elements for this to work) I'll have a look at this. 

Best

Reply all
Reply to author
Forward
0 new messages