RandomizeNoMoreThan

PennController for IBEX Forums Support RandomizeNoMoreThan

This topic contains 2 replies, has 2 voices, and was last updated by Avatar Elise 1 week, 1 day ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #7244
    Avatar
    Elise
    Participant

    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,
    Elise

    #7248
    Jeremy
    Jeremy
    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-tstcon-filcon-tstcon-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

    #7252
    Avatar
    Elise
    Participant

    Thank you very much, Jeremy! It worked perfectly!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.