This article describes how to transform MaxDiff preference share variables to use as the Alternatives input in TURF analysis.
Requirements
- A Displayr document with preference share variables either created from a MaxDiff analysis output in Displayr or included in the underlying data set.
Method
MaxDiff data can also be used in TURF, but it must first be converted into binary format.
There are several ways of doing this. With rankings, we assign a value of 1 to the highest-ranked alternatives. This can be the highest, the highest two, the highest three, or more alternatives. It’s an arbitrary decision.
Alternatively, we can use a threshold-based selection. Some threshold is specified (e.g., preference share is above the respondent’s average), and alternatives with a share above this value are assigned a value of 1 and others a value of 0.
The example below assigns the value of one to the highest-ranked alternatives for each respondent. The goal is to work out which of the alternatives has the highest preference share for each respondent. Then, we'll replace the highest value with 1 and all others with 0. We can do this with some R code.
When you have a MaxDiff analysis output in Displayr
This method assumes you have already run a MaxDiff analysis from the Report tree + or the toolbar via > Advanced Analysis > MaxDiff > Hierarchical Bayes / Latent Class Analysis / Multinomial Logit.
- Select the MaxDiff output you want to use in the TURF analysis.
- In the object inspector
, click Data > Save Variable(s) > Preference Shares. This saves out the preference share data we'll need.
- Find the preference share variable set in the Data Sources tree.
- Click the small arrow next to the variable set to expand it:
- Select the first variable in the list. In my screenshot above, it's the "Apple" variable.
- In the object inspector
, go to Data > R Code - Data > Edit Code.
- In the code editor, set the first line equal to "shares" like this:
-
Then paste in the code below. You can skip the first 3 lines, just paste everything from "#find the max value across all attributes" on down. Modify the numbers on the "z" line to change how many of the highest-ranked alternatives you count as "Selected" for use in the TURF.
shares = prop.table(exp(as.matrix((flipMaxDiff::RespondentParameters(max.diff.2)))), 1) #set first line equal to "shares". #Do not overwrite the code that was already there. # find the top N values across all attributes for each respondent. # to change the top N values selected, change the values in the square brackets: [1:2] for top 2, [1:3] for top three, etc. z <- t(apply(shares, 1, function(x) order(x, decreasing = TRUE)[1:2])) # Create a matrix of zeros with the same dimensions as 'shares' turf_matrix <- matrix(0, nrow = nrow(shares), ncol = ncol(shares)) # Populate the 'top_matrix' with 1s at the indices of the top values for (i in 1:nrow(shares)) { turf_matrix[i, z[i,]] <- 1 } # Assign matching variable names to the 'turf_matrix' colnames(turf_matrix) <- colnames(shares) #return data turf_matrix - Click the red Calculate button in the object inspector
.
- Next, go back to the Data Sources tree and select the top of the variable set again:
- With it selected, go to the General tab of the object inspector
.
- Give this modified variable set a new Label.
- From the Data tab, update the Structure dropdown to Binary - Multi.
- Click the Fix button in the orange warning that appears in the object inspector
.
- Click Proceed Regardless.
- Click OK.
Now you can use this variable set as the Alternatives in your TURF.
When you have imported preference share variables into your data set
- Hover over any variable in the Data Sources tree and click + > Custom Code > R > Numeric - Multi to create a variable set.
- Type the number of variables you want to create in the How Many Variables Do You Want to Create? box to match the number of attributes in your preference share variables.
- Click OK.
-
Expand the new R variable set and select the first variable:
- From the object inspector
, click Data > R Code - Data > Edit Code.
-
In the code editor replace the example code with the following, but update the variable set label reference in line 2 to match the label of your preference share variables. Modify the numbers on the "z" line to change how many of the highest-ranked alternatives you count as "Selected" for use in the TURF.
# get the preference shares shares <- `MaxDiff Preference Shares` # remove SUM column shares <- shares[,colnames(shares) != "SUM"] # find the top N values across all attributes for each respondent. # to change the top N values selected, change the values in the square brackets: [1:2] for top 2, [1:3] for top three, etc. z <- t(apply(shares, 1, function(x) order(x, decreasing = TRUE)[1:2])) # Create a matrix of zeros with the same dimensions as 'shares' turf_matrix <- matrix(0, nrow = nrow(shares), ncol = ncol(shares)) # Populate the 'top_matrix' with 1s at the indices of the top values for (i in 1:nrow(shares)) { turf_matrix[i, z[i,]] <- 1 } # Assign matching variable names to the 'turf_matrix' colnames(turf_matrix) <- colnames(shares) #return data turf_matrix - Press Calculate in the object inspector
.
- Follow steps 11 to 16 from the previous method.
Next
How to Save Respondent-Level Preference Shares from a MaxDiff Latent Class Analysis
UPCOMING WEBINAR: The Roadmap for Market Researchers in the Age of AI