Published on :
Statistics INTERNAL_CREATION

Predicting Choice Probabilities with PROC BCHOICE

This code is also available in: Deutsch Español Français
Awaiting validation
This script illustrates the use of the BCHOICE procedure to fit a discrete choice model (here, chocolate preferences) and predict choice probabilities for a set of user-defined scenarios (covariates). It creates training data and a design matrix (DesignMatrix), runs the MCMC simulation, and generates posterior predictive distributions via the PREDDIST statement.
Data Analysis

Type : INTERNAL_CREATION


Training data (Chocs) and covariates for prediction (DesignMatrix) are entirely created within the script via DATA and DATALINES steps.

1 Code Block
DATA STEP Data
Explanation :
Creation of the 'Chocs' dataset containing observed choices (Choice variable) for 10 subjects (Subj) based on binary product characteristics (Dark, Soft, Nuts).
Copied!
1DATA Chocs;
2 INPUT Subj Choice Dark Soft Nuts;
3 DATALINES;
41 0 0 0 0
51 0 0 0 1
61 0 0 1 0
71 0 0 1 1
81 1 1 0 0
91 0 1 0 1
101 0 1 1 0
111 0 1 1 1
122 0 0 0 0
132 0 0 0 1
142 0 0 1 0
152 0 0 1 1
162 0 1 0 0
172 1 1 0 1
182 0 1 1 0
192 0 1 1 1
203 0 0 0 0
213 0 0 0 1
223 0 0 1 0
233 0 0 1 1
243 0 1 0 0
253 0 1 0 1
263 1 1 1 0
273 0 1 1 1
284 0 0 0 0
294 0 0 0 1
304 0 0 1 0
314 0 0 1 1
324 1 1 0 0
334 0 1 0 1
344 0 1 1 0
354 0 1 1 1
365 0 0 0 0
375 1 0 0 1
385 0 0 1 0
395 0 0 1 1
405 0 1 0 0
415 0 1 0 1
425 0 1 1 0
435 0 1 1 1
446 0 0 0 0
456 0 0 0 1
466 0 0 1 0
476 0 0 1 1
486 0 1 0 0
496 1 1 0 1
506 0 1 1 0
516 0 1 1 1
527 0 0 0 0
537 1 0 0 1
547 0 0 1 0
557 0 0 1 1
567 0 1 0 0
577 0 1 0 1
587 0 1 1 0
597 0 1 1 1
608 0 0 0 0
618 0 0 0 1
628 0 0 1 0
638 0 0 1 1
648 0 1 0 0
658 1 1 0 1
668 0 1 1 0
678 0 1 1 1
689 0 0 0 0
699 0 0 0 1
709 0 0 1 0
719 0 0 1 1
729 0 1 0 0
739 1 1 0 1
749 0 1 1 0
759 0 1 1 1
7610 0 0 0 0
7710 0 0 0 1
7810 0 0 1 0
7910 0 0 1 1
8010 0 1 0 0
8110 1 1 0 1
8210 0 1 1 0
8310 0 1 1 1
84;
2 Code Block
DATA STEP Data
Explanation :
Creation of a 'DesignMatrix' table containing the 8 possible combinations of attributes for which predicted probabilities are to be calculated.
Copied!
1DATA DesignMatrix;
2 INPUT Dark Soft Nuts;
3 DATALINES;
40 0 0
50 0 1
60 1 0
70 1 1
81 0 0
91 0 1
101 1 0
111 1 1
12;
3 Code Block
PROC BCHOICE
Explanation :
Execution of PROC BCHOICE to fit the model. The MODEL statement specifies the response and effects. The PREDDIST statement uses the 'DesignMatrix' covariates to generate predictive distributions (Probabilities) in the 'Predout' output table.
Copied!
1PROC BCHOICE DATA=Chocs outpost=Bsamp nmc=10000 thin=2 seed=124;
2 class Dark(ref='0') Soft(ref='0') Nuts(ref='0') Subj;
3 model Choice = Dark Soft Nuts / choiceset=(Subj);
4 preddist covariates=DesignMatrix nalter=8 outpred=Predout;
5RUN;
4 Code Block
MACRO CALL
Explanation :
Call to the %SUMINT macro to summarize the credibility intervals of the predicted probabilities (variables starting with Prob_1_) contained in the 'Predout' table.
Copied!
1%SUMINT(DATA=Predout, var=Prob_1_:)
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : SAS SAMPLE LIBRARY, NAME: BCHCEX7, PRODUCT: STAT