Example of a full-factorial design with ChoiceDesign
This notebook illustrates how to use ChoiceDesign to generate a simple full-factorial experimental design.
Step 1: Load modules and define attributes
[1]:
from choicedesign.design import FullFactDesign
from choicedesign.expressions import Attribute
Each attribute is defined with Attribute(name, levels). The following lines define 4 attributes across 2 alternatives:
[2]:
alt1_A = Attribute('alt1_A', [1, 2, 3])
alt1_B = Attribute('alt1_B', [10, 15, 15.5])
alt2_A = Attribute('alt2_A', [1, 2, 3])
alt2_C = Attribute('alt2_C', [0, 3, 5])
Step 2: Construct design object and generate the design matrix
FullFactDesign takes a list of Attribute objects. gen_design() returns a DataFrame with all combinations of attribute levels (3×3×3×3 = 81 rows).
[3]:
design = FullFactDesign(X=[alt1_A, alt1_B, alt2_A, alt2_C])
full_design = design.gen_design()
full_design
[3]:
| alt1_A | alt1_B | alt2_A | alt2_C | |
|---|---|---|---|---|
| 0 | 1 | 10.0 | 1 | 0 |
| 1 | 1 | 10.0 | 1 | 3 |
| 2 | 1 | 10.0 | 1 | 5 |
| 3 | 1 | 10.0 | 2 | 0 |
| 4 | 1 | 10.0 | 2 | 3 |
| ... | ... | ... | ... | ... |
| 76 | 3 | 15.5 | 2 | 3 |
| 77 | 3 | 15.5 | 2 | 5 |
| 78 | 3 | 15.5 | 3 | 0 |
| 79 | 3 | 15.5 | 3 | 3 |
| 80 | 3 | 15.5 | 3 | 5 |
81 rows × 4 columns