Introduction
Predicting how likely different groups of respondents are to choose
specific products or services is one of the key goals in choice-based
conjoint analysis. These predictions, known as Shares of
Preferences (SOP), can be calculated using the
predict_for_cohorts() function. Cohort objects for this
workflow come from g6tr.cohorts; g6tr.conjoint
uses them to aggregate predictions across respondent groups. This
vignette demonstrates the basic usage of this function and its various
prediction scenarios.
Prerequisites
Let’s start by loading the necessary packages and fitting a model using our example data:
Prediction scenarios
While the standard predict() method uses
id_col to generate predictions for individual respondents,
shares of preferences are always calculated for groups of respondents.
That’s why predict_for_cohorts() replaces
id_col with a cohorts parameter, where you can
pass either a single cohort created with create_cohort() or
multiple cohorts created with create_cohort_set() after
loading g6tr.cohorts. When cohorts = NULL (the
default), predictions are made for the full population. We’ll use this
default in most examples, but you can learn more about working with
cohorts in the Using g6tr.cohorts
vignette.
Another key difference from standard prediction is that users typically start with a set of concept definitions rather than model data containing task IDs. For example:
concepts <- tibble(
service = c("Apple Music", "Apple One Premier", "Apple One Premier"),
scenario = c("Scenario 1", "Scenario 1", "Scenario 2")
)
concepts
#> # A tibble: 3 × 2
#> service scenario
#> <chr> <chr>
#> 1 Apple Music Scenario 1
#> 2 Apple One Premier Scenario 1
#> 3 Apple One Premier Scenario 2With such a set of concepts, you’d typically want to either compare
them all together in one task or compare each of them against none. The
task_spec parameter is designed to make these common
scenarios easier to handle.
Compare All Concepts Together
By default, predict_for_cohorts() compares all concepts
together in one simulated choice task
(task_spec = compare_all_together()):
pred_all <- predict_for_cohorts(mod, concepts)
#> ℹ No weights provided. Using equal weights of 1.
pred_all
#> # A tibble: 3 × 4
#> task service scenario probability
#> <dbl> <chr> <chr> <dbl>
#> 1 1 Apple Music Scenario 1 0.495
#> 2 1 Apple One Premier Scenario 1 0.255
#> 3 1 Apple One Premier Scenario 2 0.251The output adds a probability column to the original
concepts, showing the predicted share of preferences for each concept
when all are presented together.
To include a “none” option in the comparison:
pred_all_none <- predict_for_cohorts(
mod,
concepts,
task_spec = compare_all_together(allow_none = TRUE)
)
#> ℹ No weights provided. Using equal weights of 1.
pred_all_none
#> # A tibble: 3 × 4
#> task service scenario probability
#> <dbl> <chr> <chr> <dbl>
#> 1 1 Apple Music Scenario 1 0.264
#> 2 1 Apple One Premier Scenario 1 0.168
#> 3 1 Apple One Premier Scenario 2 0.166Notice that the probabilities are lower than before, as some share of preferences is now allocated to the “none” option.
Compare Each Concept Against “None”
To evaluate each concept individually against a “none” option:
pred_each_vs_none <- predict_for_cohorts(
mod,
concepts,
task_spec = compare_each_vs_none()
)
#> ℹ No weights provided. Using equal weights of 1.
pred_each_vs_none
#> # A tibble: 3 × 4
#> task service scenario probability
#> <int> <chr> <chr> <dbl>
#> 1 1 Apple Music Scenario 1 0.506
#> 2 2 Apple One Premier Scenario 1 0.429
#> 3 3 Apple One Premier Scenario 2 0.429This shows how each concept performs when it’s the only option available besides “none.”
Using Custom Task Definitions
Finally, for more complex scenarios, you can define your own tasks by adding a task column to your concepts:
# First two concepts in task 1, third in task 2
concepts_tasks <- concepts |>
mutate(task_id = c(1, 1, 2))
concepts_tasks
#> # A tibble: 3 × 3
#> service scenario task_id
#> <chr> <chr> <dbl>
#> 1 Apple Music Scenario 1 1
#> 2 Apple One Premier Scenario 1 1
#> 3 Apple One Premier Scenario 2 2
pred_by_task <- predict_for_cohorts(
mod,
concepts_tasks,
task_spec = use_task_column(task_id, allow_none = TRUE)
)
#> ℹ No weights provided. Using equal weights of 1.
pred_by_task
#> # A tibble: 3 × 4
#> task service scenario probability
#> <dbl> <chr> <chr> <dbl>
#> 1 1 Apple Music Scenario 1 0.329
#> 2 1 Apple One Premier Scenario 1 0.237
#> 3 2 Apple One Premier Scenario 2 0.429This approach gives you full control over which concepts are compared
together, similar to how the standard predict() function
works.
Identifying Top Concepts
When working with conjoint analysis, we often want to find the
best-performing concepts. Here’s how you can do this using the
predict_for_cohorts() function.
Start by generating all possible concepts from the model’s attributes:
all_concepts <- generate_concepts(mod)Evaluate each concept individually against a “none” option to assess its standalone appeal:
pred_each_vs_none <- predict_for_cohorts(
mod,
all_concepts,
task_spec = compare_each_vs_none()
)
#> ℹ No weights provided. Using equal weights of 1.To identify the top five concepts based on their predicted share of preferences:
slice_max(pred_each_vs_none, probability, n = 5)
#> # A tibble: 5 × 4
#> task service scenario probability
#> <int> <chr> <chr> <dbl>
#> 1 49 Standard Accessory Package Scenario 1 0.512
#> 2 50 Standard Accessory Package Scenario 2 0.509
#> 3 31 iCloud+ 2TB Scenario 1 0.508
#> 4 1 Apple Music Scenario 1 0.506
#> 5 19 AppleCare+ and iCloud+ 200GB Scenario 1 0.506To analyze preferences by country, create a cohort set grouped by country to evaluate top concepts within each market:
library(tidyr)
cohort_set_countries <-
example_cjt_fp_drn_survey |>
create_cohort_set(
id_col = response_id,
weight_col = weight,
grp_cols = country
)
pred_each_vs_none_by_country <-
predict_for_cohorts(
mod,
all_concepts,
task_spec = compare_each_vs_none(),
cohorts = cohort_set_countries
)
top_concepts_by_country <-
pred_each_vs_none_by_country |>
rowwise() |>
mutate(
top_5 = list(
predictions |>
slice_max(probability, n = 5) |>
mutate(ind = row_number())
)
) |>
select(level, top_5) |>
unnest(top_5)
top_concepts_by_country
#> # A tibble: 15 × 6
#> level task service scenario probability ind
#> <chr> <int> <chr> <chr> <dbl> <int>
#> 1 population 49 Standard Accessory Package Scenario 1 0.511 1
#> 2 population 50 Standard Accessory Package Scenario 2 0.508 2
#> 3 population 31 iCloud+ 2TB Scenario 1 0.507 3
#> 4 population 1 Apple Music Scenario 1 0.505 4
#> 5 population 19 AppleCare+ and iCloud+ 200GB Scenario 1 0.504 5
#> 6 Italy 50 Standard Accessory Package Scenario 2 0.506 1
#> 7 Italy 49 Standard Accessory Package Scenario 1 0.506 2
#> 8 Italy 19 AppleCare+ and iCloud+ 200GB Scenario 1 0.503 3
#> 9 Italy 2 Apple Music Scenario 2 0.503 4
#> 10 Italy 20 AppleCare+ and iCloud+ 200GB Scenario 2 0.502 5
#> 11 Spain 49 Standard Accessory Package Scenario 1 0.515 1
#> 12 Spain 31 iCloud+ 2TB Scenario 1 0.512 2
#> 13 Spain 50 Standard Accessory Package Scenario 2 0.510 3
#> 14 Spain 32 iCloud+ 2TB Scenario 2 0.508 4
#> 15 Spain 1 Apple Music Scenario 1 0.507 5