我正在用JSPsych编写一个实验,在这个实验中我有十个条件。我需要呈现一个由五个图像组成的数组,根据条件的不同具有不同的频率。
我已经设法使用for循环和randomize.sampleWithReplacement获得了某种工作,但它不能以我所需的频率呈现图像。
例如,在一种情况下,我希望图像5显示8次,图像4显示6次,以此类推。
有人知道我如何使用插件和JSPsych函数来实现这一点吗?
到目前为止,我的代码如下:
if (cond2 == 'uniform') {
var ratings_r = jsPsych.randomization.repeat(ratings, 4);
for (var i = 0; i < ratings_r.length; i++) {
timeline.push({
type: "html-button-response",
choices: ['Click here to continue'],
button_html: '<button class="jspsych-btn" style="display:none">%choice%</button>',
on_start: function() { setTimeout(function(){setDisplay("jspsych-btn","")}, 3000)},
is_html: true,
timeline: [{
stimulus: "<img src=" + ratings_r[i] + "><br><br><br>"
}
]
});
}
} if (cond2 == 'left-skew') {
var ratings_ls = jsPsych.randomization.sampleWithReplacement(ratings, 20, [2, 1, 1, 1, 1]);
console.log(ratings_ls)
for (var i = 0; i < ratings_ls.length; i++) {
timeline.push({
type: "html-button-response",
choices: ['Click here to continue'],
button_html: '<button class="jspsych-btn" style="display:none">%choice%</button>',
on_start: function() { setTimeout(function(){setDisplay("jspsych-btn","")}, 3000)},
is_html: true,
timeline: [{
stimulus: "<img src=" + ratings_ls[i] + "><br><br><br>"
}
]
});
}
} else {
var ratings_rs = jsPsych.randomization.sampleWithReplacement(ratings, 20, [1, 1, 1, 1, 4]);
console.log(ratings_rs)
for (var i = 0; i < ratings_rs.length; i++) {
timeline.push({
type: "html-button-response",
choices: ['Click here to continue'],
button_html: '<button class="jspsych-btn" style="display:none">%choice%</button>',
on_start: function() { setTimeout(function(){setDisplay("jspsych-btn","")}, 3000)},
is_html: true,
timeline: [{
stimulus: "<img src=" + ratings_rs[i] + "><br><br><br>"
}
]
});
}
};它适用于第一种情况(因为这非常简单)。
这只是我用JSPsych编写的第二个实验,所以我是一个新手,如果能提供任何帮助,我将不胜感激!
我现在有了这个:
if (cond2 == 'uniform') {
var uni = jsPsych.randomization.sampleWithoutReplacement([5, 5, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1]);
console.log(uni);
for (var i = 0; i < uni.length; i++) {
timeline.push({
type: "html-button-response",
choices: ['Click here to continue'],
button_html: '<button class="jspsych-btn" style="display:none">%choice%</button>',
on_start: function() { setTimeout(function(){setDisplay("jspsych-btn","")}, 3000)},
is_html: true,
timeline: [{
stimulus: "<img src=" + ratings[i] + "><br><br><br>"
}
]
});
}
} else if (cond2 == 'left-skew') {
var lesk = jsPsych.randomization.sampleWithoutReplacement([5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 3, 3, 3, 2, 2, 1]);
console.log(lesk);
for (var i = 0; i < lesk.length; i++) {
timeline.push({
type: "html-button-response",
choices: ['Click here to continue'],
button_html: '<button class="jspsych-btn" style="display:none">%choice%</button>',
on_start: function() { setTimeout(function(){setDisplay("jspsych-btn","")}, 3000)},
is_html: true,
timeline: [{
stimulus: "<img src=" + ratings[i] + "><br><br><br>"
}
]
});
}
} else {
var risk = jsPsych.randomization.sampleWithoutReplacement([1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5]);
console.log(risk);
for (var i = 0; i < risk.length; i++) {
timeline.push({
type: "html-button-response",
choices: ['Click here to continue'],
button_html: '<button class="jspsych-btn" style="display:none">%choice%</button>',
on_start: function() { setTimeout(function(){setDisplay("jspsych-btn","")}, 3000)},
is_html: true,
timeline: [{
stimulus: "<img src=" + ratings[i] + "><br><br><br>"
}
]
});
}
};我已经创建了一个混洗数组,它规定了呈现频率,但我不确定如何合并到循环中,以便图像呈现该次数。这些图像被标记为1、2、3、4、5。
发布于 2019-12-05 08:09:56
终于想出了一个可行的办法。
if (cond2 == 'uniform') {
var uni = jsPsych.randomization.sampleWithoutReplacement([5, 5, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1], 20);
console.log(uni);
for (var i = 0; i < uni.length; i++) {
timeline.push({
type: "html-button-response",
choices: ['Click here to continue'],
button_html: '<button class="jspsych-btn" style="display:none">%choice%</button>',
on_start: function() { setTimeout(function(){setDisplay("jspsych-btn","")}, 3000)},
is_html: true,
timeline: [{
stimulus: "<img src=./img/" + uni[i] + ".png><br><br><br>"
}
]
});
}
} else if (cond2 == 'left_skew') {
var lesk = jsPsych.randomization.sampleWithoutReplacement([5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 3, 3, 3, 2, 2, 1], 20);
console.log(lesk);
for (var i = 0; i < lesk.length; i++) {
timeline.push({
type: "html-button-response",
choices: ['Click here to continue'],
button_html: '<button class="jspsych-btn" style="display:none">%choice%</button>',
on_start: function() { setTimeout(function(){setDisplay("jspsych-btn","")}, 3000)},
is_html: true,
timeline: [{
stimulus: "<img src=./img/" + lesk[i] + ".png><br><br><br>"
}
]
});
}
} else {
var risk = jsPsych.randomization.sampleWithoutReplacement([1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5], 20);
console.log(risk);
for (var i = 0; i < risk.length; i++) {
timeline.push({
type: "html-button-response",
choices: ['Click here to continue'],
button_html: '<button class="jspsych-btn" style="display:none">%choice%</button>',
on_start: function() { setTimeout(function(){setDisplay("jspsych-btn","")}, 3000)},
is_html: true,
timeline: [{
stimulus: "<img src=./img/" + risk[i] + ".png><br><br><br>"
}
]
});
}
};
So I basically created an array specifying the frequency for each condition and called that in the for loop. https://stackoverflow.com/questions/59154173
复制相似问题