{ "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", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
alt1_Aalt1_Balt2_Aalt2_C
0110.010
1110.013
2110.015
3110.020
4110.023
...............
76315.523
77315.525
78315.530
79315.533
80315.535
\n", "

81 rows × 4 columns

\n", "
" ], "text/plain": [ " alt1_A alt1_B alt2_A alt2_C\n", "0 1 10.0 1 0\n", "1 1 10.0 1 3\n", "2 1 10.0 1 5\n", "3 1 10.0 2 0\n", "4 1 10.0 2 3\n", ".. ... ... ... ...\n", "76 3 15.5 2 3\n", "77 3 15.5 2 5\n", "78 3 15.5 3 0\n", "79 3 15.5 3 3\n", "80 3 15.5 3 5\n", "\n", "[81 rows x 4 columns]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "design = FullFactDesign(X=[alt1_A, alt1_B, alt2_A, alt2_C])\n", "full_design = design.gen_design()\n", "full_design" ] } ], "metadata": { "kernelspec": { "display_name": "choicedesign-oSBhddzi-py3.13", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.1" } }, "nbformat": 4, "nbformat_minor": 5 }