Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simulation mode: survey-multi-select does not allow empty responses #3072

Open
nikbpetrov opened this issue Jun 20, 2023 · 0 comments
Open

Comments

@nikbpetrov
Copy link
Contributor

Problem statement

The way the simulation mode for the survey-multi-select is set up is not only having the RT hard-coded (see line 343) but also does not account for cases where data.response might be empty.

E.g. say I have simulations options defined like so:

data: function () {
    const valid_responses_prop = 0.50
    if (jsPsych.randomization.sampleBernoulli(valid_responses_prop)) {
        return {rt: 100}
    } else {
        return {rt: null, response: null}
    }
}

where the expected output is that in 50% of the cases I get random responses (as generated by the plugin) after 100ms and in the other 50% of cases I would expect the response to be null.

2 issues:

  1. If data.response is null, the simulate_visual errors when defining answers, line 322
  2. if rt is null, there is no way to end the trial as this one does not support trial_duration

Solution

Apart from the fact that I don't quite understand why there is no trial_duration for this one, the solution I've implemented for myself is by first defining the simulation options like this:

data: function () {
    const valid_responses_prop = 0.50
    if (jsPsych.randomization.sampleBernoulli(valid_responses_prop)) {
        return {rt: 100}
    } else {
        return {rt: 100, response: null}
    }
}

(notice how the rt is 100 for both now)

and then check if data.response is null in simulate_visual function -- if it is, then we end the trial after data.rt (in this case, 100ms) using setTimeout, inside of which we call jsPsych.finishTrial(new_data), wherein new_data is the same as data but the rt is changed to be null

in code (notice that in my setup I've also got rid of the hardcoded 1000):

simulate_visual(trial, simulation_options, load_callback) {
    const data = this.create_simulation_data(trial, simulation_options);
    const display_element = this.jsPsych.getDisplayElement();
    this.trial(display_element, trial);
    load_callback();
    if (data.response != null) {
      const answers = Object.entries(data.response);
      for (let i = 0; i < answers.length; i++) {
          for (const a of answers[i][1]) {
              this.jsPsych.pluginAPI.clickTarget(display_element.querySelector(`#jspsych-survey-multi-select-response-${i}-${trial.questions[i].options.indexOf(a)}`), ((data.rt - data.rt) / answers.length) * (i + 1));
          }
      }
      this.jsPsych.pluginAPI.clickTarget(display_element.querySelector("#jspsych-survey-multi-select-next"), data.rt);
    } else {
      this.jsPsych.pluginAPI.setTimeout(() => {
          let new_data = _.merge(_.cloneDeep(data), {rt: null})
          this.jsPsych.finishTrial(new_data)
      }, data.rt)
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant