Find optimal bundle in a conjoint experiment with Tabu Search
Gradient Metrics
2025-10-17
Source:vignettes/tabu_search.Rmd
tabu_search.RmdUse case
People are largely unable to determine why they make certain choices. For businesses, finding out consumer preferences, and their willingness to pay for certain features, is an essential ingredient to a successful strategy.
Conjoint (consider jointly) experiments are held to allow a respondent to pick an option between a set of concepts. Each option is called a concept while the full view is called a task. Each respondent is presented many tasks. Concepts are listed with a set of attributes, where some of the attributes (called top level) affect levels within other attributes.
Thanks to such a joint experiment researchers are able, even with a small sample size, to extract the magnitude of influence each considered attribute provides to a specific concept.
Business use cases are known to determine between walk-in options in medical and sport centers, political use cases overlap the candidates/parties preferences in comparison to their programme/believes. One could even apply a conjoint study to determine his/hers willingness to pick an option during car, house or vacation selection. This type of study lets researchers understand the underlying drivers responsible for making a choice.
The biggest use case of this study however is to determine the best bundle (a set of presented concepts) that either maximizes the share (in comparison to NONE option) or a revenue. A compromise between those two is also a challenge.
Tabu search
When finding the optimal bundle (a set of concepts that brings the
biggest revenue or market share) one can consider
scoring all possible bundles. However that is not always
possible since the number of possible bundles can exceed gazillion
options. Another way of looking for a candidate that brings high revenue
in comparison to other bundles is desired. One way to do that is to
follow the tabu search method which in short terms
- picks initial candidate for the biggest revenue maker
- seeks for close/similar bundles (substitute one level to another), that are called neighbours
- scores all considered neighbours in comparison to the initial
candidate
- the score is made thanks to the parameters of the multi logisitic regression model
- when shares are calculated, they can be used to calculate the revenue
- if any neighbour is better than the initial candidate, change this
winner with the initial candidate and repeat the procedure until
specified
max_iterations - in each iteration don’t consider winners from previous n (maxTabuSize) iterations, not to go back and forth in the optimization routine
As stated above, tabu search needs a function that can generate neighbourhood and the function that can calculate the measure of goodness, which is often the share of the revenue. The second function is said to be named fit or fitness.
Recent conjoint projects
Let’s see how the flow look like for the recent projects. We are aiming to find the bundle, that maximizes the market share in comparison to NONE option, so we only focus on designs that used NONE option in their setup.
cbc_fp <- cjt_read_toy_data("CBC-FP", none = 'SRN')
cbc_fp_asserted <- cjt_assert_data(cbc_fp, id = 'response_id', n_choices = 2, none_value = 3, n_tasks = 12)
cbc_fp_tidy <- cjt_tidy_data(cbc_fp_asserted)
cbc_fp_model <- cjt_model(cbc_fp_tidy, mcmc = list(R = 500, use = 500))Once the data is in the tidy format and the model was applied, we are able to use the model and the initial candidate, to find the best possible bundle in it’s neighbourhood with the help of Tabu Search.
cjt_candidate_1 <-
cbc_fp_model$pwu_grid %>%
select(attribute_name, level_name) %>%
unique %>%
mutate(level_name = janitor::make_clean_names(level_name)) %>%
group_by(attribute_name) %>%
top_n(1, level_name) %>%
filter(level_name != 'none') %>%
spread(attribute_name, level_name) %>%
mutate(main = 'main')
cjt_candidate_2 <-
cbc_fp_model$pwu_grid %>%
select(attribute_name, level_name) %>%
unique %>%
mutate(level_name = janitor::make_clean_names(level_name)) %>%
group_by(attribute_name) %>%
top_n(2, level_name) %>%
filter(level_name != 'none') %>%
ungroup %>%
mutate(hlp = rep(1:2, nrow(.)/2)) %>%
spread(attribute_name, level_name) %>%
select(-hlp) %>%
mutate(main = 'main')
cjt_candidate_3 <-
cbc_fp_model$pwu_grid %>%
select(attribute_name, level_name) %>%
unique %>%
mutate(level_name = janitor::make_clean_names(level_name)) %>%
group_by(attribute_name) %>%
top_n(3, level_name) %>%
filter(level_name != 'none') %>%
ungroup %>%
mutate(hlp = rep(1:3, nrow(.)/3)) %>%
spread(attribute_name, level_name) %>%
select(-hlp) %>%
mutate(main = 'main')Let us use initial candidate with one possible option, two possible
options and three possible options. The main column is just
here to allow the usage of top_level attribute specific levels and
values. For those studies we didn’t have any top_level attributes that
had their own specific values, so this needs to be provided but doesn’t
do anything.
cjt_candidate_1
cjt_candidate_2
cjt_candidate_3The application of the search is below.
cjt_optim(cbc_fp_model,
cjt_candidate_1,
max_iterations = 100,
max_tabu_size = 100)
cjt_optim(cbc_fp_model,
cjt_candidate_2,
max_iterations = 100,
max_tabu_size = 100)
cjt_optim(cbc_fp_model,
cjt_candidate_3,
max_iterations = 100,
max_tabu_size = 100)Application for DRN
cbc_fp_drn <- cjt_read_toy_data("CBC-FP", none = 'DRN')
cbc_fp_drn_asserted <- cjt_assert_data(cbc_fp_drn, id = 'response_id', n_choices = 2, none_value = 3, n_tasks = 15)
cbc_fp_drn_tidy <- cjt_tidy_data(cbc_fp_drn_asserted, DRN_pattern = 'actual')
cbc_fp_drn_model <- cjt_model(cbc_fp_drn_tidy, mcmc = list(R = 500, use = 500))
cjt_candidate_drn_3 <-
cbc_fp_drn_model$pwu_grid %>%
select(attribute_name, level_name) %>%
unique %>%
mutate(level_name = janitor::make_clean_names(level_name)) %>%
group_by(attribute_name) %>%
top_n(3, level_name) %>%
filter(level_name != 'none') %>%
ungroup %>%
mutate(hlp = rep(1:3, nrow(.)/3)) %>%
spread(attribute_name, level_name) %>%
select(-hlp) %>%
mutate(main = 'main')
cjt_optim(cbc_fp_drn_model,
cjt_candidate_drn_3,
max_iterations = 100,
max_tabu_size = 100)Bain project - conjoint with pricing
Let us use the bain project data
Where a candidate for the best bundle listed below
ds_bain_candidatepresents attributes that were considered. We can see that there is a
top_level variable that enables only possible levels to be
displayed for other attributes. The set of possible levels is assigned
to the meta_design object that for each top level variable
list levels for each considered attribute
bain_meta_design <-
list(
value = list(
message = c(1:2, 4) ,
quality = 1,
embellish = 1,
money_option = 1:6,
fake_numeric = c(3, 6, 8, 10)
),
standard = list(
message = c(1:4),
quality = 1:2,
embellish = 1:2,
money_option = 1:6,
fake_numeric = c(3, 6, 10)
),
premium = list(
message = c(1:4),
quality = 2:4,
embellish = 2:4,
money_option = 1:6,
fake_numeric = c(3, 8, 10)
)
)A special class added to the object is needed to determine the class of variables
attr(bain_meta_design, "classes") <-
list(
message = "ordered",
quality = "categorical",
embellish = "categorical",
money_option = "ordered",
fake_numeric = "numeric"
)this will be explained in the algorithm that is going to be used to find the optimal bundle.
Find neighbours
The meta_design object is used to verified what levels
are possible when looking for neighbours and how a level can be
substituted to a new one depending on the class of the attribute. If
this is categorical, than any random possible level can be used. If this
is an ordinal or numeric variable then only the closest level(s) can be
used.
One can create a function that would seek for neighbours thanks to the generator
neighbours_candidate_lock_message <-
tabu_neighbors_generator(
lock_columns = c("message", "top_level"),
meta_design = bain_meta_design,
lock_rows = NULL
)that uses general tabu_neighbors function but sets few
parameters to specific default values.
One can lock_columns, so values within them are not substituted. The
same happens for rows. The meta_design is also needed. For many examples
visit ?tabu_neighbors in the R session.
Below is the example of the execution.
neighbours_candidate_lock_message(ds_bain_candidate)Fitness calculator
The same idea is used in the cjt_fintess_generator that
is used to set default values in the tabu_fitness
function.
fitness_share_concepts <-
tabu_fitness_generator(ds_bain_utilities,
prohibitions = NULL,
price_calculator = bain_price_calculator,
top_level = "top_level",
measure = "share",
concepts = c(1, 3), # should we calculate the share for specific concepts
meta_design = bain_meta_design,
toplevel_related_variables = "money_option",
utils_none_name = "NONE"
)Few more parameters are needed this time. The set of utilities
provided in the first parameter. The names should relate to the ones
used in the meta_design . The variables that are affected
by the top level attributes should be passed by the name, to the
toplevel_related_variables parameter and the top_level
names should be included in the name of the specific variable in the
utilities set. Check out the input of
ds_bain_utilities
head(ds_bain_utilities)We can see that the money_option has a prefixed
top_level attributes in its names. Each categorical and ordinal variable
also has the level name in the name of the column in the utilities set.
The numeric variables only require the parameter to be used to multiple
the value from the candidate.
Another thing is the utils_none_name that you use to let
the share calculator know what is the input from NONE
option to the general market share (provided by the individual level, in
the end calculated for the market). Concepts can be used to calculate
the share only for considered concepts, and the measure can
be set to share or revenue, where for the
revenue the price_calculator function is going to be used
to be multiplied by shares. In this case we will calculate the share
with the following function.
bain_price_calculator <- function(candidate){
candidate %>%
mutate(money_option = as.integer(money_option)) %>%
mutate(
price = case_when(
top_level == 'value' & money_option == 1 ~ 0.7,
top_level == 'value' & money_option == 2 ~ 0.9,
top_level == 'value' & money_option == 3 ~ 1.1,
top_level == 'value' & money_option == 4 ~ 1.25,
top_level == 'value' & money_option == 5 ~ 1.75,
top_level == 'value' & money_option == 6 ~ 1.99,
top_level == 'standard' & money_option == 1 ~ 2.99,
top_level == 'standard' & money_option == 2 ~ 4.1,
top_level == 'standard' & money_option == 3 ~ 4.5,
top_level == 'standard' & money_option == 4 ~ 4.75,
top_level == 'standard' & money_option == 5 ~ 4.99,
top_level == 'standard' & money_option == 6 ~ 5.15,
top_level == 'premium' & money_option == 1 ~ 5.5,
top_level == 'premium' & money_option == 2 ~ 6.99,
top_level == 'premium' & money_option == 3 ~ 7.95,
top_level == 'premium' & money_option == 4 ~ 8.65,
top_level == 'premium' & money_option == 5 ~ 8.99,
top_level == 'premium' & money_option == 6 ~ 9.75
)
) %>%
pull(price)
}If the design of the experiment is very complex and it’s impossible
to specify all complexity with the meta_design object then
one can also pass the probitions parameter which is a list
of all possible bundles to be scored. Sometimes neighbour function could
find too many candidates if the design has too complicated constraints
and here’s where prohibitions can be used to satisfy the condition of
more complex things
Below is the example of the execution.
lapply(neighbours_candidate_lock_message(ds_bain_candidate), fitness_share_concepts)Final application
Having the neighbourhood generator and the price calculator used in the fitness function, we can then execute the tabu_search algorithm. This will handle bundles, where each top level variable has either a different input, the same input, or multiple inputs of the same various possible levels.
ds_bain_candidate_many_multiple_toplevels <-
ds_bain_candidate %>%
bind_rows(
tibble(
top_level = 'value',
message = 4,
quality = 1,
embellish = 1,
money_option= 3,
fake_numeric= 8
)
)
ds_bain_candidate_many_multiple_toplevels
ds_bain_candidate_thesame_toplevel <-
ds_bain_candidate_many_multiple_toplevels %>%
filter(top_level == 'value')
ds_bain_candidate_thesame_toplevel
tabu_search(ds_bain_candidate, fitness_share_concepts, neighbours_candidate_lock_message, max_iterations = 100)
tabu_search(ds_bain_candidate_many_multiple_toplevels, fitness_share_concepts, neighbours_candidate_lock_message, max_iterations = 100)
tabu_search(ds_bain_candidate_thesame_toplevel, fitness_share_concepts, neighbours_candidate_lock_message, max_iterations = 100)