Finds the best package bundle for a conjoint model with a None option. The bundle is chosen based on maximizing the market share, starting with an initial candidate and model parth-worth utilities.
Arguments
- model
The full model object returned by
g6tr.cjt::cjt_model()with Part-Worth utilities data frame stored in thepwu_gridelement.- initial_condition
Used as an initial baseline for the neighbourhood detection.
- max_iterations
The number of iterations before to stop if the neighbourhood candidates are not better than initial condition.
- max_tabu_size
The maximum size of the considered candidates in the neighbourhood.
Details
A wrapper around tabu_search() that reshapes utilities for you and
prepares the neighbourhood function and the fitness function (responsible
for the market share calculations).
Examples
library(dplyr)
library(tidyr)
library(g6tr.cjt)
cbc_fp <- cjt_read_toy_data("CBC-FP", none = "SRN")
#>
Rows: 250 Columns: 25
#> Building packages ■■■■■■■■■■■■■■■■■■■■■■■■■ 79% | ETA: 2m
#>
#> Building packages ■■■■■■■■■■■■■■■■■■■■■■■■■ 79% | ETA: 2m
── Column specification ─────────────────────────────────────────────────────────────────────────────────────────────────────
#> Building packages ■■■■■■■■■■■■■■■■■■■■■■■■■ 79% | ETA: 2m
Delimiter: ","
#> chr (13): response_id, des_1, des_2, des_3, des_4, des_5, des_6, des_7, des_...
#> dbl (12): a1_m1_cjt, a2_m1_cjt, a3_m1_cjt, a4_m1_cjt, a5_m1_cjt, a6_m1_cjt, ...
#>
#> Building packages ■■■■■■■■■■■■■■■■■■■■■■■■■ 79% | ETA: 2m
#>
#>
#> Building packages ■■■■■■■■■■■■■■■■■■■■■■■■■ 79% | ETA: 2m
ℹ Use `spec()` to retrieve the full column specification for this data.
#> Building packages ■■■■■■■■■■■■■■■■■■■■■■■■■ 79% | ETA: 2m
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#> Building packages ■■■■■■■■■■■■■■■■■■■■■■■■■ 79% | ETA: 2m
cbc_fp_asserted <-
cjt_assert_data(cbc_fp, id = "response_id", n_choices = 2, none_value = 3, n_tasks = 12)
#>
#>
#> Building packages ■■■■■■■■■■■■■■■■■■■■■■■■■ 79% | ETA: 2m
#>
#> ── Asserting Identifiers ────────────────────────────────────────────────────────────────────────────────────────────────────
#> Building packages ■■■■■■■■■■■■■■■■■■■■■■■■■ 79% | ETA: 2m
#>
#> ✔ All Identifiers are unique and do not contain missing values. Moving on...
#> Building packages ■■■■■■■■■■■■■■■■■■■■■■■■■ 79% | ETA: 2m
#>
#>
#> Building packages ■■■■■■■■■■■■■■■■■■■■■■■■■ 79% | ETA: 2m
#>
#> ── Asserting the answers ────────────────────────────────────────────────────────────────────────────────────────────────────
#> Building packages ■■■■■■■■■■■■■■■■■■■■■■■■■ 79% | ETA: 2m
#>
#> ✔ No empty responses. Moving on...
#> Building packages ■■■■■■■■■■■■■■■■■■■■■■■■■ 79% | ETA: 2m
#>
#> ✔ Choice options are all valid. Moving on...
#> Building packages ■■■■■■■■■■■■■■■■■■■■■■■■■ 79% | ETA: 2m
#>
#>
#> Building packages ■■■■■■■■■■■■■■■■■■■■■■■■■ 79% | ETA: 2m
#>
#> ── Asserting the design ─────────────────────────────────────────────────────────────────────────────────────────────────────
#> Building packages ■■■■■■■■■■■■■■■■■■■■■■■■■ 79% | ETA: 2m
#>
#> ✖ 3 respondents have empty design elements - dropping them
#> Building packages ■■■■■■■■■■■■■■■■■■■■■■■■■ 79% | ETA: 2m
cbc_fp_tidy <- cjt_tidy_data(cbc_fp_asserted)
#>
#>
#> Building packages ■■■■■■■■■■■■■■■■■■■■■■■■■ 79% | ETA: 2m
#>
#> ── Tidying & appending answers ──────────────────────────────────────────────────────────────────────────────────────────────
#> Building packages ■■■■■■■■■■■■■■■■■■■■■■■■■ 79% | ETA: 2m
#>
#>
#> Building packages ■■■■■■■■■■■■■■■■■■■■■■■■■ 79% | ETA: 2m
#>
#> ── Parsing design ───────────────────────────────────────────────────────────────────────────────────────────────────────────
#> Building packages ■■■■■■■■■■■■■■■■■■■■■■■■■ 79% | ETA: 2m
#>
#> ✔ Data formatting complete. You can proceed with modeling.
#> Building packages ■■■■■■■■■■■■■■■■■■■■■■■■■ 79% | ETA: 2m
cbc_fp_model <- cjt_model(cbc_fp_tidy, mcmc = list(R = 500, use = 500))
#>
#>
#> Building packages ■■■■■■■■■■■■■■■■■■■■■■■■■ 79% | ETA: 2m
#>
#> ── Running choicemodelr. ────────────────────────────────────────────────────────────────────────────────────────────────────
#> Building packages ■■■■■■■■■■■■■■■■■■■■■■■■■ 79% | ETA: 2m
#>
#>
#> Building packages ■■■■■■■■■■■■■■■■■■■■■■■■■ 79% | ETA: 2m
#>
#> ── Using default xcoding. ──
#> Building packages ■■■■■■■■■■■■■■■■■■■■■■■■■ 79% | ETA: 2m
#>
#>
#> Building packages ■■■■■■■■■■■■■■■■■■■■■■■■■ 79% | ETA: 2m
#>
#> ── Using manual mcmc sampling: R = "500" & use = "500" ──
#> Building packages ■■■■■■■■■■■■■■■■■■■■■■■■■ 79% | ETA: 2m
#>
#>
#> Building packages ■■■■■■■■■■■■■■■■■■■■■■■■■ 79% | ETA: 2m
#>
#> ── Using default options. ──
#> Building packages ■■■■■■■■■■■■■■■■■■■■■■■■■ 79% | ETA: 2m
#>
#>
#> Building packages ■■■■■■■■■■■■■■■■■■■■■■■■■ 79% | ETA: 2m
#>
ℹ Applying model for full data.
#> Logit Data
#> ==================================================
#> Attribute Type Levels
#> -----------------------------------
#> Attribute 1 Part Worth 4
#> Attribute 2 Part Worth 10
#> Attribute 3 Part Worth 6
#> Attribute 4 Part Worth 11
#> Attribute 5 Part Worth 6
#>
#> 33 parameters to be estimated (including 'None').
#>
#> 247 total units.
#> Average of 3 alternatives in each of 12 sets per unit.
#> 2964 tasks in total.
#>
#> Table of choice data pooled across units:
#> Choice Count Pct.
#> --------------------
#> 1 845 28.51%
#> 2 860 29.01%
#> 3 1259 42.48%
#>
#> MCMC Inference for Hierarchical Logit
#> ==================================================
#> Total Iterations: 500
#> Draws used in estimation: 500
#> Units: 247
#> Parameters per unit: 33
#> Constraints not in effect.
#> Draws not saved.
#> Prior degrees of freedom: 5
#> Prior variance: 2
#>
#> MCMC Iteration Beginning...
#> Iteration Acceptance RLH Pct. Cert. Avg. Var. RMS Time to End
#> 100 0.337 0.435 0.221 0.50 0.39 0:01
#> 200 0.301 0.536 0.415 0.98 0.79 0:01
#> 300 0.313 0.596 0.520 1.48 1.09 0:01
#> 400 0.307 0.630 0.575 1.93 1.30 0:00
#> 500 0.306 0.646 0.601 2.29 1.46 0:00
#>
#> Total Time Elapsed: 0:01
#>
#> Writing estimated unit-level betas to Rbetas.csv in the working directory
#>
#> Writing RLH, the geometric mean of the likelihood of the choices made,
#>
#> across the choice sets of each unit to RLH.csv in the working directory
#>
#>
✔ Modeling full data was successful. Ready to start extracting stats. [3.2s]
#>
#> Building packages ■■■■■■■■■■■■■■■■■■■■■■■■■ 79% | ETA: 2m
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_optim(
cbc_fp_model,
cjt_candidate_1,
max_iterations = 100,
max_tabu_size = 100
)
#> Finding best bundle...
#> ==================================================
#>
#> Iteration Fitness
#> Warning: `all_equal()` was deprecated in dplyr 1.1.0.
#> ℹ Please use `all.equal()` instead.
#> ℹ And manually order the rows/cols as needed
#> ℹ The deprecated feature was likely used in the g6tr.tabu package.
#> Please report the issue to the authors.
#> 0 0.515
#> 1 0.532
#> 2 0.552
#> 3 0.56
#> 4 0.56
#> 5 0.562
#> 6 0.562
#>
#> Best bundle found. Returning optimal bundle.
#>
#> # A tibble: 1 × 6
#> bailouts benefits medical open publichealth main
#> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 bail_out_b_state_governments_b provide_econo… requir… phas… require_fac… main