Replies: 2 comments 9 replies
-
Hi @y-j-huang, I'm not sure if this will work, but you could try changing your var practice = {
timeline: function() {
return jsPsych.randomization.sampleWithoutReplacement(trials, 2);
}
} If that doesn't work, then what I would do is just put var verbs = [verb1, verb2, verb3, verb4, verb5, verb6];
var practice = {
timeline: [practice_trial, feedback],
timeline_variables: function() {
var sampled_stimuli = jsPsych.randomization.sampleWithoutReplacement(verbs, 2);
// sampled_stimuli contains two separate arrays, so we need to combine them into a single array using .concat()
return sampled_stimuli[0].concat(sampled_stimuli[1]);
}
}; Do either of those methods work? |
Beta Was this translation helpful? Give feedback.
-
Ok, instead of my suggestion to use a dynamic parameter for The custom sampling function receives one argument, which is an array of trial indices from 0 to n-1, where n is the number of trials in your Here's how I did this. First, I added the set name to all of the trial objects in your trial info arrays ( var verb1 = [
{
questions: [
{prompt: 'verb1 question 1', options: options}
],
correct_response: '1',
set: 'verb1' // label each trial with its set name
},
{
questions: [
{prompt: 'verb1 question 2', options: options}
],
correct_response: '2',
set: 'verb1'
}
];
// same for verb2, verb3, etc. Then I combined all of these into a single flattened array so that it can be passed to var verbs = verb1.concat(verb2).concat(verb3); // etc. I also created a list of the stimuli set names, called var set_names = ['verb1','verb2','verb3']; // etc. Finally, in the var practice = {
timeline: [practice_trial],
timeline_variables: verbs,
sample: {
type: 'custom',
fn: function(t) {
// empty array to store the trials that will be presented
var sampled_trials = [];
// randomly select two stimuli set names (e.g. verb1, verb2, etc.)
var sampled_sets = jsPsych.randomization.sampleWithoutReplacement(set_names,2);
t.forEach(function(x) {
// for each trial in the verbs array, check if its 'set' name is one of the sampled sets,
// and if so, add the trial to the array of trials that will be presented
if (sampled_sets.includes(verbs[t[x]].set)) {
sampled_trials.push(t[x]);
}
});
// randomize the order of the selected trials and return it
return jsPsych.randomization.shuffle(sampled_trials);
}
}
}; One other thing that I noticed - when checking the participant's response against the correct response, the responses are stored in the if (data.correct_response == JSON.stringify(data.response)) { I checked the response accuracy like this (I only had one question per page and didn't name them): if (data.response.Q0 == data.correct_response) I hope this helps! Let us know if this solution works for you. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone, I created a practice structure where I have two nested levels (Level A and B). Each condition in Level A contains 6 conditions in Level B which contains 7 trials each). So there are 42 trials in total. I want to sample at level A (the upper level so that the relevant items in level B will be grouped together). I also want to record the accuracy so any participant whose accuracy is lower than 0.8 will need to redo the practice. If I sample with the sampling method, it only samples at level B for every individual item. So, I created an array at level A. In addition, I created a loop so that the practice will repeat if the accuracy is below 0.8 However, the loop doesn't update the sample, so the practice items stays the same while I want them to be different every time (I don't want toe participants to repeat the same practice items over again). Here's my code:
// Repeat practice trial if too many mistakes
I 'm guessing the "sample" is defined as a global variable so it doesn't work but putting it within the loop function doesn't work either. I would appreciate some insight of what I should change or if there's a different way to accomplish this. Thank you!
Beta Was this translation helpful? Give feedback.
All reactions