FOCUS AREAS

SAS/STAT Examples

Bayesian Multinomial Model for Ordinal Data


Contents | SAS Program | PDF


data icecream;
   input y1-y5 brand;
   if brand = 1 then brand1 = 1;
      else brand1 = 0;
   if brand = 2 then brand2 = 1;
      else brand2 = 0;
   keep y1-y5 brand1 brand2;
   datalines;
   70 71 151 30 46 1                            
   20 36 130 74 70 2 
   50 55 140 52 50 3 
   ;

ods graphics on;
   proc mcmc data=icecream nbi=10000 nmc=25000 thin=10 seed=1181
   propcov=quanew monitor=(beta1 beta2 or12 or13 or23);   
   array data[5] y1 y2 y3 y4 y5;
   array theta[4]; 
   array gamma[4];
   array pi[5]; 
   
   parms theta1-theta4 beta1 beta2;  
   prior theta1 ~ normal(0,var=100); 
   prior theta2 ~ normal(0,var=100,lower=theta1);
   prior theta3 ~ normal(0,var=100,lower=theta2);
   prior theta4 ~ normal(0,var=100,lower=theta3);
   prior beta: ~ normal(0,var=1000);

   mu = beta1*brand1 + beta2*brand2;
   do j = 1 to 4;
      gamma[j] = logistic(theta[j] + mu);
     if j>=2  then pi[j]=gamma[j]-gamma[j-1];
   end;
   pi1 = gamma1;
   pi5 = 1 - sum(of pi1-pi4);

   model data~multinom(pi);

   beginnodata;
      or12 = exp(beta1-beta2);
      or13 = exp(beta1);
      or23 = exp(beta2);
   endnodata;         
run;   
ods graphics off;