Skip to contents

g6tr.conjoint provides tools for choice-based conjoint analysis, focusing on: - Fitting hierarchical Bayes choice models - Predicting shares of preferences - Analyzing preferences by cohort - Generating level summaries

Installation

install.packages("g6tr.conjoint")

Example

Load packages and example data:

library(g6tr.conjoint)
library(g6tr.cohorts)
library(dplyr)
library(tidyr)
data("example_cjt_fp_drn_survey")
data("example_cjt_fp_drn_flat_data")

Fit a choice model:

mod <- cjt_model(
  nn_choice + allows_none(drn_sub_buy_choice) ~ service + scenario,
  data = example_cjt_fp_drn_flat_data,
  id_col = id,
  task_col = task,
  mcmc = list(R = 200, use = 200)
)
mod
#> Conjoint Task Model
#> • Number of Respondents: 843
#> • ID Column: "id"
#> • Task Column: "task"
#> • Formula: "nn_choice + drn_sub_buy_choice ~ service + scenario + 0"
#> • Allows None: `TRUE`

Generate all possible concepts and predict their shares of preferences:

all_concepts <- generate_concepts(mod)

pred_each_vs_none <- predict_for_cohorts(
  mod, 
  all_concepts, 
  task_spec = compare_each_vs_none()
)
#> ℹ No weights provided. Using equal weights of 1.

# View top concepts
slice_max(pred_each_vs_none, probability, n = 3)
#> # A tibble: 3 × 4
#>    task service                      scenario   probability
#>   <int> <chr>                        <chr>            <dbl>
#> 1    49 Standard Accessory Package   Scenario 1       0.517
#> 2    31 iCloud+ 2TB                  Scenario 1       0.517
#> 3    19 AppleCare+ and iCloud+ 200GB Scenario 1       0.515

Analyze preferences by country:

Cohort objects are created in g6tr.cohorts and then passed into predict_for_cohorts():

cohort_set_countries <- 
  example_cjt_fp_drn_survey |>
  create_cohort_set(
    id_col = response_id,
    weight_col = weight,
    grp_cols = country
  )

pred_by_country <- predict_for_cohorts(
  mod, 
  all_concepts, 
  task_spec = compare_each_vs_none(),
  cohorts = cohort_set_countries
)

# View top concepts by country
pred_by_country |>
  rowwise() |>
  mutate(
    top_5 = list(
      predictions |>
        slice_max(probability, n = 3) |>
        mutate(ind = row_number())
    )
  ) |>
  select(level, top_5) |>
  unnest(top_5)
#> # A tibble: 9 × 6
#>   level       task service                      scenario   probability   ind
#>   <chr>      <int> <chr>                        <chr>            <dbl> <int>
#> 1 population    31 iCloud+ 2TB                  Scenario 1       0.516     1
#> 2 population    49 Standard Accessory Package   Scenario 1       0.516     2
#> 3 population    19 AppleCare+ and iCloud+ 200GB Scenario 1       0.513     3
#> 4 Italy         31 iCloud+ 2TB                  Scenario 1       0.512     1
#> 5 Italy         19 AppleCare+ and iCloud+ 200GB Scenario 1       0.512     2
#> 6 Italy         49 Standard Accessory Package   Scenario 1       0.511     3
#> 7 Spain         49 Standard Accessory Package   Scenario 1       0.520     1
#> 8 Spain         31 iCloud+ 2TB                  Scenario 1       0.519     2
#> 9 Spain         50 Standard Accessory Package   Scenario 2       0.515     3