How do I encode a condition matching technique into my program?

111 Views Asked by At

I am new to programming and am currently trying to use jsPsych to create a browser-based behavior experiment.

In my experiment, participants first complete a "pre-trial" in which they rate various pictures:

var scale_1 = ["Do not enjoy", "Neutral", "Enjoy"];

var pre_trial = {
    timeline: [{
        type: 'survey-likert',
        preamble: jsPsych.timelineVariable('image'),
        questions: [{labels: scale_1, prompt: "The prompt"}]
    }],
    timeline_variables: [
       {image: 'image address'},
       {image: 'image address'},
       {image: 'image address'}
    ]
};

Then, I use the ratings to divide the images into two conditions, A and B. This division process uses matching such that, ultimately, the images that received a "Do not enjoy" rating are evenly distributed between Condition A and Condition B, as are the images rated "Neutral" and the ones rated "Enjoy."

Unfortunately, I cannot figure out how to perform this matching procedure. I have tried many different combinations of various JavaScript and jsPsych functionalities, such as pop( ), splice( ), concat( ), jspsych.data.get( ).select('response'), and many more. However, all of them have failed.

Does anyone here have experience with matched condition assignment in jsPsych, or any idea about how to do it? If so, would you please consider sharing your ideas here? I know that there is a GitHub forum dedicated to jsPsych, but I figured I would ask my question here as well since I am struggling so much to find the answer.

1

There are 1 best solutions below

0
On

I think maybe you can divide your whole experiment into four parts: pretrial, do-not-enjoy, neutral, enjoy.

In the pretrial, there are only pretrial and the function of jumping to the page depending on the answer participants give.

The last three parts are the same, they can distribute the participants into condition A or condition B randomly. (And depends on the platform you host, you can pass an url parameter to the second part to link the data)

// pre_trial is omitted here
jsPsych.init({
    timeline: [pre_trial],
on_finish: function(data) {
        var url;
        if (data.values()[0].response =="Neutral"){
          url = "http://...." // the url of neutral part
        }else if (data.values()[0].response =="Enjoy"){
          url = "http://...." // the url of Enjoy part
        }else if (data.values()[0].response =="Not Enjoy"){
          url = "http://...." // the url of Not Enjoy part
        }
        window.open(url)
    }
});