Title
Go to content
 

How to use the R conjoint package for conjoint analysis

 
by Craig Kolb, 23 April 2025

Metrisim's market simulator is compatible with the R conjoint package. This article explains how you can use R conjoint with Metrisim.

Metric conjoint analysis with the R conjoint analysis package involves a design stage (where you use R to create an experimental design that can in turn be used to create product profiles for your survey) and an analysis / parameter estimation phase where you estimate the partworths for two purposes: 1.) Determine what attributes are important and which levels have the biggest impact. 2.) Provide the partworths needed to build a market simulator.

This tutorial assumes you’ve installed the open source R statistical software from the CRAN website and that you’ve also installed the conjoint package. Either open the console or use an IDE like ‘R commander’ and set the working directory to the folder you want to save your files to.
You can adapt the example code below to generate a fractional factorial design; after the point where it says expand.grid. For instance, Brand is the attribute name and Kinder Green is one of the levels. Change the attribute names and levels to your own, and add or delete attributes as needed. Note: anything after a ‘#’ symbol in R, is a comment that is not part of the code.

Example R code to generate an experimental design suitable for metric conjoint analysis
library(conjoint)
experiment<-expand.grid(
        Brand<-c("Kinder Green","Clover","Dewfresh","First Choice","Parmalat"),
        Price<-c("9.99","13.99","17.99","21.99"),
        Type<-c("Cow Milk","Cow-Free Milk (from cells)","Cow-Free Milk (from       flora)"),
        Cap<-c("Plastic","Bioplastic"),
        Pack<-c("Recyclable","Not recyclable"))
design<-caFactorialDesign(data=experiment, type="fractional")
print(design)
str(design)   #check number of runs included
print(cor(caEncodedDesign(design)))   #examine attribute correlations (as low as possible)
edesign<-caEncodedDesign(design)

 
# Write CSV in R
write.csv(design, file = "design.csv")
write.csv(edesign, file = "edesign.csv")

 
The above code saves design.csv file into your working folder. It provides a human readable version of the edesign.csv. Keep copies of both as you will need them after your survey.

Usually, you would want to make a copy of the design.csv and use that to generate more presentable product profiles that you can save as individual images to use in your survey tool. Note that in the language of experimental design, the row/run of the experimental design is the same thing as a product profile in conjoint analysis.

 
Example of a survey ready product profile image created from a single run in the design.csv file

Estimating partworths

Once your survey is complete you need to estimate partworths from the ratings. You need to prepare your ratings file as in the screenshot below.

Example of how the ratings file should be formatted


 

R conjoint package also requires the edesign.csv you created prior to your survey as well as a ‘levels.csv’ file as shown in the screenshot below.
Example of how the levels should be formatted
  
 

 
You can use the code example below as a starting point.
R conjoint analysis code
library(conjoint)
# 1) IMPORT EDESIGN with headings added manually in file (DELETE the card number column before import)
edesign2<-read.table("edesign.csv", header=TRUE, sep=",")
# 2) IMPORT LEVELS Create vector of level labels (write "Levels" on first row as header)
levels<-read.table("levels.csv", header=TRUE, sep=",")
# 3) IMPORT RATINGS  
ratings<- read.table("ratings.csv", header=TRUE, sep=",", row.names="id")
# 4) GENERATE PARTWORTHS
caPartUtilities (ratings,edesign2,levels)   #individual level partworths
indiv<-caPartUtilities (ratings,edesign2,levels)
write.csv(indiv, file = "pws.csv")

Output and simulator

The above script will generate various statistics as output, such as the coefficients and will also output partworth charts. The screenshot below, shows partworths per UHT milk brand output by the R conjoint package. As can be seen Parmalat leads, while profiles branded as Kinder Green have the lowest purchase probability.


 


The above script will also save the partworths estimated per respondent to a csv file called pws.csv; see the example screenshot below.

Example of how the partworths saved by the script should look

Why Metrisim is a useful supplement to the R conjoint package

While R conjoint is a very useful open-source tool, it is limited in terms of the simulator, which provides no way to incorporate external effects, calibration or respondent / volume weighting. It is also not very user-friendly for non-technical users and is fairly cumbersome to use. The output is also not too attractive, and must be manually positioned in PowerPoint. The cluster analysis is also not presented in a way that is useful in practice.

Metrisim provides a solution to all of this, while being compatible with the R conjoint package’s output files. Metrisim uses the partworths to automatically construct a market simulator that provides better accuracy and enhances analyst productivity.  Metrisim also offers a complete suite - including design and estimation - which offers an alternative path to using open source tools such as R conjoint, for those seeking more convenience.

Note: if you are going to use the pws.csv to build a conjoint analysis market simulator in Metrisim and you want to keep an id column in your pws.csv, check that column header (first row in the first column) is ‘id’.


Copyright Reserved, Metrisim, 2025
Back to content