{ "cells": [ { "cell_type": "markdown", "id": "cell-0", "metadata": {}, "source": [ "# Example of a Db-efficient RUM design with ChoiceDesign\n", "\n", "This notebook illustrates how to use **ChoiceDesign** to generate a **Db-efficient** (Bayesian) experimental design for a Random Utility Maximisation (RUM) model.\n", "\n", "## What is a Db-efficient design?\n", "\n", "A standard Dp-efficient design minimises the D-error at fixed prior parameter values. The problem is that priors are always uncertain: if the assumed values are wrong, the resulting design can be suboptimal for estimation.\n", "\n", "A **Db-efficient design** (Sandor & Wedel, 2001) addresses this by treating the researcher's priors as random variables following a probability distribution. Instead of minimising a point D-error, it minimises the **Db-error** \u2014 the expected D-error integrated over the entire prior distribution:\n", "\n", "$$D_b\\text{-error} = \\mathbb{E}_{\\beta \\sim \\pi}\\left[\\det\\left(I(\\beta)^{-1}\\right)^{1/K}\\right]$$\n", "\n", "This is estimated by Monte Carlo: draw $R$ samples from the prior distribution, evaluate the D-error at each draw, and take the mean. The result is a design that performs well *on average* across the range of plausible true parameter values.\n", "\n", "> **Note:** This is different from a Random Parameters (Mixed Logit) design. In a Db design the uncertainty is the *researcher's* uncertainty about fixed true parameters. The underlying estimation model is still plain MNL." ] }, { "cell_type": "markdown", "id": "cell-1", "metadata": {}, "source": [ "## Step 1: Load modules, define design parameters and set attributes\n", "\n", "The following lines load:\n", "- `EffDesign`: the class of efficient designs,\n", "- `Attribute` and `Parameter`: the classes of attributes and parameters, respectively." ] }, { "cell_type": "code", "execution_count": 1, "id": "cell-2", "metadata": {}, "outputs": [], "source": [ "from choicedesign.design import EffDesign\n", "from choicedesign.expressions import Attribute, Parameter" ] }, { "cell_type": "markdown", "id": "cell-3", "metadata": {}, "source": [ "Each attribute is defined by the `Attribute` class. The arguments of this class are:\n", "\n", "* `name`: a string with the attribute name,\n", "* `levels`: a list of levels of the attribute.\n", "\n", "Each attribute is alternative-specific. The following lines define 2 alternatives, named `alt1` and `alt2`, and 4 attributes named from $A$ to $D$:" ] }, { "cell_type": "code", "execution_count": 2, "id": "cell-4", "metadata": {}, "outputs": [], "source": [ "alt1_A = Attribute('alt1_A', [1, 2, 3])\n", "alt1_B = Attribute('alt1_B', [10, 15, 15.5])\n", "alt1_C = Attribute('alt1_C', [0, 3, 5])\n", "alt1_D = Attribute('alt1_D', [0, 1, 2])\n", "\n", "alt2_A = Attribute('alt2_A', [1, 2, 3])\n", "alt2_B = Attribute('alt2_B', [10, 15, 15.5])\n", "alt2_C = Attribute('alt2_C', [0, 3, 5])\n", "alt2_D = Attribute('alt2_D', [0, 1, 2])" ] }, { "cell_type": "markdown", "id": "cell-5", "metadata": {}, "source": [ "## Step 2: Construct efficient design object and generate initial design matrix\n", "\n", "The second step consists of constructing the experimental design object, which requires the following parameters:\n", "\n", "- `X`: A list of `Attribute` class elements,\n", "- `ncs`: The number of choice situations." ] }, { "cell_type": "code", "execution_count": 3, "id": "cell-6", "metadata": {}, "outputs": [], "source": [ "design = EffDesign(\n", " X=[alt1_A, alt1_B, alt1_C, alt1_D,\n", " alt2_A, alt2_B, alt2_C, alt2_D],\n", " ncs=18)" ] }, { "cell_type": "code", "execution_count": 4, "id": "cell-7", "metadata": {}, "outputs": [ { "data": { "application/vnd.microsoft.datawrangler.viewer.v0+json": { "columns": [ { "name": "index", "rawType": "int64", "type": "integer" }, { "name": "alt1_A", "rawType": "float64", "type": "float" }, { "name": "alt1_B", "rawType": "float64", "type": "float" }, { "name": "alt1_C", "rawType": "float64", "type": "float" }, { "name": "alt1_D", "rawType": "float64", "type": "float" }, { "name": "alt2_A", "rawType": "float64", "type": "float" }, { "name": "alt2_B", "rawType": "float64", "type": "float" }, { "name": "alt2_C", "rawType": "float64", "type": "float" }, { "name": "alt2_D", "rawType": "float64", "type": "float" } ], "ref": "85fb0f99-6a6d-472e-8bea-72b6e3e43270", "rows": [ [ "0", "1.0", "10.0", "5.0", "1.0", "2.0", "15.5", "5.0", "2.0" ], [ "1", "2.0", "15.0", "3.0", "2.0", "3.0", "15.0", "5.0", "0.0" ], [ "2", "3.0", "10.0", "5.0", "1.0", "2.0", "15.5", "5.0", "1.0" ], [ "3", "3.0", "15.5", "0.0", "1.0", "1.0", "10.0", "3.0", "2.0" ], [ "4", "1.0", "15.5", "3.0", "0.0", "1.0", "15.5", "5.0", "0.0" ], [ "5", "2.0", "15.0", "3.0", "2.0", "3.0", "15.0", "3.0", "0.0" ], [ "6", "2.0", "10.0", "3.0", "2.0", "2.0", "10.0", "0.0", "1.0" ], [ "7", "1.0", "10.0", "0.0", "0.0", "3.0", "15.5", "0.0", "0.0" ], [ "8", "3.0", "15.5", "5.0", "0.0", "1.0", "10.0", "5.0", "2.0" ], [ "9", "3.0", "10.0", "0.0", "2.0", "2.0", "15.0", "0.0", "0.0" ], [ "10", "1.0", "10.0", "0.0", "0.0", "1.0", "15.5", "0.0", "0.0" ], [ "11", "3.0", "15.0", "5.0", "1.0", "3.0", "10.0", "3.0", "1.0" ], [ "12", "2.0", "15.0", "5.0", "2.0", "1.0", "15.0", "3.0", "1.0" ], [ "13", "1.0", "15.5", "3.0", "2.0", "3.0", "15.0", "0.0", "2.0" ], [ "14", "2.0", "15.5", "3.0", "0.0", "3.0", "15.5", "0.0", "1.0" ], [ "15", "2.0", "15.0", "5.0", "1.0", "2.0", "15.0", "5.0", "2.0" ], [ "16", "3.0", "15.5", "0.0", "1.0", "2.0", "10.0", "3.0", "2.0" ], [ "17", "1.0", "15.0", "0.0", "0.0", "1.0", "10.0", "3.0", "1.0" ] ], "shape": { "columns": 8, "rows": 18 } }, "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", " \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", " \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_Balt1_Calt1_Dalt2_Aalt2_Balt2_Calt2_D
01.010.05.01.02.015.55.02.0
12.015.03.02.03.015.05.00.0
23.010.05.01.02.015.55.01.0
33.015.50.01.01.010.03.02.0
41.015.53.00.01.015.55.00.0
52.015.03.02.03.015.03.00.0
62.010.03.02.02.010.00.01.0
71.010.00.00.03.015.50.00.0
83.015.55.00.01.010.05.02.0
93.010.00.02.02.015.00.00.0
101.010.00.00.01.015.50.00.0
113.015.05.01.03.010.03.01.0
122.015.05.02.01.015.03.01.0
131.015.53.02.03.015.00.02.0
142.015.53.00.03.015.50.01.0
152.015.05.01.02.015.05.02.0
163.015.50.01.02.010.03.02.0
171.015.00.00.01.010.03.01.0
\n", "
" ], "text/plain": [ " alt1_A alt1_B alt1_C alt1_D alt2_A alt2_B alt2_C alt2_D\n", "0 1.0 10.0 5.0 1.0 2.0 15.5 5.0 2.0\n", "1 2.0 15.0 3.0 2.0 3.0 15.0 5.0 0.0\n", "2 3.0 10.0 5.0 1.0 2.0 15.5 5.0 1.0\n", "3 3.0 15.5 0.0 1.0 1.0 10.0 3.0 2.0\n", "4 1.0 15.5 3.0 0.0 1.0 15.5 5.0 0.0\n", "5 2.0 15.0 3.0 2.0 3.0 15.0 3.0 0.0\n", "6 2.0 10.0 3.0 2.0 2.0 10.0 0.0 1.0\n", "7 1.0 10.0 0.0 0.0 3.0 15.5 0.0 0.0\n", "8 3.0 15.5 5.0 0.0 1.0 10.0 5.0 2.0\n", "9 3.0 10.0 0.0 2.0 2.0 15.0 0.0 0.0\n", "10 1.0 10.0 0.0 0.0 1.0 15.5 0.0 0.0\n", "11 3.0 15.0 5.0 1.0 3.0 10.0 3.0 1.0\n", "12 2.0 15.0 5.0 2.0 1.0 15.0 3.0 1.0\n", "13 1.0 15.5 3.0 2.0 3.0 15.0 0.0 2.0\n", "14 2.0 15.5 3.0 0.0 3.0 15.5 0.0 1.0\n", "15 2.0 15.0 5.0 1.0 2.0 15.0 5.0 2.0\n", "16 3.0 15.5 0.0 1.0 2.0 10.0 3.0 2.0\n", "17 1.0 15.0 0.0 0.0 1.0 10.0 3.0 1.0" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "init_design = design.gen_initdesign(seed=42)\n", "init_design" ] }, { "cell_type": "markdown", "id": "cell-8", "metadata": {}, "source": [ "## Step 3: Set the utility functions with uncertain priors\n", "\n", "For a Db-efficient design, each parameter can carry a `prior_std` argument that specifies the standard deviation of its prior distribution. The `prior` value is interpreted as the mean.\n", "\n", "* Parameters with `prior_std` set are treated as **uncertain** \u2014 draws are taken from $\\mathcal{N}(\\text{prior}, \\text{prior\\_std})$ during Db-error computation.\n", "* Parameters without `prior_std` (or with `prior_std=None`) are **fixed** \u2014 they contribute no uncertainty.\n", "\n", "Here, attributes $A$ and $B$ have uncertain priors; $C$ and $D$ are treated as known:" ] }, { "cell_type": "code", "execution_count": 5, "id": "cell-9", "metadata": {}, "outputs": [], "source": [ "beta_A = Parameter('beta_A', -0.1, prior_std=0.01) # uncertain: N(-0.1, 0.01)\n", "beta_B = Parameter('beta_B', -0.2, prior_std=0.03) # uncertain: N(-0.2, 0.03)\n", "beta_C = Parameter('beta_C', 0.1) # fixed prior\n", "beta_D = Parameter('beta_D', 0.15) # fixed prior" ] }, { "cell_type": "markdown", "id": "cell-10", "metadata": {}, "source": [ "The utility functions use the same linear MNL structure as any other example. There are no random draws inside the utility expression \u2014 the Bayesian averaging happens at the criterion level, not inside the utility tree:" ] }, { "cell_type": "code", "execution_count": 6, "id": "cell-11", "metadata": {}, "outputs": [], "source": [ "V1 = beta_A * alt1_A + beta_B * alt1_B + beta_C * alt1_C + beta_D * alt1_D\n", "V2 = beta_A * alt2_A + beta_B * alt2_B + beta_C * alt2_C + beta_D * alt2_D\n", "\n", "V = {1: V1, 2: V2}" ] }, { "cell_type": "markdown", "id": "cell-12", "metadata": {}, "source": [ "## Step 4: Optimise the design minimising the Db-error\n", "\n", "The `optimise()` method accepts a `bayes_draws` argument. When set, the swapping algorithm minimises the **Db-error** (expected D-error over prior draws) instead of the point D-error.\n", "\n", "* `bayes_draws`: number of Monte Carlo draws from the prior distributions per D-error evaluation. Higher values reduce Monte Carlo noise at the cost of longer run times. Values between 200 and 1000 are typically sufficient.\n", "\n", "All other stopping criteria work as usual:" ] }, { "cell_type": "code", "execution_count": 7, "id": "cell-13", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Evaluating initial design\n", "Optimization complete 0:00:59 / D-error: 0.042138\n", "Elapsed time: 0:01:00\n", "D-error of initial design: 0.099028\n", "D-error of last stored design: 0.042138\n", "Utility Balance ratio: 82.87 %\n", "Algorithm iterations: 471\n", "\n" ] } ], "source": [ "optimal_design, init_perf, final_perf, final_iter, ubalance_ratio = design.optimise(\n", " init_design=init_design,\n", " V=V,\n", " bayes_draws=500,\n", " time_lim=1,\n", " verbose=True\n", ")" ] }, { "cell_type": "markdown", "id": "cell-14", "metadata": {}, "source": [ "## Step 5: Compare Db-error vs point D-error\n", "\n", "The `evaluate()` method also accepts `bayes_draws`. Calling it with and without this argument shows the difference between the Db-error (what the design was optimised for) and the point D-error (what a Dp design would report at the prior means).\n", "\n", "A well-calibrated Db design will have a higher point D-error than a Dp design optimised at the same prior means \u2014 that is the cost of robustness. The benefit is a design that degrades more gracefully when the true parameters differ from the assumed priors." ] }, { "cell_type": "code", "execution_count": 8, "id": "cell-15", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Db-error (robust, averaged over prior draws): 0.042240\n", "Dp-error (point, evaluated at prior means): 0.042150\n", "Utility balance: 82.87 %\n" ] } ], "source": [ "db_error, ubalance_db = design.evaluate(optimal_design, V, bayes_draws=500)\n", "dp_error, ubalance_dp = design.evaluate(optimal_design, V)\n", "\n", "print(f'Db-error (robust, averaged over prior draws): {db_error:.6f}')\n", "print(f'Dp-error (point, evaluated at prior means): {dp_error:.6f}')\n", "print(f'Utility balance: {ubalance_dp:.2f} %')" ] }, { "cell_type": "markdown", "id": "cell-16", "metadata": {}, "source": [ "## (optional) Block the design\n", "\n", "The optimal design can be blocked using `gen_blocks()`. This method randomly creates candidate blocks and keeps the one with the minimum correlation between the blocking column and all attributes:" ] }, { "cell_type": "code", "execution_count": 9, "id": "cell-17", "metadata": {}, "outputs": [ { "data": { "application/vnd.microsoft.datawrangler.viewer.v0+json": { "columns": [ { "name": "index", "rawType": "int64", "type": "integer" }, { "name": "CS", "rawType": "float64", "type": "float" }, { "name": "alt1_A", "rawType": "float64", "type": "float" }, { "name": "alt1_B", "rawType": "float64", "type": "float" }, { "name": "alt1_C", "rawType": "float64", "type": "float" }, { "name": "alt1_D", "rawType": "float64", "type": "float" }, { "name": "alt2_A", "rawType": "float64", "type": "float" }, { "name": "alt2_B", "rawType": "float64", "type": "float" }, { "name": "alt2_C", "rawType": "float64", "type": "float" }, { "name": "alt2_D", "rawType": "float64", "type": "float" }, { "name": "Block", "rawType": "int64", "type": "integer" } ], "ref": "0848d3e6-29e3-4433-9301-3ccbff155544", "rows": [ [ "0", "1.0", "1.0", "10.0", "5.0", "1.0", "2.0", "15.0", "0.0", "2.0", "2" ], [ "1", "2.0", "2.0", "15.5", "0.0", "2.0", "1.0", "10.0", "5.0", "0.0", "1" ], [ "2", "3.0", "3.0", "10.0", "0.0", "0.0", "1.0", "15.0", "5.0", "2.0", "3" ], [ "3", "4.0", "2.0", "15.0", "0.0", "1.0", "2.0", "10.0", "5.0", "1.0", "3" ], [ "4", "5.0", "3.0", "15.0", "5.0", "0.0", "1.0", "15.5", "0.0", "2.0", "2" ], [ "5", "6.0", "2.0", "15.0", "5.0", "2.0", "2.0", "15.5", "0.0", "0.0", "3" ], [ "6", "7.0", "3.0", "15.5", "3.0", "1.0", "2.0", "10.0", "0.0", "1.0", "2" ], [ "7", "8.0", "1.0", "10.0", "5.0", "1.0", "3.0", "15.0", "3.0", "1.0", "1" ], [ "8", "9.0", "3.0", "15.0", "0.0", "1.0", "1.0", "15.0", "3.0", "1.0", "1" ], [ "9", "10.0", "1.0", "10.0", "0.0", "2.0", "3.0", "15.5", "5.0", "0.0", "3" ], [ "10", "11.0", "1.0", "15.0", "0.0", "0.0", "3.0", "15.5", "5.0", "2.0", "1" ], [ "11", "12.0", "2.0", "15.5", "5.0", "2.0", "3.0", "10.0", "0.0", "0.0", "3" ], [ "12", "13.0", "3.0", "10.0", "3.0", "2.0", "1.0", "15.5", "5.0", "0.0", "2" ], [ "13", "14.0", "1.0", "15.0", "3.0", "0.0", "3.0", "15.0", "3.0", "1.0", "2" ], [ "14", "15.0", "1.0", "15.5", "3.0", "0.0", "3.0", "10.0", "0.0", "2.0", "2" ], [ "15", "16.0", "2.0", "10.0", "3.0", "1.0", "2.0", "15.5", "3.0", "1.0", "1" ], [ "16", "17.0", "2.0", "15.5", "3.0", "2.0", "2.0", "10.0", "3.0", "0.0", "1" ], [ "17", "18.0", "3.0", "15.5", "5.0", "0.0", "1.0", "15.0", "3.0", "2.0", "3" ] ], "shape": { "columns": 10, "rows": 18 } }, "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", " \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", " \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", "
CSalt1_Aalt1_Balt1_Calt1_Dalt2_Aalt2_Balt2_Calt2_DBlock
01.01.010.05.01.02.015.00.02.02
12.02.015.50.02.01.010.05.00.01
23.03.010.00.00.01.015.05.02.03
34.02.015.00.01.02.010.05.01.03
45.03.015.05.00.01.015.50.02.02
56.02.015.05.02.02.015.50.00.03
67.03.015.53.01.02.010.00.01.02
78.01.010.05.01.03.015.03.01.01
89.03.015.00.01.01.015.03.01.01
910.01.010.00.02.03.015.55.00.03
1011.01.015.00.00.03.015.55.02.01
1112.02.015.55.02.03.010.00.00.03
1213.03.010.03.02.01.015.55.00.02
1314.01.015.03.00.03.015.03.01.02
1415.01.015.53.00.03.010.00.02.02
1516.02.010.03.01.02.015.53.01.01
1617.02.015.53.02.02.010.03.00.01
1718.03.015.55.00.01.015.03.02.03
\n", "
" ], "text/plain": [ " CS alt1_A alt1_B alt1_C alt1_D alt2_A alt2_B alt2_C alt2_D \\\n", "0 1.0 1.0 10.0 5.0 1.0 2.0 15.0 0.0 2.0 \n", "1 2.0 2.0 15.5 0.0 2.0 1.0 10.0 5.0 0.0 \n", "2 3.0 3.0 10.0 0.0 0.0 1.0 15.0 5.0 2.0 \n", "3 4.0 2.0 15.0 0.0 1.0 2.0 10.0 5.0 1.0 \n", "4 5.0 3.0 15.0 5.0 0.0 1.0 15.5 0.0 2.0 \n", "5 6.0 2.0 15.0 5.0 2.0 2.0 15.5 0.0 0.0 \n", "6 7.0 3.0 15.5 3.0 1.0 2.0 10.0 0.0 1.0 \n", "7 8.0 1.0 10.0 5.0 1.0 3.0 15.0 3.0 1.0 \n", "8 9.0 3.0 15.0 0.0 1.0 1.0 15.0 3.0 1.0 \n", "9 10.0 1.0 10.0 0.0 2.0 3.0 15.5 5.0 0.0 \n", "10 11.0 1.0 15.0 0.0 0.0 3.0 15.5 5.0 2.0 \n", "11 12.0 2.0 15.5 5.0 2.0 3.0 10.0 0.0 0.0 \n", "12 13.0 3.0 10.0 3.0 2.0 1.0 15.5 5.0 0.0 \n", "13 14.0 1.0 15.0 3.0 0.0 3.0 15.0 3.0 1.0 \n", "14 15.0 1.0 15.5 3.0 0.0 3.0 10.0 0.0 2.0 \n", "15 16.0 2.0 10.0 3.0 1.0 2.0 15.5 3.0 1.0 \n", "16 17.0 2.0 15.5 3.0 2.0 2.0 10.0 3.0 0.0 \n", "17 18.0 3.0 15.5 5.0 0.0 1.0 15.0 3.0 2.0 \n", "\n", " Block \n", "0 2 \n", "1 1 \n", "2 3 \n", "3 3 \n", "4 2 \n", "5 3 \n", "6 2 \n", "7 1 \n", "8 1 \n", "9 3 \n", "10 1 \n", "11 3 \n", "12 2 \n", "13 2 \n", "14 2 \n", "15 1 \n", "16 1 \n", "17 3 " ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "optimal_design_blocked, corr_history = design.gen_blocks(optimal_design, n_blocks=3)\n", "optimal_design_blocked" ] }, { "cell_type": "markdown", "id": "cell-18", "metadata": {}, "source": [ "## References\n\n[1] Sandor, Z., & Wedel, M. (2001). Designing conjoint choice experiments using managers' prior beliefs. *Journal of Marketing Research*, 38(4), 430\u2013444.\n\n[2] Quan, W., Rose, J. M., Collins, A. T., & Bliemer, M. C. (2011). A comparison of algorithms for generating efficient choice experiments." ] } ], "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 }