jsPsych version: 2021.2.3
url: Pavlovia
hi,
I am trying to build an experiment where participants reproduce a target duration by two space button presses (the interval between the two button presses is what the reproduction stands for in this design). at first, participants are asked to reproduce the target for 90 times. in the further blocks, I will present these reproductions by randomly choosing 30 of them according to some predetermined criteria. in one block, I want to choose 30 of these 90 reproductions that make (e.g.,) distribution with coefficient of variation (i.e., std / mean reproduction) that is 10% above the original (i.e., the distribution with all the 90 reproductions) distribution or 10% below the original or somewhere in between 101% - 99%. In some of the blocks, I create my own random distributions with the same parameters. I am using the loops below for the depicted scenario:
function shuffle(a) {
var j, x, i;
for (i = a.length - 1; i > 0; i--) {
j = Math.floor(Math.random() * (i + 1));
x = a[i];
a[i] = a[j];
a[j] = x;
}
return a;
}
function generateGaussian(mean,std, n){
var a = [];
for (let i = 0; i < n; i++) {
var _2PI = Math.PI * 2;
var u1 = Math.random();
var u2 = Math.random();
var z0 = Math.sqrt(-2.0 * Math.log(u1)) * Math.cos(_2PI * u2);
var z1 = Math.sqrt(-2.0 * Math.log(u1)) * Math.sin(_2PI * u2);
a.push(z0 * std + mean);
}
return a;
}
function getRandomSubarray(arr, size) {
var shuffled = arr.slice(0), i = arr.length, temp, index;
while (i--) {
index = Math.floor((i + 1) * Math.random());
temp = shuffled[index];
shuffled[index] = shuffled[i];
shuffled[i] = temp;
}
return shuffled.slice(0, size);
}
console.log(all_repro);
shuffle(all_repro);
psychoJS.experiment.addData("all_repro_shuffled", all_repro);
mean_repro = all_repro.reduce((a, b) => a + b) / all_repro.length;
console.log(mean_repro)
stdev_repro = Math.sqrt(all_repro.reduce((s,n) => s + (n - mean_repro) ** 2, 0) / (all_repro.length - 1));
console.log(stdev_repro)
cv_original = (stdev_repro / mean_repro);
console.log(cv_original);
self_rep_high = [];
self_rep_medium = [];
self_rep_low = [];
cv_upper = (cv_original * 1.1);
console.log(cv_upper)
cv_lower = (cv_original * 0.9);
console.log(cv_lower)
cv_upper_same = (cv_original * 1.001);
console.log(cv_upper_same)
cv_lower_same = (cv_original * 0.999);
console.log(cv_lower_same)
psychoJS.experiment.addData("cv_upper", cv_upper);
psychoJS.experiment.addData("cv_lower", cv_lower);
psychoJS.experiment.addData("cv_upper_same", cv_upper_same);
psychoJS.experiment.addData("cv_lower_same", cv_lower_same);
var p;
p = getRandomSubarray(all_repro, 30);
console.log(p)
var t;
var mean_t;
var std_t;
var check_val;
var mean_p;
var std_p;
mean_p = p.reduce((a, b) => a + b) / p.length;
console.log(mean_p)
std_p = Math.sqrt(p.reduce((s,n) => s + (n - mean_p) ** 2, 0) / (p.length - 1));
console.log(std_p)
selfhigh_cv = (std_p / mean_p);
console.log(selfhigh_cv)
while ((selfhigh_cv < cv_upper)) {
p = getRandomSubarray(all_repro, 30);
console.log(p)
mean_p = p.reduce((a, b) => a + b) / p.length;
console.log(mean_p)
std_p = Math.sqrt(p.reduce((s,n) => s + (n - mean_p) ** 2, 0) / (p.length - 1));
console.log(std_p)
selfhigh_cv = (std_p / mean_p);
console.log(selfhigh_cv) //// never ends
}
self_rep_high = p;
console.log(self_rep_high)
psychoJS.experiment.addData("self_rep_high", self_rep_high);
psychoJS.experiment.addData("selfhigh_cv", selfhigh_cv);
p = getRandomSubarray(all_repro, 30);
console.log(p)
mean_p = p.reduce((a, b) => a + b) / p.length;
console.log(mean_p)
std_p = Math.sqrt(p.reduce((s,n) => s + (n - mean_p) ** 2, 0) / (p.length - 1));
console.log(std_p)
selflow_cv = (std_p / mean_p);
console.log(selflow_cv)
while ((selflow_cv > cv_lower)) {
p = getRandomSubarray(all_repro, 30);
console.log(p)
mean_p = p.reduce((a, b) => a + b) / p.length;
console.log(mean_p)
std_p = Math.sqrt(p.reduce((s,n) => s + (n - mean_p) ** 2, 0) / (p.length - 1));
console.log(std_p)
selflow_cv = (std_p / mean_p);
console.log(selflow_cv)
}
self_rep_low = p;
console.log(self_rep_low);
psychoJS.experiment.addData("self_rep_low", self_rep_low);
psychoJS.experiment.addData("selflow_cv", selflow_cv);
p = getRandomSubarray(all_repro, 30);
console.log(p)
mean_p = p.reduce((a, b) => a + b) / p.length;
console.log(mean_p)
std_p = Math.sqrt(p.reduce((s,n) => s + (n - mean_p) ** 2, 0) / (p.length - 1));
console.log(std_p)
selfsame_cv = (std_p / mean_p);
console.log(selfsame_cv)
while ((! ((selfsame_cv > cv_lower_same) && (selfsame_cv < cv_upper_same)))) { //burada hata
p = getRandomSubarray(all_repro, 30);
console.log(p)
mean_p = p.reduce((a, b) => a + b) / p.length;
console.log(mean_p)
std_p = Math.sqrt(p.reduce((s,n) => s + (n - mean_p) ** 2, 0) / (p.length - 1));
console.log(std_p)
selfsame_cv = (std_p / mean_p);
}
self_rep_medium = p;
console.log(self_rep_medium)
psychoJS.experiment.addData("self_rep_medium", self_rep_medium);
psychoJS.experiment.addData("selfsame_cv", selfsame_cv);
obs_rep = [];
other_rep_high = [];
other_rep_medium = [];
other_rep_low = [];
for (var i, _pj_c = 0, _pj_a = util.range(0, 90), _pj_b = _pj_a.length; (_pj_c < _pj_b); _pj_c += 1) {
i = _pj_a[_pj_c];
check_val = generateGaussian(mean_repro, stdev_repro,1);
console.log(check_val)
while ((check_val < 0)) {
check_val = generateGaussian(mean_repro, stdev_repro,1);
console.log(check_val)
}
obs_rep.push(check_val);
console.log(obs_rep)
}
psychoJS.experiment.addData("obs_rep", obs_rep);
mean_repro_obs = obs_rep.reduce((a, b) => a + b) / obs_rep.length
console.log(mean_repro_obs)
stdev_repro_obs = Math.sqrt(obs_rep.reduce((s,n) => s + (n - mean_repro_obs) ** 2, 0) / (obs_rep.length - 1));
console.log(stdev_repro_obs)
psychoJS.experiment.addData('mean_repro_obs',mean_repro_obs);
psychoJS.experiment.addData('stdev_repro_obs',stdev_repro_obs);
p = getRandomSubarray(all_repro, 30);
console.log(p)
mean_p = p.reduce((a, b) => a + b) / p.length;
console.log(mean_p)
std_p = Math.sqrt(p.reduce((s,n) => s + (n - mean_p) ** 2, 0) / (p.length - 1));
console.log(std_p)
otherhigh_cv = (std_p / mean_p);
console.log(otherhigh_cv)
while ((selfhigh_cv < cv_upper)) {
p = getRandomSubarray(obs_rep, 30);
console.log(p)
mean_p = p.reduce((a, b) => a + b) / p.length;
console.log(mean_p)
std_p = Math.sqrt(p.reduce((s,n) => s + (n - mean_p) ** 2, 0) / (p.length - 1));
console.log(std_p)
otherhigh_cv = (std_p / mean_p);
console.log(otherhigh_cv)
}
other_rep_high = p;
console.log(other_rep_high)
psychoJS.experiment.addData("other_rep_high", other_rep_high);
psychoJS.experiment.addData("otherhigh_cv", otherhigh_cv);
p = getRandomSubarray(all_repro, 30);
console.log(p)
mean_p = p.reduce((a, b) => a + b) / p.length;
console.log(mean_p)
std_p = Math.sqrt(p.reduce((s,n) => s + (n - mean_p) ** 2, 0) / (p.length - 1));
console.log(std_p)
otherlow_cv = (std_p / mean_p);
console.log(otherlow_cv)
while ((selflow_cv > cv_lower)) {
p = getRandomSubarray(obs_rep, 30);
console.log(p)
mean_p = p.reduce((a, b) => a + b) / p.length;
console.log(mean_p)
std_p = Math.sqrt(p.reduce((s,n) => s + (n - mean_p) ** 2, 0) / (p.length - 1));
console.log(std_p)
otherlow_cv = (std_p / mean_p);
console.log(otherlow_cv)
}
other_rep_low = p;
console.log(other_rep_low)
psychoJS.experiment.addData("other_rep_low", other_rep_low);
psychoJS.experiment.addData("otherlow_cv", otherlow_cv);
p = getRandomSubarray(all_repro, 30);
console.log(p)
mean_p = p.reduce((a, b) => a + b) / p.length;
console.log(mean_p)
std_p = Math.sqrt(p.reduce((s,n) => s + (n - mean_p) ** 2, 0) / (p.length - 1));
console.log(std_p)
othersame_cv = (std_p / mean_p);
while ((! ((othersame_cv > cv_lower_same) && (othersame_cv < cv_upper_same)))) {
p = getRandomSubarray(obs_rep, 30);
console.log(p)
mean_p = p.reduce((a, b) => a + b) / p.length;
console.log(mean_p)
std_p = Math.sqrt(p.reduce((s,n) => s + (n - mean_p) ** 2, 0) / (p.length - 1));
console.log(std_p)
othersame_cv = (std_p / mean_p);
console.log(othersame_cv)
}
other_rep_medium = p;
console.log(other_rep_medium)
psychoJS.experiment.addData("other_rep_medium", other_rep_medium);
psychoJS.experiment.addData("othersame_cv", othersame_cv);
I am nearly sure that the values that are being checked in the while loop are changing. I’ve also checked from the console to make sure. But after a while, the code gives Page Unresponsive warning and thus, the experiment does not continue as it should do.
I have made my experiment open to public view, any idea for the solution?
thanks so much for the effort in advance, t