{ "cells": [ { "cell_type": "markdown", "id": "cell-0", "metadata": {}, "source": [ "# Example of a full-factorial design with ChoiceDesign\n", "\n", "This notebook illustrates how to use **ChoiceDesign** to generate a simple full-factorial experimental design.\n", "\n", "## Step 1: Load modules and define attributes" ] }, { "cell_type": "code", "execution_count": 1, "id": "cell-1", "metadata": {}, "outputs": [], "source": [ "from choicedesign.design import FullFactDesign\n", "from choicedesign.expressions import Attribute" ] }, { "cell_type": "markdown", "id": "cell-2", "metadata": {}, "source": [ "Each attribute is defined with `Attribute(name, levels)`. The following lines define 4 attributes across 2 alternatives:" ] }, { "cell_type": "code", "execution_count": 2, "id": "cell-3", "metadata": {}, "outputs": [], "source": [ "alt1_A = Attribute('alt1_A', [1, 2, 3])\n", "alt1_B = Attribute('alt1_B', [10, 15, 15.5])\n", "\n", "alt2_A = Attribute('alt2_A', [1, 2, 3])\n", "alt2_C = Attribute('alt2_C', [0, 3, 5])" ] }, { "cell_type": "markdown", "id": "cell-4", "metadata": {}, "source": [ "## Step 2: Construct design object and generate the design matrix\n", "\n", "`FullFactDesign` takes a list of `Attribute` objects. `gen_design()` returns a DataFrame with all combinations of attribute levels (3×3×3×3 = 81 rows)." ] }, { "cell_type": "code", "execution_count": 3, "id": "cell-5", "metadata": {}, "outputs": [ { "data": { "application/vnd.microsoft.datawrangler.viewer.v0+json": { "columns": [ { "name": "index", "rawType": "int64", "type": "integer" }, { "name": "alt1_A", "rawType": "int64", "type": "integer" }, { "name": "alt1_B", "rawType": "float64", "type": "float" }, { "name": "alt2_A", "rawType": "int64", "type": "integer" }, { "name": "alt2_C", "rawType": "int64", "type": "integer" } ], "ref": "ea9b4ddf-d0f3-4e98-8c4b-a90a2a5a00cc", "rows": [ [ "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" ], [ "5", "1", "10.0", "2", "5" ], [ "6", "1", "10.0", "3", "0" ], [ "7", "1", "10.0", "3", "3" ], [ "8", "1", "10.0", "3", "5" ], [ "9", "1", "15.0", "1", "0" ], [ "10", "1", "15.0", "1", "3" ], [ "11", "1", "15.0", "1", "5" ], [ "12", "1", "15.0", "2", "0" ], [ "13", "1", "15.0", "2", "3" ], [ "14", "1", "15.0", "2", "5" ], [ "15", "1", "15.0", "3", "0" ], [ "16", "1", "15.0", "3", "3" ], [ "17", "1", "15.0", "3", "5" ], [ "18", "1", "15.5", "1", "0" ], [ "19", "1", "15.5", "1", "3" ], [ "20", "1", "15.5", "1", "5" ], [ "21", "1", "15.5", "2", "0" ], [ "22", "1", "15.5", "2", "3" ], [ "23", "1", "15.5", "2", "5" ], [ "24", "1", "15.5", "3", "0" ], [ "25", "1", "15.5", "3", "3" ], [ "26", "1", "15.5", "3", "5" ], [ "27", "2", "10.0", "1", "0" ], [ "28", "2", "10.0", "1", "3" ], [ "29", "2", "10.0", "1", "5" ], [ "30", "2", "10.0", "2", "0" ], [ "31", "2", "10.0", "2", "3" ], [ "32", "2", "10.0", "2", "5" ], [ "33", "2", "10.0", "3", "0" ], [ "34", "2", "10.0", "3", "3" ], [ "35", "2", "10.0", "3", "5" ], [ "36", "2", "15.0", "1", "0" ], [ "37", "2", "15.0", "1", "3" ], [ "38", "2", "15.0", "1", "5" ], [ "39", "2", "15.0", "2", "0" ], [ "40", "2", "15.0", "2", "3" ], [ "41", "2", "15.0", "2", "5" ], [ "42", "2", "15.0", "3", "0" ], [ "43", "2", "15.0", "3", "3" ], [ "44", "2", "15.0", "3", "5" ], [ "45", "2", "15.5", "1", "0" ], [ "46", "2", "15.5", "1", "3" ], [ "47", "2", "15.5", "1", "5" ], [ "48", "2", "15.5", "2", "0" ], [ "49", "2", "15.5", "2", "3" ] ], "shape": { "columns": 4, "rows": 81 } }, "text/html": [ "
| \n", " | alt1_A | \n", "alt1_B | \n", "alt2_A | \n", "alt2_C | \n", "
|---|---|---|---|---|
| 0 | \n", "1 | \n", "10.0 | \n", "1 | \n", "0 | \n", "
| 1 | \n", "1 | \n", "10.0 | \n", "1 | \n", "3 | \n", "
| 2 | \n", "1 | \n", "10.0 | \n", "1 | \n", "5 | \n", "
| 3 | \n", "1 | \n", "10.0 | \n", "2 | \n", "0 | \n", "
| 4 | \n", "1 | \n", "10.0 | \n", "2 | \n", "3 | \n", "
| ... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
| 76 | \n", "3 | \n", "15.5 | \n", "2 | \n", "3 | \n", "
| 77 | \n", "3 | \n", "15.5 | \n", "2 | \n", "5 | \n", "
| 78 | \n", "3 | \n", "15.5 | \n", "3 | \n", "0 | \n", "
| 79 | \n", "3 | \n", "15.5 | \n", "3 | \n", "3 | \n", "
| 80 | \n", "3 | \n", "15.5 | \n", "3 | \n", "5 | \n", "
81 rows × 4 columns
\n", "