How to filter output data in the proper format to be able to create variables that I need in the next part of the task? #1751
-
Hi everyone, I´m working on a new experiment where on its first part, For the second part of the experiment, I want to select a subset of images I expect to find a way to obtain an array with the selected subset of images Is there a way to obtain the filtered collection of images as I was expecting, Also, I am wondering, how could I display the filtered output data? Thank you very much for your help in advance, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
Hi @Sivileo, this is a little hard to explain without some example code to work with, so feel free to post a minimal example if you have one. I think you're on the right track with the approach you suggested. My general approach would be to:
var rating_trial = {
// other trial parameters...
data: {task_part: 'rating'}
};
// then, after part 1, you can filter the data to get all of the image ratings:
var ratings_trials = jsPsych.data.get().filter({task_part: 'rating'});
// filter the ratings trials again to see if the response meets the criteria
// for the low/high category
var high_rated_images = ratings_trials.filterCustom(function(trial) {
return trial.response > 75;
});
var low_rated_images = ratings_trials.filterCustom(function(trial) {
return trial.response < 25;
});
// note that you can also do this in a single step, by chaining togther the filter and filterCustom functions
// as you suggested in your post:
// var high_rated_images = jspsych.data.get().filter({task_part: 'rating'}).filterCustom(function(trial) {
// return trial.response > 75;
// });
// var low_rated_images = jspsych.data.get().filter({task_part: 'rating'}).filterCustom(function(trial) {
// return trial.response < 25;
// });
// check that the low and high arrays contain all of the images that meet your criteria
console.log('high rated images: ', high_rated_images);
console.log('low rated images: ', low_rated_images);
// create a global variable to store the current image stimulus
// the value of this variable will be changed in the looping function
var current_image;
// create a global variable to track the index of the current image in the low/high arrays
var count = 0;
var repeat_image_trial = {
stimulus: function() {
// use a dynamic parameter to get the current value of the current_image variable
return current_image;
},
// other parameters for the trial that presents the low/high-rated images...
};
var low_rated_images_loop = {
timeline: [repeat_image_trial],
looping_function: function() {
count++;
if (count < low_rated_images.length) {
// after increasing the trial count, if there are still images in the array, then set current_image
current_image = low_rated_images[count];
return true;
} else {
// if the trial count has exceeded the number of images in the array, then we're done looping
return false;
}
}
};
var low_rated_images_conditional = {
timeline: [low_rated_images_loop]
conditional_function: function() {
if (low_rated_images.length > 0) {
// if there are any images in the low_rated_images array, then run the low_rated_images_loop procedure
return true;
} else {
// otherwise skip the low_rated_images_loop procedure
return false;
}
}
};
// add the conditional timeline to your main experiment timeline
timeline.push(low_rated_images_conditional);
Yes, you can include the function |
Beta Was this translation helpful? Give feedback.
Hi @Sivileo, this is a little hard to explain without some example code to work with, so feel free to post a minimal example if you have one.
I think you're on the right track with the approach you suggested. My general approach would be to: