1.1.1. patsy.balanced

patsy.balanced(factor_name=num_levels[, factor_name=num_levels, ..., repeat=1])[source]

Create simple balanced factorial designs for testing.

Given some factor names and the number of desired levels for each, generates a balanced factorial design in the form of a data dictionary. For example:

In [1]: balanced(a=2, b=3)
Out[1]: 
{'a': ['a1', 'a1', 'a1', 'a2', 'a2', 'a2'],
 'b': ['b1', 'b2', 'b3', 'b1', 'b2', 'b3']}

By default it produces exactly one instance of each combination of levels, but if you want multiple replicates this can be accomplished via the repeat argument:

In [2]: balanced(a=2, b=2, repeat=2)
Out[2]: 
{'a': ['a1', 'a1', 'a2', 'a2', 'a1', 'a1', 'a2', 'a2'],
 'b': ['b1', 'b2', 'b1', 'b2', 'b1', 'b2', 'b1', 'b2']}