如果参与者提供了 n 个正确答案,则跳过剩余的时间线 (jspsych)
Skip rest of timeline if participant provides n correct answers (jspsych)
我在时间轴上有 n 个决策试验。正确答案被记录为数据属性。如果参与者提供了固定数量的正确答案,我想跳过剩余的时间线。这需要一个条件,但我的不起作用。
var if_node = {
timeline: [test_procedure],
conditional_function: function(){
var data = jsPsych.data.get()
var correct_count = data.filter({correct: true}).count();
return correct_count < 2
}
}
下面的可重现代码(需要 jspsych-6)。
<!DOCTYPE html>
<html>
<head>
<title>My experiment</title>
<script src="jspsych-6/jspsych.js"></script>
<script src="jspsych-6/plugins/jspsych-html-keyboard-response.js"></script>
<script src="jspsych-6/plugins/jspsych-html-button-response.js"></script>
<link href="jspsych-6/css/jspsych.css" rel="stylesheet" type="text/css"></link>
</head>
<body></body>
<script>
/* create timeline */
var timeline = [];
/* test trials */
var test_stimuli = [
{ word: "table", data: { false_word: '0' } },
{ word: "tfble", data: { false_word: '1' } },
{ word: "tablw", data: { false_word: '1' } }
];
var trial = {
type: ["html-button-response"],
stimulus: jsPsych.timelineVariable('word'),
choices: ["real", "fake"],
margin_vertical: "0px",
margin_horizontal: "8px",
response_ends_trial: true,
post_trial_gap: [500],
data: jsPsych.timelineVariable('data'),
on_finish: function(data){
data.correct = data.false_word == data.button_pressed
}
};
var test_procedure = {
timeline: [trial],
timeline_variables: test_stimuli
}
//timeline.push(test_procedure);
var if_node = {
timeline: [test_procedure],
conditional_function: function(){
var data = jsPsych.data.get()
var correct_count = data.filter({correct: true}).count();
return correct_count < 2
}
}
timeline.push(if_node);
/* start the experiment */
jsPsych.init({
timeline: timeline,
on_finish: function() {
jsPsych.data.displayData();
}
});
</script>
</html>
你可以在实验开始时声明一个correct_count
变量,当实验正确时将该变量加1,然后在if_node
时检查那个计数器是否大于一个数字,相应地执行时间线。
我对您的代码进行了一些更改,并在注释中突出显示了我的更改。请在下面查看它们。
<!DOCTYPE html>
<html>
<head>
<title>My experiment</title>
<script src="jspsych-6/jspsych.js"></script>
<script src="jspsych-6/plugins/jspsych-html-keyboard-response.js"></script>
<script src="jspsych-6/plugins/jspsych-html-button-response.js"></script>
<link href="jspsych-6/css/jspsych.css" rel="stylesheet" type="text/css"></link>
</head>
<body></body>
<script>
/* create timeline */
var timeline = [];
/* here I create correct_count variable to count correct trials */
var correct_count = 0;
/* test trials */
var test_stimuli = [
{ word: "table", data: { false_word: '0' } },
{ word: "tfble", data: { false_word: '1' } },
{ word: "tablw", data: { false_word: '1' } }
];
var trial = {
type: ["html-button-response"],
stimulus: jsPsych.timelineVariable('word'),
choices: ["real", "fake"],
margin_vertical: "0px",
margin_horizontal: "8px",
response_ends_trial: true,
post_trial_gap: [500],
data: jsPsych.timelineVariable('data'),
on_finish: function(data){
data.correct = data.false_word == data.button_pressed
console.log(data.correct )
if (data.correct = true){ // here I increment the counter variable if the response is correct
correct_count++
console.log(correct_count)
}
}
};
var test_procedure = {
timeline: [trial],
timeline_variables: test_stimuli
}
//timeline.push(test_procedure);
var if_node = {
timeline: [test_procedure],
conditional_function: function(){
console.log(correct_count)
if (correct_count < 2) { //here I check if counter is less than 2, if so, keep executing the timeline.
return true
}
}
}
timeline.push(if_node);
/* start the experiment */
jsPsych.init({
timeline: timeline,
on_finish: function() {
jsPsych.data.displayData();
}
});
</script>
</html>
我在时间轴上有 n 个决策试验。正确答案被记录为数据属性。如果参与者提供了固定数量的正确答案,我想跳过剩余的时间线。这需要一个条件,但我的不起作用。
var if_node = {
timeline: [test_procedure],
conditional_function: function(){
var data = jsPsych.data.get()
var correct_count = data.filter({correct: true}).count();
return correct_count < 2
}
}
下面的可重现代码(需要 jspsych-6)。
<!DOCTYPE html>
<html>
<head>
<title>My experiment</title>
<script src="jspsych-6/jspsych.js"></script>
<script src="jspsych-6/plugins/jspsych-html-keyboard-response.js"></script>
<script src="jspsych-6/plugins/jspsych-html-button-response.js"></script>
<link href="jspsych-6/css/jspsych.css" rel="stylesheet" type="text/css"></link>
</head>
<body></body>
<script>
/* create timeline */
var timeline = [];
/* test trials */
var test_stimuli = [
{ word: "table", data: { false_word: '0' } },
{ word: "tfble", data: { false_word: '1' } },
{ word: "tablw", data: { false_word: '1' } }
];
var trial = {
type: ["html-button-response"],
stimulus: jsPsych.timelineVariable('word'),
choices: ["real", "fake"],
margin_vertical: "0px",
margin_horizontal: "8px",
response_ends_trial: true,
post_trial_gap: [500],
data: jsPsych.timelineVariable('data'),
on_finish: function(data){
data.correct = data.false_word == data.button_pressed
}
};
var test_procedure = {
timeline: [trial],
timeline_variables: test_stimuli
}
//timeline.push(test_procedure);
var if_node = {
timeline: [test_procedure],
conditional_function: function(){
var data = jsPsych.data.get()
var correct_count = data.filter({correct: true}).count();
return correct_count < 2
}
}
timeline.push(if_node);
/* start the experiment */
jsPsych.init({
timeline: timeline,
on_finish: function() {
jsPsych.data.displayData();
}
});
</script>
</html>
你可以在实验开始时声明一个correct_count
变量,当实验正确时将该变量加1,然后在if_node
时检查那个计数器是否大于一个数字,相应地执行时间线。
我对您的代码进行了一些更改,并在注释中突出显示了我的更改。请在下面查看它们。
<!DOCTYPE html>
<html>
<head>
<title>My experiment</title>
<script src="jspsych-6/jspsych.js"></script>
<script src="jspsych-6/plugins/jspsych-html-keyboard-response.js"></script>
<script src="jspsych-6/plugins/jspsych-html-button-response.js"></script>
<link href="jspsych-6/css/jspsych.css" rel="stylesheet" type="text/css"></link>
</head>
<body></body>
<script>
/* create timeline */
var timeline = [];
/* here I create correct_count variable to count correct trials */
var correct_count = 0;
/* test trials */
var test_stimuli = [
{ word: "table", data: { false_word: '0' } },
{ word: "tfble", data: { false_word: '1' } },
{ word: "tablw", data: { false_word: '1' } }
];
var trial = {
type: ["html-button-response"],
stimulus: jsPsych.timelineVariable('word'),
choices: ["real", "fake"],
margin_vertical: "0px",
margin_horizontal: "8px",
response_ends_trial: true,
post_trial_gap: [500],
data: jsPsych.timelineVariable('data'),
on_finish: function(data){
data.correct = data.false_word == data.button_pressed
console.log(data.correct )
if (data.correct = true){ // here I increment the counter variable if the response is correct
correct_count++
console.log(correct_count)
}
}
};
var test_procedure = {
timeline: [trial],
timeline_variables: test_stimuli
}
//timeline.push(test_procedure);
var if_node = {
timeline: [test_procedure],
conditional_function: function(){
console.log(correct_count)
if (correct_count < 2) { //here I check if counter is less than 2, if so, keep executing the timeline.
return true
}
}
}
timeline.push(if_node);
/* start the experiment */
jsPsych.init({
timeline: timeline,
on_finish: function() {
jsPsych.data.displayData();
}
});
</script>
</html>