The HPDECIDE Procedure
Example 6.1 Using a Revenue Matrix and Cost Variables to Make Decisions
This fictitious example demonstrates how to use PROC HPDECIDE to adjust posterior probabilities and how to use a revenue matrix and cost variables to make decisions. In the following DATA steps, the categorical target variable tar has two levels in the data set data1: a and b.
data data1(drop=i);
do i=1 to 5;
tar="b";
if i<3 then tar="a";
p_a=abs(ranuni(81923));
p_b=abs(1-p_a);
c1=ranpoi(38192,5);
c2=ranpoi(28131,7);
output;
end;
run;
data decdata1(type=revenue);
input dv1-dv2 op np tar $;
DATALINES;
5 3 .5 .2 a
6 3 .5 .8 b
;
The estimated posterior probabilities that correspond to the categories of the target variable are denoted by p_a and p_b. The two cost variables, c1 and c2, represent the target-specific consequences for the decision variables dv1 and dv2, respectively. The variable op contains the "old" prior probabilities that were used the first time the model was fictitiously fit. The variable np contains the "new" prior probabilities that are used to make decisions.
The following statements take the data set data1 and the data set decdata1, and output the data set out1 and the data set outstat1. The target variable is tar. Because the input data set resides on the client and no PERFORMANCE statement is specified, the client performs all computations.
proc hpdecide data=data1 out=out1 outstat=outstat1;
decision decdata=decdata1 decvars=dv1-dv2
oldpriorvar=op priorvar=np cost=c1 c2;
posteriors p_a p_b;
target tar;
performance details nthreads=2;
run;
proc print data=out1;
var p_a p_b I_tar F_tar dv1 dv2 D_DECDATA1 EP_DECDATA1 CP_DECDATA1;
run;
proc print data=outstat1;
run;
Output 6.1.1 shows the out1 data set, which displays the decision for each observation. The adjusted posterior probabilities are also shown in the out1 data set.
Output 6.1.1: out1 Data Set
| Obs | p_a | p_b | I_tar | F_tar | dv1 | dv2 | D_DECDATA1 | EP_DECDATA1 | CP_DECDATA1 |
|---|---|---|---|---|---|---|---|---|---|
| 1 | 0.35602 | 0.64398 | B | A | 0.64398 | -6 | dv1 | 0.64398 | 0 |
| 2 | 0.38571 | 0.61429 | B | A | 0.61429 | -1 | dv1 | 0.61429 | 0 |
| 3 | 0.18922 | 0.81078 | B | B | -1.18922 | -2 | dv1 | -1.18922 | -1 |
| 4 | 0.11035 | 0.88965 | B | B | 4.88965 | 0 | dv1 | 4.88965 | 5 |
| 5 | 0.29158 | 0.70842 | B | B | -3.29158 | -2 | dv2 | -2.00000 | -2 |
Output 6.1.2 shows the outstat1 data set, which shows that the total profit is 2.6666666667 and the average profit is 0.5333333333, based on the decisions from the out1 data set.
Output 6.1.2: outstat1 Data Set
| Obs | _PROF_ | _APROF_ |
|---|---|---|
| 1 | 2.66667 | 0.53333 |
Output 6.1.3 shows the performance information.
Output 6.1.3: Performance Information
| Performance Information | |
|---|---|
| Execution Mode | Single-Machine |
| Number of Threads | 2 |