39  Conjoint design and analysis using R

Published

August 8, 2024

This post is to illustrate how to use R to do basic conjoint analysis.

39.1 Conjoint Analysis

Marketing people used to use Sawtooth to do conjoint analysis.

What is conjoint analysis? Here is the intro from Sawtooth:

“Conjoint analysis methods use statistical analysis to compute mathematical representations of survey respondents’ preferences for product features, simulate how attribute changes affect demand, and even predict market acceptance of new products before they launch.

This powerful research methodology has become very popular with market researchers and economists for the valuable insight that few other research methods can provide.”

“Consider the task of purchasing a new vehicle.

When searching for the “right” vehicle, you typically consider a multitude of variables: type, make (brand), model, year, mileage, price, color, accessories packages, etc. You can see how this is a complex choice to make.

How does anyone possibly make such a complicated decision?

You think about what features matter most to you and then make tradeoffs.

For example, one vehicle could be an acceptable make and model, but at a high price point, whereas a second option is not the ideal make and model but has a more palatable price.

The tradeoff in this simple example is whether the make and model is more preferable to a reasonable price, or vice versa.

A conjoint survey captures the relationship between different attributes of a product and how preferable they are both comparatively and when combined.

Because of this, conjoint analysis is the gold standard solution for testing multiple features simultaneously, when limited A/B testing doesn’t go far enough.”

“In simple terms, the conjoint survey design algorithm generates a balanced survey design with product profiles, also known as concepts, formulated to have ideal statistical properties (such as level balance and independence of attributes).

Each profile is made up of multiple conjoined product features (hence, conjoint analysis), such as brand, type, engine, and color, each with systematically varied levels.

These product concepts are then included in a series of questions, usually 8-20, called choice tasks, that make up the conjoint analysis portion of the survey.”

39.2 Example

The example uses the tea data that ships with the conjoint package (Bąk and Bartłomowicz 2012). A hundred respondents rate 13 tea profiles on a scale from 0 to 10. Each profile combines four attributes: price (low, medium, high), variety (black, green, red), kind (bags, granulated, leafy) and aroma (yes, no).

Code
library(tidyverse)
library(conjoint)

data(tea)   # tprof: the 13 profiles; tprefm: 100 x 13 ratings; tlevn: level names

levels_list <- list(price   = c("low", "medium", "high"),
                    variety = c("black", "green", "red"),
                    kind    = c("bags", "granulated", "leafy"),
                    aroma   = c("yes", "no"))

profiles <- tprof
profiles[] <- Map(function(x, l) factor(l[x], levels = l), tprof, levels_list)

tea_long <- tibble(respondent = rep(1:100, each = 13),
                   profile    = rep(1:13, times = 100),
                   rating     = as.vector(t(tprefm))) |>
  bind_cols(profiles[rep(1:13, times = 100), ])

tea_long
# A tibble: 1,300 × 7
   respondent profile rating price  variety kind       aroma
 *      <int>   <int>  <int> <fct>  <fct>   <fct>      <fct>
 1          1       1      8 high   black   bags       yes  
 2          1       2      1 low    green   bags       yes  
 3          1       3      1 medium green   granulated yes  
 4          1       4      3 medium black   leafy      yes  
 5          1       5      9 high   red     leafy      yes  
 6          1       6      2 medium black   bags       no   
 7          1       7      7 high   green   bags       no   
 8          1       8      2 medium red     bags       no   
 9          1       9      2 high   black   granulated no   
10          1      10      2 low    red     granulated no   
# ℹ 1,290 more rows

The data are 1,300 rows, 100 respondents times 13 profiles.

39.3 Conjoint design of experiment

With three, three, three and two levels, the full factorial has \(3 \times 3 \times 3 \times 2 = 54\) profiles. Asking every respondent to rate 54 teas is too much, so a conjoint study shows a fraction of them. The question is which fraction. A good design lets us estimate the effect of every attribute level, with little correlation between the attributes.

AlgDesign searches for such designs. optFederov() picks the subset of the full factorial that maximizes the determinant of the information matrix for a main-effects model, the D-optimality criterion. A main-effects model here has 8 parameters, an intercept plus \(2 + 2 + 2 + 1\) level contrasts, so a design needs at least 8 profiles. We search for designs of several sizes and report their D-efficiency (Kuhfeld, Tobias, and Garratt 1994) and whether every level appears equally often.

Code
library(AlgDesign)

full <- expand.grid(lapply(levels_list, factor))

set.seed(123)
designs <- map(c(9, 12, 13, 18, 27, 54),
               \(n) optFederov(~ ., data = full, nTrials = n, criterion = "D"))

tibble(trials       = c(9, 12, 13, 18, 27, 54),
       D_efficiency = map_dbl(designs, "Dea"),
       balanced     = map_lgl(designs, \(d) all(map_lgl(d$design,
                                     \(f) length(unique(table(f))) == 1))))
# A tibble: 6 × 3
  trials D_efficiency balanced
   <dbl>        <dbl> <lgl>   
1      9        0.146 FALSE   
2     12        0.779 TRUE    
3     13        0.67  FALSE   
4     18        1     TRUE    
5     27        0.969 FALSE   
6     54        1     TRUE    

D-efficiency measures how much information a design carries per profile, relative to an ideal orthogonal design. A design with efficiency 0.8 needs about 25% more observations to give the same standard errors as one with efficiency 1. Balance requires a number of profiles divisible by 3 and by 2. Among these sizes, only 12, 18 and 54 are balanced. The 18-profile design reaches an efficiency of 1: it is an orthogonal main-effects design, a third of the full factorial with nothing lost for a main-effects model.

The tea study used 13 profiles. That number cannot be balanced, and the design shows it.

Code
map(profiles, table)
$price

   low medium   high 
     3      5      5 

$variety

black green   red 
    5     5     3 

$kind

      bags granulated      leafy 
         5          3          5 

$aroma

yes  no 
  5   8 
Code
X <- model.matrix(~ price + variety + kind + aroma, profiles)[, -1]
round(cor(X), 2)
               pricemedium pricehigh varietygreen varietyred kindgranulated
pricemedium           1.00     -0.62         0.02      -0.06          -0.06
pricehigh            -0.62      1.00         0.02      -0.06          -0.06
varietygreen          0.02      0.02         1.00      -0.43          -0.06
varietyred           -0.06     -0.06        -0.43       1.00           0.13
kindgranulated       -0.06     -0.06        -0.06       0.13           1.00
kindleafy             0.02      0.02         0.02      -0.06          -0.43
aromano              -0.02     -0.02        -0.02       0.06           0.06
               kindleafy aromano
pricemedium         0.02   -0.02
pricehigh           0.02   -0.02
varietygreen        0.02   -0.02
varietyred         -0.06    0.06
kindgranulated     -0.43    0.06
kindleafy           1.00   -0.02
aromano            -0.02    1.00

Low price and red variety appear 3 times, while other levels appear 5 times, and aroma is “no” in 8 of the 13 profiles. The correlations between dummies of the same attribute, such as \(-0.62\) for medium and high price, come from the coding and are expected. What matters is the correlation between attributes, and it stays small: the largest is 0.13, between red variety and granulated kind. The attributes are close to independent, so each attribute’s effect can be estimated without much contamination from the others.

39.4 Conjoint analysis

The part-worths are the coefficients of a regression of the rating on attribute dummies. Each respondent rates 13 profiles, so the ratings are clustered by respondent, and the standard errors have to allow for that.

Code
library(sandwich)
library(lmtest)

partworths_lm <- lm(rating ~ price + variety + kind + aroma, data = tea_long)
coeftest(partworths_lm, vcov = vcovCL(partworths_lm, cluster = ~ respondent))

t test of coefficients:

               Estimate Std. Error t value  Pr(>|t|)    
(Intercept)     4.95614    0.25090 19.7538 < 2.2e-16 ***
pricemedium    -0.38334    0.18135 -2.1139  0.034717 *  
pricehigh      -0.33734    0.23621 -1.4282  0.153483    
varietygreen   -0.58000    0.25521 -2.2727  0.023210 *  
varietyred     -1.26466    0.25189 -5.0206 5.870e-07 ***
kindgranulated -1.02666    0.10561 -9.7216 < 2.2e-16 ***
kindleafy       0.61600    0.22559  2.7306  0.006407 ** 
aromano        -0.82155    0.17027 -4.8250 1.567e-06 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

The baseline profile is low-priced black tea in bags with aroma. Relative to it, red tea lowers the rating by 1.26 points and green tea by 0.58. Granulated tea lowers it by 1.03, while leafy tea raises it by 0.62. Tea without aroma is rated 0.82 lower. Price matters least: medium and high prices lower the rating by about 0.35, and only the medium-price contrast is significant at 5%.

Conjoint software usually reports part-worths in effect coding, where the part-worths of each attribute sum to zero. They are the same coefficients, re-centred within each attribute. The importance of an attribute is the range of its part-worths as a share of the sum of the ranges.

Code
part_worths <- imap_dfr(levels_list, \(lv, attr) {
  b <- c(0, coef(partworths_lm)[paste0(attr, lv[-1])])
  tibble(attribute = attr, level = factor(lv, levels = lv), part_worth = b - mean(b))
})

importance <- part_worths |>
  group_by(attribute) |>
  summarise(range = diff(range(part_worth))) |>
  mutate(importance = round(100 * range / sum(range), 1))
importance
# A tibble: 4 × 3
  attribute range importance
  <chr>     <dbl>      <dbl>
1 aroma     0.822       20  
2 kind      1.64        39.9
3 price     0.383        9.3
4 variety   1.26        30.8
Code
ggplot(part_worths, aes(level, part_worth)) +
  geom_col(fill = "darkcyan") +
  geom_hline(yintercept = 0) +
  facet_wrap(~ attribute, scales = "free_x", nrow = 1) +
  labs(x = NULL, y = "Part-worth") +
  theme_bw()

Kind is the most important attribute, with 39.9% of the total range, followed by variety with 30.8%, aroma with 20.0% and price with 9.3%.

The conjoint package computes the same quantities. Its pooled part-worths match ours exactly. Its importance figures do not, and the reason is worth knowing. caImportance() computes each respondent’s importance from that respondent’s own part-worths, and then averages across respondents. Individual part-worths from 13 ratings are noisy, and noise widens every attribute’s range, so the averaged importance spreads more evenly across attributes than the pooled figure.

Code
# conjoint's functions switch R to sum-to-zero contrasts globally and do not
# switch back, which would break every later regression; save and restore.
op <- options("contrasts")
invisible(capture.output(pooled <- caUtilities(y = tprefm, x = tprof, z = tlevn)))
invisible(capture.output(imp <- caImportance(y = tprefm, x = tprof)))
options(op)

round(pooled, 3)                      # intercept, then effect-coded part-worths
 [1]  3.553  0.240 -0.143 -0.097  0.615  0.035 -0.650  0.137 -0.890  0.753
[11]  0.411 -0.411
Code
setNames(imp, names(levels_list))     # averaged over respondents
  price variety    kind   aroma 
  24.76   32.22   27.15   15.88 

The averaged importances are 24.8 for price, 32.2 for variety, 27.2 for kind and 15.9 for aroma. Price moves from least important to second. The two figures answer different questions. The pooled range describes the average respondent. The averaged importance describes how much each attribute matters within a respondent, and it is inflated by sampling noise in the individual fits.

39.5 Causal effect in conjoint analysis

Hainmueller, Hopkins, and Yamamoto (2014) define the average marginal component effect (AMCE): the average change in the outcome when one attribute moves from one level to another, averaged over the distribution of the other attributes. It is not to be confused with the ACME, the average causal mediation effect of Imai, Keele, and Tingley (2010). When the attribute levels are randomized independently of each other and of the respondents, the AMCE is identified, and it is estimated by the coefficients of a regression of the outcome on the attribute dummies. Standard errors are clustered by respondent. The cjoint package implements it.

Code
library(cjoint)

amce_fit <- amce(rating ~ price + variety + kind + aroma, data = as.data.frame(tea_long),
                 cluster = TRUE, respondent.id = "respondent")

imap_dfr(amce_fit$estimates, \(m, attr)
  tibble(attribute = attr, level = colnames(m),
         amce = round(m["AMCE", ], 3), se = round(m["Std. Error", ], 3)))
# A tibble: 7 × 4
  attribute level            amce    se
  <chr>     <chr>           <dbl> <dbl>
1 aroma     aromano        -0.822 0.17 
2 kind      kindgranulated -1.03  0.106
3 kind      kindleafy       0.616 0.226
4 price     pricemedium    -0.383 0.181
5 price     pricehigh      -0.337 0.236
6 variety   varietygreen   -0.58  0.255
7 variety   varietyred     -1.26  0.252

The AMCEs are exactly the part-worth coefficients above, with the same clustered standard errors. The tea profiles were not randomized; they are a fixed 13-profile design. The attributes in it are close to independent, which is why the regression coefficients still read as average effects of each attribute. The causal reading also needs the ratings to reflect the attributes shown and nothing else about the profile, and it holds only for the population of profiles the design represents.

39.6 Summary

A conjoint study asks respondents to rate or choose among product profiles whose attributes vary by design. The full factorial is usually too long, so we use a fraction chosen for D-efficiency and balance. For the tea attributes, an 18-profile design is fully efficient and balanced. The study’s own 13 profiles cannot be balanced, but the correlations between attributes stay below 0.13.

The analysis is a regression of the ratings on attribute dummies, with standard errors clustered by respondent. The coefficients are the part-worths. Kind and variety matter most, and price least. Importance from the pooled part-worths differs from conjoint’s average of individual importances, because individual fits are noisy. When attribute levels are independent, the same coefficients are Hainmueller et al.’s average marginal component effects, which cjoint reproduces.