PennController for IBEX › Forums › Support › RandomizeNoMoreThan › Reply To: RandomizeNoMoreThan
September 10, 2021 at 11:07 am
#7248
Keymaster
Hi Elise,
The randomizeNoMoreThan function is based on exact match between labels: it will only make sure that, say, con-tst is not followed by more than two other con-tst, however, it will be OK with a sequence like con-tst–con-fil–con-tst–con-fil
You can minimally edit it, so that you can pass it predicates after n to identify which trials from the set it should target:
function RandomizeNoMoreThan(predicate,n,...filters) {
this.args = [predicate];
this.run = function(arrays) {
let moreThanN = true;
let order;
while (moreThanN){
order = randomize(predicate).run(arrays);
moreThanN = false;
let previousType = "";
let current_n = 0;
for (let i = 0; i < order.length; i++){
let currentType = order[i][0].type;
if (currentType==previousType || (filters.length&&filters.filter(f=>f(currentType)).length)){
current_n++;
if (current_n > n){
moreThanN = true;
break;
}
}
else{
current_n = 1;
previousType = currentType;
}
}
}
return order;
};
}
function randomizeNoMoreThan(predicate, n, ...filters) {
return new RandomizeNoMoreThan(predicate,n, ...filters);
}
Then you can use it like this:
Sequence(
randomizeNoMoreThan(
anyOf(startsWith("con-"), startsWith("incon-"), startsWith("neu-")),
3,
startsWith("con-")
)
)
and it will make sure that you have no subseries of more than three trials whose label starts with con- in a row (it will allow for 3+ series of trials with any other labels)
Jeremy