Accessing data from html-button-response in subsequent trials

488 views
Skip to first unread message

stephen_a...@berkeley.edu

unread,
Aug 1, 2018, 4:41:14 PM8/1/18
to jsPsych
Hi! I'm trying to build a study in which participants select an image from an array and then rate the selected image on a variety of traits. Have been able to format selection page and rating multiple traits page, but having trouble getting selected image from first page to display again in the rating page. Have been trying to access "button_pressed" from html-button-response, but can't figure out how. Using jsPsych-6.0.1. Code I have so far is below. Any help with this would be much appreciated. Thanks!

// selecting the stimuli
var first_block = {
type: "html-button-response",
stimulus: createStimulusDisplayHTML(images),
prompt: "Please select your favorite color of these two.",
choices: ['1','2','3']
//on_finish: function(data) {
//var choice = data.button_pressed;
//jsPsych.data.addDataToLastTrial({choice: choice});
//}
};

/* rating selected stimuli
function displaySelectedImage() {
//var t1 = jsPsych.data.getTimelineVariable('choice');
//var t1 = jsPsych.data.get().last(1).values()[1];
var t1 = jsPsych.data.get().filter({trial_type: 'html-button-response',choice: choice})
console.log(t1)
return t1
};
*/

var options = ['Strongly Disagree','Somewhat Disagree','Neither Agree nor Disagree','Somewhat Disagree','Strongly Disagree'];

var ratings = {
type: 'survey-likert',
questions: [{prompt:'<b><i>Extraverted, enthusiastic</i></b>',labels:options}],
preamble: '<p>Please indicate the extent to which you agree each of the following items applies to the image shown below.</p>'+'<p>'+
parseInt(first_block.button_pressed,10)+'<br>'+'</p>'+
'<img src="'+images[parseInt(first_block.button_pressed,10)]+'<br>'+'">'
};

Josh de Leeuw

unread,
Aug 1, 2018, 5:21:28 PM8/1/18
to stephen_a...@berkeley.edu, jsPsych
I think what you want is:

jsPsych.data.get().last(1).values()[0].button_pressed;

Explainer:

jsPsych.data.get() returns the full DataCollection (see https://www.jspsych.org/core_library/jspsych-data/#datacollection).

.last(1) filters down to the last trial

.values() returns the raw array of data

[0] selects the first element of the array (the only trial in the array, since array.length == 1)

.button_pressed selects the button_pressed property in the object.

--
You received this message because you are subscribed to the Google Groups "jsPsych" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jspsych+u...@googlegroups.com.
To post to this group, send email to jsp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jspsych/884ae36c-1ad0-44b6-a288-c2c3cf3196b7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Stephen Antonoplis

unread,
Aug 1, 2018, 10:40:04 PM8/1/18
to Josh de Leeuw, jsPsych
thanks! still doesn't work thought...experiment won't load. explanation makes sense. from the documentation online, button_pressed is supposed to be stored as an integer, but the data I see at the end of the survey contains a string (i.e., "button_pressed": "0",). do you think this is the issue? I've been trying to use Number(), parseInt(), and parseFloat() to convert button_pressed to a number; but none of those work (experiment fails to load). code works when I simply write 1 or 0.

On Wed, Aug 1, 2018 at 2:21 PM, Josh de Leeuw <josh.d...@gmail.com> wrote:
I think what you want is:

jsPsych.data.get().last(1).values()[0].button_pressed;

Explainer:

jsPsych.data.get() returns the full DataCollection (see https://www.jspsych.org/core_library/jspsych-data/#datacollection).

.last(1) filters down to the last trial

.values() returns the raw array of data

[0] selects the first element of the array (the only trial in the array, since array.length == 1)

.button_pressed selects the button_pressed property in the object.

To unsubscribe from this group and stop receiving emails from it, send an email to jspsych+unsubscribe@googlegroups.com.

To post to this group, send email to jsp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jspsych/884ae36c-1ad0-44b6-a288-c2c3cf3196b7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Stephen Antonoplis
PhD Student, UC Berkeley

Reply all
Reply to author
Forward
0 new messages