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

calculating the number of correct responses of a survey-multi-select #3321

Open
fatemene opened this issue Jun 17, 2024 · 6 comments
Open

calculating the number of correct responses of a survey-multi-select #3321

fatemene opened this issue Jun 17, 2024 · 6 comments

Comments

@fatemene
Copy link

Dear all,
I want to both give feedback to respondents and save the data for the number of correct responses when the participant chooses the correct response from a multi-select survey, but I do not know how. Can anybody help? Thanks in advance.
`

<title>Memory Experiment</title> <script src="jatos.js"></script> <script src="lib/jspsych.js"></script> <script src="lib/plugin-html-button-response.js"></script> <script src="lib/plugin-html-keyboard-response.js"></script> <script src="lib/plugin-survey-text.js"></script> <script src="lib/plugin-survey-multi-select.js"></script> <script>
    /* initialize jsPsych */

    var jsPsych = initJsPsych({
        on_trial_start: jatos.addAbortButton,
        on_finish: () => jatos.endStudy(jsPsych.data.get().json())
    });

    /* create timeline */
    var timeline = [];
    /* define welcome message trial */
    var welcome = {
    type: jsPsychHtmlButtonResponse,
    stimulus:`
                <p style="font-size:38px;color:darkblue;">سلام</p>
                <pstyle="font-size:18px;">در این آزمون، به شما 15 کلمه نشان داده می شود. پس از اینکه همه کلمات را دیدید، تعدادی کلمه به شما داده می شود که از بین آنها کلماتی را که قبلا دیده اید، انتخاب کنید. <p/>           
    `,
    choices:['<p style="font-size:22px;color:darkblue;">ادامـه</p>']
    };
    timeline.push(welcome);
    //demographic info
    var demographic = {
        type: jsPsychSurveyText,
        questions: [
            {prompt: 'نام یا کد', name: 'name'},
            {prompt: 'سن', name: 'age'},
            {prompt: 'جنسیت', name: 'gender'},
            {prompt: 'سال تحصیلی', name: 'degree'},
            {prompt: 'زبان مادری', name: 'place'},
        ]
};
timeline.push(demographic);
    
    var first_trial_stimuli = [
        {stimulus: '<div style="font-size:37.34px; font-family: b nazanin">طبل</div>'},
        {stimulus: '<div style="font-size:37.34px; font-family: b nazanin">پرده</div>'},
        {stimulus: '<div style="font-size:37.34px; font-family: b nazanin">زنگ</div>'},
        {stimulus: '<div style="font-size:37.34px; font-family: b nazanin">ماهی</div>'},

        {stimulus: '<div style="font-size:37.34px; font-family: b shadi">مدرسه</div>'},
        {stimulus: '<div style="font-size:37.34px;font-family: b shadi">کلاه</div>'},
        {stimulus: '<div style="font-size:37.34px;font-family: b shadi">قایق</div>'},
        {stimulus: '<div style="font-size:37.34px;font-family: b shadi">بینی</div>'},

        {stimulus: '<div style="font-size:37.34px;font-family: b kaj">مداد</div>'},
        {stimulus: '<div style="font-size:37.34px;font-family: b kaj">کفش</div>'},
        {stimulus: '<div style="font-size:37.34px;font-family: b kaj">قهوه</div>'},
        {stimulus: '<div style="font-size:37.34px; font-family: b kaj">میز</div>'},

        {stimulus: '<div style="font-size:37.34px;font-family: IranNastaliq">پرنده</div>'},
        {stimulus: '<div style="font-size:37.34px;font-family: IranNastaliq">بخاری</div>'},
        {stimulus: '<div style="font-size:37.34px;font-family: IranNastaliq">کوه</div>'},
        {stimulus: '<div style="font-size:37.34px;font-family: IranNastaliq">ماه</div>'},

        
    ]

    var first_trial = {
        type: jsPsychHtmlKeyboardResponse,
        stimulus: jsPsych.timelineVariable('stimulus'),
        choices: "NO_KEYS",
        trial_duration: 1000, 
        post_trial_gap: 1000
    };
    var trial_one_procedure = {
        timeline: [first_trial],
        timeline_variables: first_trial_stimuli,
        randomize_order: true
    };
    timeline.push(trial_one_procedure);

    var SecondPhase = {
    type: jsPsychHtmlButtonResponse,
    stimulus:'<p style="font-size:18px;">اکنون به شما 40 کلمه نشان داده می شود که از بین آنها کلماتی را که قبلا دیده اید، انتخاب کنید. <p/>',
    choices:['<p style="font-size:22px;color:darkblue;">ادامـه</p>']
    };
    timeline.push(SecondPhase);

    var test_page = {
        type: jsPsychSurveyMultiSelect,
        questions: [
        {
            prompt: "کدامیک از این کلمات را در لیست قبلی مشاهده کردید؟ آن را انتخاب کنید",
            options: [
                '<p style="font-size:37.34px;">(1) آهن</p>',
                '<p style="font-size:37.34px;">(2) ماه</p>',
                '<p style="font-size:37.34px;">(3) طبل</p>',
                '<p style="font-size:37.34px;">(4) بخاری</p>',
                '<p style="font-size:37.34px;">)(5) پرنده</p>',
                '<p style="font-size:37.34px;">(6) سنجاق</p>',
                '<p style="font-size:37.34px;">(7) مداد</p>',
                '<p style="font-size:37.34px;">(8) جغد</p>',
                '<p style="font-size:37.34px;">(9) بیل</p>',
                '<p style="font-size:37.34px;">(10) ریسمان</p>',
                '<p style="font-size:37.34px;">(11) سوراخ</p>',
                '<p style="font-size:37.34px;">(12) چانه</p>',
                '<p style="font-size:37.34px;">(13) سیمان</p>',
                '<p style="font-size:37.34px;">(14) ماهی</p>',
                '<p style="font-size:37.34px;">(15) زنگ</p>',
                '<p style="font-size:37.34px;">(16) دیوار</p>',
                '<p style="font-size:37.34px;">(17) کلاه</p>',
                '<p style="font-size:37.34px;">(18) در</p>',
                '<p style="font-size:37.34px;">(19) ناخن</p>',
                '<p style="font-size:37.34px;">(20) کفش</p>',
                '<p style="font-size:37.34px;">(21) چنگال</p>',
                '<p style="font-size:37.34px;">(22) سطل</p>',
                '<p style="font-size:37.34px;">(23) چوب</p>',
                '<p style="font-size:37.34px;">(24) پرده</p>',
                '<p style="font-size:37.34px;">(25) میز</p>',
                '<p style="font-size:37.34px;">(26) فندک</p>',
                '<p style="font-size:37.34px;">(27) مدرسه</p>',
                '<p style="font-size:37.34px;">(28) قایق</p>',
                '<p style="font-size:37.34px;">(29) بینی</p>',
                '<p style="font-size:37.34px;">(30) کوه</p>',
                '<p style="font-size:37.34px;">(31) لیوان</p>',
                '<p style="font-size:37.34px;">(32) قهوه</p>',
                

            ],
            required: true, 
            horizontal: true,
            data: {
                    task: 'response', 
                    correct_response: jsPsych.timelineVariable('stimulus')
                },
            on_finish: function(data){
                data.correct = data.response === data.correct_response;
            }
        }
        ]
};
timeline.push(test_page);
// var debrief_block = {
//     type: jsPsychHtmlKeyboardResponse,
//     stimulus: function() {

//     var trials = jsPsych.data.get().filter({task: 'response{"Q0"}'});
//     var correct_trials = trials.filter({correct: true});
//     return '<p>You responded correctly on ${accuracy}% of the trials.</p>';
//     }, 
//     choices: "NO_KEYS",
//     trial_duration: 4000
// };
// timeline.push(debrief_block);

var ending = {
  type: jsPsychHtmlKeyboardResponse,
  stimulus: "<p>این آزمون به پایان رسید. از همکاری شما سپاسگزاریم </p>",
  choices: "NO_KEYS",
  trial_duration: 3000
};
timeline.push(ending);



    /* start the experiment */
    jatos.onLoad(() => {
        jsPsych.run(timeline);
    });

</script>
`
@vzhang03
Copy link
Contributor

Hi Fateme,

While you could access the entire data, for this particular use case for simplicity it would be easier to get data from the last trial (which is the multi-select) and iterate through that data scoring the answers. Replicating the code and experiment you had above, I could correctly score the experiments by changing the debrief block as shown below. When you implement this in your experiment you should adjust the correct answers to include the correct answers in your case. I would be happy to send my entire HTML experiment file if this isn't working for you.

`

      var debrief_block = {
        type: jsPsychHtmlKeyboardResponse,
        stimulus: function() {
          var answersHTML = jsPsych.data.getLastTrialData().values()[0]['response']['Q0'];
          const correctAnswers = ["آهن"];
          var answers = [];
          const total = 32;
          var correct = total - correctAnswers.length;

          // Iterate through each element in the input array
          for (const answer of answersHTML) {
              // Use regex to extract (number) ArabicCharacter pattern
              var match = answer.match(/\((\d+)\)\s*(\S+)/)[2];                  
              match = match.replace("</p>", ""); // removes final header
              answers.push(match); // match[2] contains the answer character
          }
          
          // scores correct and incorrect items
          for (const answer of answers) {
            if (correctAnswers.includes(answer)) correct++; // scores correct
            else correct --; // scores incorrect
          }

          return `<p>You responded correctly on ${100 
            * (correct/total)}% of the trials.</p>`;
        }, 
        choices: "NO_KEYS",
        trial_duration: 4000
      };

`

@fatemene
Copy link
Author

Thanks a lot for the great help. The math does not seem to work correctly. I show 16 words in the presentation part; in the memory task, they should choose those 16 words from the 32 words given. If respondents choose from the 16 words given in the correctAnswers, they should get a plus score; otherwise (if the correct answer is not chosen or the incorrect answer is chosen) it should be counted as an incorrect response. We have a total of responses from which the number of correct answers should be calculated. Here is how I completed the code with your kind suggestion.
`

<title>Memory Experiment</title> <script src="jatos.js"></script> <script src="lib/jspsych.js"></script> <script src="lib/plugin-html-button-response.js"></script> <script src="lib/plugin-html-keyboard-response.js"></script> <script src="lib/plugin-survey-text.js"></script> <script src="lib/plugin-survey-multi-select.js"></script> <script>
    /* initialize jsPsych */

    var jsPsych = initJsPsych({
        on_trial_start: jatos.addAbortButton,
        on_finish: () => jatos.endStudy(jsPsych.data.get().json())
    });

    /* create timeline */
    var timeline = [];
    /* define welcome message trial */
    var welcome = {
    type: jsPsychHtmlButtonResponse,
    stimulus:`
                <p style="font-size:38px;color:darkblue;">سلام</p>
                <pstyle="font-size:18px;">در این آزمون، به شما 15 کلمه نشان داده می شود. پس از اینکه همه کلمات را دیدید، تعدادی کلمه به شما داده می شود که از بین آنها کلماتی را که قبلا دیده اید، انتخاب کنید. <p/>           
    `,
    choices:['<p style="font-size:22px;color:darkblue;">ادامـه</p>']
    };
    timeline.push(welcome);
    //demographic info
    var demographic = {
        type: jsPsychSurveyText,
        questions: [
            {prompt: 'نام یا کد', name: 'name'},
            {prompt: 'سن', name: 'age'},
            {prompt: 'جنسیت', name: 'gender'},
            {prompt: 'سال تحصیلی', name: 'degree'},
            {prompt: 'زبان مادری', name: 'place'},
        ]
};
timeline.push(demographic);
    
    var first_trial_stimuli = [
        {stimulus: '<div style="font-size:37.34px; font-family: b nazanin">طبل</div>'},
        {stimulus: '<div style="font-size:37.34px; font-family: b nazanin">پرده</div>'},
        {stimulus: '<div style="font-size:37.34px; font-family: b nazanin">زنگ</div>'},
        {stimulus: '<div style="font-size:37.34px; font-family: b nazanin">ماهی</div>'},

        {stimulus: '<div style="font-size:37.34px; font-family: b shadi">مدرسه</div>'},
        {stimulus: '<div style="font-size:37.34px;font-family: b shadi">کوه</div>'},
        {stimulus: '<div style="font-size:37.34px;font-family: b shadi">قایق</div>'},
        {stimulus: '<div style="font-size:37.34px;font-family: b shadi">بینی</div>'},

        {stimulus: '<div style="font-size:37.34px;font-family: b kaj">ماه</div>'},
        {stimulus: '<div style="font-size:37.34px;font-family: b kaj">کلاه</div>'},
        {stimulus: '<div style="font-size:37.34px;font-family: b kaj">قهوه</div>'},
        {stimulus: '<div style="font-size:37.34px; font-family: b kaj">میز</div>'},

        {stimulus: '<div style="font-size:37.34px;font-family: IranNastaliq">پرنده</div>'},
        {stimulus: '<div style="font-size:37.34px;font-family: IranNastaliq">بخاری</div>'},
        {stimulus: '<div style="font-size:37.34px;font-family: IranNastaliq">کفش</div>'},
        {stimulus: '<div style="font-size:37.34px;font-family: IranNastaliq">مداد</div>'},

        
    ]

    var first_trial = {
        type: jsPsychHtmlKeyboardResponse,
        stimulus: jsPsych.timelineVariable('stimulus'),
        choices: "NO_KEYS",
        trial_duration: 1000, 
        post_trial_gap: 1000
    };
    var trial_one_procedure = {
        timeline: [first_trial],
        timeline_variables: first_trial_stimuli,
        randomize_order: true
    };
    timeline.push(trial_one_procedure);

    var SecondPhase = {
    type: jsPsychHtmlButtonResponse,
    stimulus:'<p style="font-size:18px;">اکنون به شما 40 کلمه نشان داده می شود که از بین آنها کلماتی را که قبلا دیده اید، انتخاب کنید. <p/>',
    choices:['<p style="font-size:22px;color:darkblue;">ادامـه</p>']
    };
    timeline.push(SecondPhase);

    var test_page = {
        type: jsPsychSurveyMultiSelect,
        questions: [
        {
            prompt: "کدامیک از این کلمات را در لیست قبلی مشاهده کردید؟ آن را انتخاب کنید",
            options: [
                '<p style="font-size:37.34px;">(1) آهن</p>',
                '<p style="font-size:37.34px;">(2) ماه</p>',
                '<p style="font-size:37.34px;">(3) طبل</p>',
                '<p style="font-size:37.34px;">(4) بخاری</p>',
                '<p style="font-size:37.34px;">)(5) پرنده</p>',
                '<p style="font-size:37.34px;">(6) سنجاق</p>',
                '<p style="font-size:37.34px;">(7) مداد</p>',
                '<p style="font-size:37.34px;">(8) جغد</p>',
                '<p style="font-size:37.34px;">(9) بیل</p>',
                '<p style="font-size:37.34px;">(10) ریسمان</p>',
                '<p style="font-size:37.34px;">(11) سوراخ</p>',
                '<p style="font-size:37.34px;">(12) چانه</p>',
                '<p style="font-size:37.34px;">(13) سیمان</p>',
                '<p style="font-size:37.34px;">(14) ماهی</p>',
                '<p style="font-size:37.34px;">(15) زنگ</p>',
                '<p style="font-size:37.34px;">(16) دیوار</p>',
                '<p style="font-size:37.34px;">(17) کلاه</p>',
                '<p style="font-size:37.34px;">(18) در</p>',
                '<p style="font-size:37.34px;">(19) ناخن</p>',
                '<p style="font-size:37.34px;">(20) کفش</p>',
                '<p style="font-size:37.34px;">(21) چنگال</p>',
                '<p style="font-size:37.34px;">(22) سطل</p>',
                '<p style="font-size:37.34px;">(23) چوب</p>',
                '<p style="font-size:37.34px;">(24) پرده</p>',
                '<p style="font-size:37.34px;">(25) میز</p>',
                '<p style="font-size:37.34px;">(26) فندک</p>',
                '<p style="font-size:37.34px;">(27) مدرسه</p>',
                '<p style="font-size:37.34px;">(28) قایق</p>',
                '<p style="font-size:37.34px;">(29) بینی</p>',
                '<p style="font-size:37.34px;">(30) کوه</p>',
                '<p style="font-size:37.34px;">(31) لیوان</p>',
                '<p style="font-size:37.34px;">(32) قهوه</p>',
                

            ],
            required: true, 
            horizontal: true,
            data: {
                    task: 'response', 
                    correct_response: jsPsych.timelineVariable('stimulus')
                },
            on_finish: function(data){
                data.correct = data.response === data.correct_response;
            }
        }
        ]
};
timeline.push(test_page);
var debrief_block = {
     type: jsPsychHtmlKeyboardResponse,
     stimulus: function() {
         var answersHTML = jsPsych.data.getLastTrialData().values()[0] ['response']['Q0'];
        const correctAnswers = ["طبل", "پرده", "زنگ","ماهی","مدرسه", "کلاه", "قایق","بینی", "مداد", "کفش", "قهوه", "میز", "پرنده", "بخاری", "کوه","ماه" ];
        var answers = [];
        const total = 32;
        var correct = total - correctAnswers.length;

      // Iterate through each element in the input array
      for (const answer of answersHTML) {
          // Use regex to extract (number) ArabicCharacter pattern
          var match = answer.match(/\((\d+)\)\s*(\S+)/)[2];                  
          match = match.replace("</p>", ""); // removes final header
          answers.push(match); // match[2] contains the answer character
      }
      
      // scores correct and incorrect items
      for (const answer of answers) {
        if (correctAnswers.includes(answer)) correct++; // scores correct
        else correct --; // scores incorrect
      }

      return `<p>شما به  ${100 
        * (correct/total)}% موارد پاسخ درست داده اید.</p>
        <p> تعداد واژه های درست ${correct}</p>
        <p> تعداد واژه های نادرست ${total-correct}</p>`;
    }, 
    choices: "NO_KEYS",
    trial_duration: 4000
  };
timeline.push(debrief_block);

var ending = {
  type: jsPsychHtmlKeyboardResponse,
  stimulus: "<p>این آزمون به پایان رسید. از همکاری شما سپاسگزاریم </p>",
  choices: "NO_KEYS",
  trial_duration: 3000
};
timeline.push(ending);



    /* start the experiment */
    jatos.onLoad(() => {
        jsPsych.run(timeline);
    });

</script>
`

@vzhang03
Copy link
Contributor

If I'm understanding you correctly the code should be working because that was also how I had in mind. Is there a specific number that is failing for you?

        const correctAnswers = ["طبل", "پرده", "زنگ","ماهی","مدرسه", "کلاه", "قایق","بینی", "مداد", "کفش", "قهوه", "میز", "پرنده", "بخاری", "کوه","ماه" ];
        const total = 32;
        var correct = total - correctAnswers.length;

      for (const answer of answers) {
        if (correctAnswers.includes(answer)) correct++; // scores correct
        else correct --; // scores incorrect
      }

When the user doesn't put in answers, they should get 50% because they correctly selected the answers not displayed. When I tested it does return as 50%. When there are no answers can skip the for loop and calculate the answers correct as "var correct = total - correctAnswers.length = 16".

Same when testing the selection of all the answers. If the user selects all answers they start with 16 points before the responses are tallied. Then after going through each answer because 16 of the selections are correct or plus points and the 16 incorrect selections are negative points, the user should end up with 16 points which is being correctly represented when testing.

@Bankminer78
Copy link
Contributor

Bankminer78 commented Jun 18, 2024

Hi Fatemene,

If you would like to calculate the number of correct responses within the test-page trial itself, you can use a higher-level function inside the on_finish parameter:

 var correct = [your list of correct options in html]

var test_page = {
    type: jsPsychSurveyMultiSelect,
    questions: [
        {
            prompt: "کدامیک از این کلمات را در لیست قبلی مشاهده کردید؟ آن را انتخاب کنید",
            options: [
                '<p style="font-size:37.34px;">(1) ME</p>',
                '<p style="font-size:37.34px;">(2) ماه</p>',
                '<p style="font-size:37.34px;">(3) طبل</p>',
                '<p style="font-size:37.34px;">(4) بخاری</p>',
                '<p style="font-size:37.34px;">(5) پرنده</p>',
                '<p style="font-size:37.34px;">(6) سنجاق</p>',
                '<p style="font-size:37.34px;">(7) مداد</p>',
                '<p style="font-size:37.34px;">(8) جغد</p>',
                '<p style="font-size:37.34px;">(9) بیل</p>',
                '<p style="font-size:37.34px;">(10) ریسمان</p>',
                '<p style="font-size:37.34px;">(11) سوراخ</p>',
                '<p style="font-size:37.34px;">(12) چانه</p>',
                '<p style="font-size:37.34px;">(13) سیمان</p>',
                '<p style="font-size:37.34px;">(14) ماهی</p>',
                '<p style="font-size:37.34px;">(15) زنگ</p>',
                '<p style="font-size:37.34px;">(16) دیوار</p>',
                '<p style="font-size:37.34px;">(17) کلاه</p>',
                '<p style="font-size:37.34px;">(18) در</p>',
                '<p style="font-size:37.34px;">(19) ME TOO</p>',
                '<p style="font-size:37.34px;">(20) کفش</p>',
                '<p style="font-size:37.34px;">(21) چنگال</p>',
                '<p style="font-size:37.34px;">(22) سطل</p>',
                '<p style="font-size:37.34px;">(23) چوب</p>',
                '<p style="font-size:37.34px;">(24) پرده</p>',
                '<p style="font-size:37.34px;">(25) میز</p>',
                '<p style="font-size:37.34px;">(26) فندک</p>',
                '<p style="font-size:37.34px;">(27) مدرسه</p>',
                '<p style="font-size:37.34px;">(28) قایق</p>',
                '<p style="font-size:37.34px;">(29) بینی</p>',
                '<p style="font-size:37.34px;">(30) کوه</p>',
                '<p style="font-size:37.34px;">(31) لیوان</p>',
                '<p style="font-size:37.34px;">(32) قهوه</p>'
            ],
            required: true, 
            horizontal: true,
        }
    ],
    data: {
                task: 'response', 
                correct_response: jsPsych.timelineVariable('stimulus')
            },
  on_finish: function(data) {
                 data.success_count = data.response.Q0.reduce((acc, item) => acc + (correct.includes(item) ? 1 : 0), 0);
          }
};

(side-note: it might be a good idea to replace the 'correct' variable with a reference to a timelineVariable and adjust the implementation of the test-page trial appropriately) The reduce function here would fold the list of responses into a number representing the number of correct responses. You can then access this value in the debrief_block trial by calling an expression likejsPsych.data.getLastTrialData().values()[0]['success_count']. In the end, your data should look something like:

{
    "rt": 6170,
    "response": {
        "Q0": [
            "<p style=\"font-size:37.34px;\">(1) ME</p>",
            "<p style=\"font-size:37.34px;\">(19) ME TOO</p>"
        ]
    },
    "question_order": [
        0
    ],
    "task": "response",
    "trial_type": "survey-multi-select",
    "trial_index": 3,
    "time_elapsed": 8761,
    "internal_node_id": "0.0-3.0",
    "success_count": *number of responses selected correctly*
},

@fatemene
Copy link
Author

'

(28) قایق

',
'

(29) بینی

',
'

(30) کوه

',
'

(31) لیوان

',
'

(32) قهوه

'
],
required: true,
horizontal: true,
}
],
data: {
task: 'response',
correct_response: jsPsych.timelineVariable('stimulus')
},
on_finish: function(data) {
data.success_count = data.response.Q0.reduce((acc, item) => acc + (correct.includes(item) ? 1 : 0), 0);
}
};

Hi Fatemene,

If you would like to calculate the number of correct responses within the test-page trial itself, you can use a higher-level function inside the on_finish parameter:

 var correct = [your list of correct options in html]

var test_page = {
    type: jsPsychSurveyMultiSelect,
    questions: [
        {
            prompt: "کدامیک از این کلمات را در لیست قبلی مشاهده کردید؟ آن را انتخاب کنید",
            options: [
                '<p style="font-size:37.34px;">(1) ME</p>',
                '<p style="font-size:37.34px;">(2) ماه</p>',
                '<p style="font-size:37.34px;">(3) طبل</p>',
                '<p style="font-size:37.34px;">(4) بخاری</p>',
                '<p style="font-size:37.34px;">(5) پرنده</p>',
                '<p style="font-size:37.34px;">(6) سنجاق</p>',
                '<p style="font-size:37.34px;">(7) مداد</p>',
                '<p style="font-size:37.34px;">(8) جغد</p>',
                '<p style="font-size:37.34px;">(9) بیل</p>',
                '<p style="font-size:37.34px;">(10) ریسمان</p>',
                '<p style="font-size:37.34px;">(11) سوراخ</p>',
                '<p style="font-size:37.34px;">(12) چانه</p>',
                '<p style="font-size:37.34px;">(13) سیمان</p>',
                '<p style="font-size:37.34px;">(14) ماهی</p>',
                '<p style="font-size:37.34px;">(15) زنگ</p>',
                '<p style="font-size:37.34px;">(16) دیوار</p>',
                '<p style="font-size:37.34px;">(17) کلاه</p>',
                '<p style="font-size:37.34px;">(18) در</p>',
                '<p style="font-size:37.34px;">(19) ME TOO</p>',
                '<p style="font-size:37.34px;">(20) کفش</p>',
                '<p style="font-size:37.34px;">(21) چنگال</p>',
                '<p style="font-size:37.34px;">(22) سطل</p>',
                '<p style="font-size:37.34px;">(23) چوب</p>',
                '<p style="font-size:37.34px;">(24) پرده</p>',
                '<p style="font-size:37.34px;">(25) میز</p>',
                '<p style="font-size:37.34px;">(26) فندک</p>',
                '<p style="font-size:37.34px;">(27) مدرسه</p>',
                '<p style="font-size:37.34px;">(28) قایق</p>',
                '<p style="font-size:37.34px;">(29) بینی</p>',
                '<p style="font-size:37.34px;">(30) کوه</p>',
                '<p style="font-size:37.34px;">(31) لیوان</p>',
                '<p style="font-size:37.34px;">(32) قهوه</p>'
            ],
            required: true, 
            horizontal: true,
        }
    ],
    data: {
                task: 'response', 
                correct_response: jsPsych.timelineVariable('stimulus')
            },
  on_finish: function(data) {
                 data.success_count = data.response.Q0.reduce((acc, item) => acc + (correct.includes(item) ? 1 : 0), 0);
          }
};

(side-note: it might be a good idea to replace the 'correct' variable with a reference to a timelineVariable and adjust the implementation of the test-page trial appropriately) The reduce function here would fold the list of responses into a number representing the number of correct responses. You can then access this value in the debrief_block trial by calling an expression likejsPsych.data.getLastTrialData().values()[0]['success_count']. In the end, your data should look something like:

{
    "rt": 6170,
    "response": {
        "Q0": [
            "<p style=\"font-size:37.34px;\">(1) ME</p>",
            "<p style=\"font-size:37.34px;\">(19) ME TOO</p>"
        ]
    },
    "question_order": [
        0
    ],
    "task": "response",
    "trial_type": "survey-multi-select",
    "trial_index": 3,
    "time_elapsed": 8761,
    "internal_node_id": "0.0-3.0",
    "success_count": *number of responses selected correctly*
},

Thanks for the illuminating explanation. That was quite clear.

@fatemene
Copy link
Author

Hi Fatemene,

If you would like to calculate the number of correct responses within the test-page trial itself, you can use a higher-level function inside the on_finish parameter:

 var correct = [your list of correct options in html]

var test_page = {
    type: jsPsychSurveyMultiSelect,
    questions: [
        {
            prompt: "کدامیک از این کلمات را در لیست قبلی مشاهده کردید؟ آن را انتخاب کنید",
            options: [
                '<p style="font-size:37.34px;">(1) ME</p>',
                '<p style="font-size:37.34px;">(2) ماه</p>',
                '<p style="font-size:37.34px;">(3) طبل</p>',
                '<p style="font-size:37.34px;">(4) بخاری</p>',
                '<p style="font-size:37.34px;">(5) پرنده</p>',
                '<p style="font-size:37.34px;">(6) سنجاق</p>',
                '<p style="font-size:37.34px;">(7) مداد</p>',
                '<p style="font-size:37.34px;">(8) جغد</p>',
                '<p style="font-size:37.34px;">(9) بیل</p>',
                '<p style="font-size:37.34px;">(10) ریسمان</p>',
                '<p style="font-size:37.34px;">(11) سوراخ</p>',
                '<p style="font-size:37.34px;">(12) چانه</p>',
                '<p style="font-size:37.34px;">(13) سیمان</p>',
                '<p style="font-size:37.34px;">(14) ماهی</p>',
                '<p style="font-size:37.34px;">(15) زنگ</p>',
                '<p style="font-size:37.34px;">(16) دیوار</p>',
                '<p style="font-size:37.34px;">(17) کلاه</p>',
                '<p style="font-size:37.34px;">(18) در</p>',
                '<p style="font-size:37.34px;">(19) ME TOO</p>',
                '<p style="font-size:37.34px;">(20) کفش</p>',
                '<p style="font-size:37.34px;">(21) چنگال</p>',
                '<p style="font-size:37.34px;">(22) سطل</p>',
                '<p style="font-size:37.34px;">(23) چوب</p>',
                '<p style="font-size:37.34px;">(24) پرده</p>',
                '<p style="font-size:37.34px;">(25) میز</p>',
                '<p style="font-size:37.34px;">(26) فندک</p>',
                '<p style="font-size:37.34px;">(27) مدرسه</p>',
                '<p style="font-size:37.34px;">(28) قایق</p>',
                '<p style="font-size:37.34px;">(29) بینی</p>',
                '<p style="font-size:37.34px;">(30) کوه</p>',
                '<p style="font-size:37.34px;">(31) لیوان</p>',
                '<p style="font-size:37.34px;">(32) قهوه</p>'
            ],
            required: true, 
            horizontal: true,
        }
    ],
    data: {
                task: 'response', 
                correct_response: jsPsych.timelineVariable('stimulus')
            },
  on_finish: function(data) {
                 data.success_count = data.response.Q0.reduce((acc, item) => acc + (correct.includes(item) ? 1 : 0), 0);
          }
};

(side-note: it might be a good idea to replace the 'correct' variable with a reference to a timelineVariable and adjust the implementation of the test-page trial appropriately) The reduce function here would fold the list of responses into a number representing the number of correct responses. You can then access this value in the debrief_block trial by calling an expression likejsPsych.data.getLastTrialData().values()[0]['success_count']. In the end, your data should look something like:

{
    "rt": 6170,
    "response": {
        "Q0": [
            "<p style=\"font-size:37.34px;\">(1) ME</p>",
            "<p style=\"font-size:37.34px;\">(19) ME TOO</p>"
        ]
    },
    "question_order": [
        0
    ],
    "task": "response",
    "trial_type": "survey-multi-select",
    "trial_index": 3,
    "time_elapsed": 8761,
    "internal_node_id": "0.0-3.0",
    "success_count": *number of responses selected correctly*
},

Hi Fatemene,

If you would like to calculate the number of correct responses within the test-page trial itself, you can use a higher-level function inside the on_finish parameter:

 var correct = [your list of correct options in html]

var test_page = {
    type: jsPsychSurveyMultiSelect,
    questions: [
        {
            prompt: "کدامیک از این کلمات را در لیست قبلی مشاهده کردید؟ آن را انتخاب کنید",
            options: [
                '<p style="font-size:37.34px;">(1) ME</p>',
                '<p style="font-size:37.34px;">(2) ماه</p>',
                '<p style="font-size:37.34px;">(3) طبل</p>',
                '<p style="font-size:37.34px;">(4) بخاری</p>',
                '<p style="font-size:37.34px;">(5) پرنده</p>',
                '<p style="font-size:37.34px;">(6) سنجاق</p>',
                '<p style="font-size:37.34px;">(7) مداد</p>',
                '<p style="font-size:37.34px;">(8) جغد</p>',
                '<p style="font-size:37.34px;">(9) بیل</p>',
                '<p style="font-size:37.34px;">(10) ریسمان</p>',
                '<p style="font-size:37.34px;">(11) سوراخ</p>',
                '<p style="font-size:37.34px;">(12) چانه</p>',
                '<p style="font-size:37.34px;">(13) سیمان</p>',
                '<p style="font-size:37.34px;">(14) ماهی</p>',
                '<p style="font-size:37.34px;">(15) زنگ</p>',
                '<p style="font-size:37.34px;">(16) دیوار</p>',
                '<p style="font-size:37.34px;">(17) کلاه</p>',
                '<p style="font-size:37.34px;">(18) در</p>',
                '<p style="font-size:37.34px;">(19) ME TOO</p>',
                '<p style="font-size:37.34px;">(20) کفش</p>',
                '<p style="font-size:37.34px;">(21) چنگال</p>',
                '<p style="font-size:37.34px;">(22) سطل</p>',
                '<p style="font-size:37.34px;">(23) چوب</p>',
                '<p style="font-size:37.34px;">(24) پرده</p>',
                '<p style="font-size:37.34px;">(25) میز</p>',
                '<p style="font-size:37.34px;">(26) فندک</p>',
                '<p style="font-size:37.34px;">(27) مدرسه</p>',
                '<p style="font-size:37.34px;">(28) قایق</p>',
                '<p style="font-size:37.34px;">(29) بینی</p>',
                '<p style="font-size:37.34px;">(30) کوه</p>',
                '<p style="font-size:37.34px;">(31) لیوان</p>',
                '<p style="font-size:37.34px;">(32) قهوه</p>'
            ],
            required: true, 
            horizontal: true,
        }
    ],
    data: {
                task: 'response', 
                correct_response: jsPsych.timelineVariable('stimulus')
            },
  on_finish: function(data) {
                 data.success_count = data.response.Q0.reduce((acc, item) => acc + (correct.includes(item) ? 1 : 0), 0);
          }
};

(side-note: it might be a good idea to replace the 'correct' variable with a reference to a timelineVariable and adjust the implementation of the test-page trial appropriately) The reduce function here would fold the list of responses into a number representing the number of correct responses. You can then access this value in the debrief_block trial by calling an expression likejsPsych.data.getLastTrialData().values()[0]['success_count']. In the end, your data should look something like:

{
    "rt": 6170,
    "response": {
        "Q0": [
            "<p style=\"font-size:37.34px;\">(1) ME</p>",
            "<p style=\"font-size:37.34px;\">(19) ME TOO</p>"
        ]
    },
    "question_order": [
        0
    ],
    "task": "response",
    "trial_type": "survey-multi-select",
    "trial_index": 3,
    "time_elapsed": 8761,
    "internal_node_id": "0.0-3.0",
    "success_count": *number of responses selected correctly*
},

Thanks for the alternative solution. unfortunately the code didn't work; most probably because I didn't know to use it.

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

3 participants