This function generates a heatmap visualizing the combined
importance based on the provided model and cohorts. It uses different
methods depending on the class of the input cohorts object.
Usage
plot_attribute_heatmap(
model,
cohorts = NULL,
text_size = 5,
level_wrap = 20,
attribute_wrap = 15,
mid_point = NULL,
color_low = "#de425b",
color_mid = "#ffcf60",
color_high = "#50bd90",
text_color = "#ffffff"
)Arguments
- model
A fitted conjoint task model object of class
cjt_model- cohorts
A
cohortorcohort_setobject for analyzing specific respondent cohorts, orNULLfor full dataset analysis. Create cohorts usingcreate_cohort()orcreate_cohort_set().- text_size
Text size.
- level_wrap, attribute_wrap
Wrap attribute/level labels to a specified width so it fits in the heatmap.
- mid_point
Mid point on how color scale should be formed.
- color_low
Lower gradient color.
- color_mid
Middle gradient color.
- color_high
Higher gradient color.
- text_color
Tile text color.
Examples
library(dplyr)
library(g6tr.cohorts)
# Create a 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)
)
#> Logit Data
#> ==================================================
#> Attribute Type Levels
#> -----------------------------------
#> Attribute 1 Linear 1
#> Attribute 2 Linear 1
#> Attribute 3 Linear 1
#> Attribute 4 Linear 1
#> Attribute 5 Linear 1
#> Attribute 6 Linear 1
#> Attribute 7 Linear 1
#> Attribute 8 Linear 1
#> Attribute 9 Linear 1
#> Attribute 10 Linear 1
#> Attribute 11 Linear 1
#> Attribute 12 Linear 1
#> Attribute 13 Linear 1
#> Attribute 14 Linear 1
#>
#> 14 parameters to be estimated.
#>
#> 843 total units.
#> Average of 3.5 alternatives in each of 24 sets per unit.
#> 20232 tasks in total.
#>
#> Table of choice data pooled across units:
#> Choice Count Pct.
#> --------------------
#> 1 5224 25.82%
#> 2 6575 32.5%
#> 3 4399 21.74%
#> 4 4034 19.94%
#>
#> MCMC Inference for Hierarchical Logit
#> ==================================================
#> Total Iterations: 200
#> Draws used in estimation: 200
#> Units: 843
#> Parameters per unit: 14
#> Constraints not in effect.
#> Draws are to be 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.361 0.388 0.217 0.37 0.43 0:02
#> 200 0.303 0.507 0.434 1.63 1.17 0:00
#>
#> Total Time Elapsed: 0:04
#>
#> 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
#>
# Plot attribute importance heatmap for the whole population
plot_attribute_heatmap(mod)
#> ℹ No weights provided. Using equal weights of 1.
#> Scale for x is already present.
#> Adding another scale for x, which will replace the existing scale.
#> Scale for fill is already present.
#> Adding another scale for fill, which will replace the existing scale.
# Plot attribute importance heatmap for a specific cohort (Italy)
italy_cohort <-
example_cjt_fp_drn_survey |>
filter(country == "Italy") |>
create_cohort(
id_col = response_id,
weight_col = weight
)
plot_attribute_heatmap(mod, italy_cohort)
#> Scale for x is already present.
#> Adding another scale for x, which will replace the existing scale.
#> Scale for fill is already present.
#> Adding another scale for fill, which will replace the existing scale.
# Plot attribute importance heatmap for multiple cohorts
my_cohort_set <- create_cohort_set(
example_cjt_fp_drn_survey,
id_col = response_id,
grp_cols = c(country, m3_customer),
weight_col = weight
)
plot_attribute_heatmap(mod, my_cohort_set)
#> Scale for x is already present.
#> Adding another scale for x, which will replace the existing scale.
#> Scale for fill is already present.
#> Adding another scale for fill, which will replace the existing scale.
#> Scale for x is already present.
#> Adding another scale for x, which will replace the existing scale.
#> Scale for fill is already present.
#> Adding another scale for fill, which will replace the existing scale.
#> Scale for x is already present.
#> Adding another scale for x, which will replace the existing scale.
#> Scale for fill is already present.
#> Adding another scale for fill, which will replace the existing scale.
#> Scale for x is already present.
#> Adding another scale for x, which will replace the existing scale.
#> Scale for fill is already present.
#> Adding another scale for fill, which will replace the existing scale.
#> Scale for x is already present.
#> Adding another scale for x, which will replace the existing scale.
#> Scale for fill is already present.
#> Adding another scale for fill, which will replace the existing scale.
#> # A tibble: 5 × 5
#> column label level summaries combined_plot
#> <chr> <chr> <chr> <list> <named list>
#> 1 population Overall population population <tibble [2 × 6]> <ggplt2::>
#> 2 country NA Italy <tibble [2 × 6]> <ggplt2::>
#> 3 country NA Spain <tibble [2 × 6]> <ggplt2::>
#> 4 m3_customer NA Customer <tibble [2 × 6]> <ggplt2::>
#> 5 m3_customer NA Non-Customer <tibble [2 × 6]> <ggplt2::>