PennController for IBEX › Forums › Support › RandomizeNoMoreThan
- This topic has 2 replies, 2 voices, and was last updated 2 years, 12 months ago by Elise.
-
AuthorPosts
-
September 10, 2021 at 6:14 am #7244EliseParticipant
Hi Jeremy,
I know that when I want to constrain multiple conditions to appear only a certain times in a row, I can use the randomizeNoMoreThan function:
Sequence(randomizeNoMoreThan(anyOf(startsWith("con-"), startsWith("incon-"), startsWith("neu-"),3)))
But is there any way that I can pseudorandomize conditions such that only one condition is constrained to appear three times in a row? E.g., I want the congruent condition (“con-“) to appear not more than three times in a row, but I don’t want to apply that contraint to the incongruent and the neutral condition.
I would be greatful for any help!
Best,
EliseSeptember 10, 2021 at 11:07 am #7248JeremyKeymasterHi 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 othercon-tst
, however, it will be OK with a sequence likecon-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
September 12, 2021 at 10:10 am #7252EliseParticipantThank you very much, Jeremy! It worked perfectly!
-
AuthorPosts
- You must be logged in to reply to this topic.