jsPsych icon indicating copy to clipboard operation
jsPsych copied to clipboard

Adding `minimum_trial_duration` parameter to plugins

Open JAQuent opened this issue 4 years ago • 7 comments

Background

I propose to add a paramater that I would call response_ends_trial_after_stimulus_duration that as the name says ends a trial when a response is given and the provided stimulus_duration elapsed. Currently, the parameter response_ends_trial ignores stimulus duration that can be fine in a lot circumstances but can be problematic for certain types of experiments.

For instance in the field of memory research, we typically want our stimulus to be presented for the same duration during a learning phase regardless whether a response is given. This is important as we want to be able contrast conditions that might come with different RTs. My proposed feature would ensure that even if Condition A is faster than Condition B, stimuli in both conditions are displayed for the same duration allowing me attribute a subsequent memory effect to something other than shorter presentation times in one of the conditions. At the same time, we also often want the possiblity to end a trial when a response is given.

Implementation

I've started adding this feature to my fork and create an example. So far, I've only added this parameter to /jspsych-html-keyboard-response.js.

Crucially, I made a change that automatically sets response_ends_trial to true because it would otherwise conflict with response_ends_trial_after_stimulus.

@becky-gilbert thankfully gave some advice to improve my original modification. The discussion can be found here.

PS

I am happy to make the changes to the other plugins as well depending on the feedback here.

JAQuent avatar Mar 13 '21 10:03 JAQuent

Thanks for this @JAQuent!

@jodeleeuw would you be happy with this as a new parameter for the keyboard/button/slider response plugins? The audio-* and video-* plugins already have the response_allowed_while_playing parameter, but that is slightly different because it ignores/disables the response method during the media playback. Whereas this response_ends_trial_after_stimulus would accept a response during playback, but then wait until playback is finished before ending the trial.

becky-gilbert avatar Mar 25 '21 23:03 becky-gilbert

I'm wondering if we can generalize this to something like minimum_trial_duration or something like that? It could potentially cover more use cases and is maybe more intuitively named?

jodeleeuw avatar Mar 26 '21 13:03 jodeleeuw

I like the idea so you would for instance set minimum_trial_duration to the same time as stimulus_duration to get the behaviour that I propose.

So essentially we'd only need to change the lines in the end_trial function. I am happy to add this next weekend.

JAQuent avatar Mar 29 '21 13:03 JAQuent

@JAQuent yes I think that's exactly right - setting the minimum_trial_duration to be the same as the stimulus_duration, along with repsonse_ends_trial: true, should give you the behavior that you propose. I think that the minimum_trial_duration should just cause the trial to end after that amount of time has passed AND a response has been made. So this parameter shouldn't have any effect when response_ends_trial is false, right?

Thanks very much for agreeing to make this change!

becky-gilbert avatar Mar 29 '21 17:03 becky-gilbert

That is a good point. I've notice one potential issue and that is what happens if the user by accident specifies a minimum_trial_duration that is longer than trial_duration?

Since debugging is a bit difficult and throwing an error should probably avoid I thought it might be useful to choose whatever is longer minimum_trial_duration or trial_duration.

As you will see end_trial() is no completely unchanged, which might be better than the previous solution.

Here is the change plugin and the example to showcase the feature.

Link to the fork .

Once you give green light to particular solution I am happy to go through the other plugins that need to be changed.

JAQuent avatar Apr 09 '21 10:04 JAQuent

Great! Thanks very much for the update. We'll look at this ASAP and get back to you.

And as far as dealing with invalid/inconsistent parameter values, this can be a bit tricky and we don't expect plugins to catch everything. But one option is to just show a warning in the console, something like this:

if (trial.minimum_trial_duration !== null && trial.trial_duration !== null && trial.minimum_trial_duration > trial.trial_duration) {
  console.warn("Warning in html-keyboard-response: minimum_trial_duration is greater than trial_duration, "+
    "so minimum_trial_duration will be used as the trial duration and the trial_duration parameter will be ignored.");
}

becky-gilbert avatar Apr 09 '21 17:04 becky-gilbert

Good idea :)

JAQuent avatar Apr 09 '21 17:04 JAQuent