ListRandomizer.factors()#

classmethod ListRandomizer.factors(*factors, n, **kwargs)[source]#

Alternative constructor, creates a balanced ListRandomizer where the conditions are combinations of several factors.

Parameters
  • *factors – A variable number of iterables, giving the factors to be used in forming the conditions.

  • n (int) – The number of participants per condition.

  • **kwargs – Keyword arguments, passed on the normal intialization of ListRandomizer.

In elaborated quota-balanced designs, you may end up with a lot of different conditions when combining all different possible values of your factos. Typing them by hand is tedious. To make your life easier, you can now simply input the factors themselves, and alfred3 will construct the combinations for you. The values of the individual factors will be separated by dots.

Note

Note that, in Python, strings are iterables. That means, that a call like ListRandomizer.factors("ab", "cd", ...) will combine the individual characters within the strings. The resulting conditions in this case will be ["a.c", "a.d", "b.c", "b.d"]. If you want to include a single string on its own, put in in a list: ListRandomizer.factors("ab", ["cd"], ...) will create two conditions: ["a.cd", "b.cd"].

New in version 2.1.7.

Examples

Use the factors() constructor to create conditions:

import alfred3 as al

exp = al.Experiment()

@exp.setup
def setup(exp):
    randomizer = l.ListRandomizer.factors(
        ["a1", "a2"], ["b1", "b2"],
        n=20,
        exp=exp
    )

    exp.condition = randomizer.get_condition()

    print(randomizer.conditions)
    # (('a1.b1', 20), ('a1.b2', 20), ('a2.b1', 20), ('a2.b2', 20))

Use the factors() constructor to create conditions, then do something for all sessions that contain a specific factor value:

import alfred3 as al

exp = al.Experiment()

@exp.setup
def setup(exp):
    randomizer = al.ListRandomizer.factors(
        ["a1", "a2"], ["b1", "b2"],
        n=20,
        exp=exp
    )

    exp.condition = randomizer.get_condition()

    if "a1" in exp.condition:
        # do something only for conditions with a1
        pass