The CQLIM Procedure

Example 11.3 Bayesian Analysis

This example uses the CQLIM procedure to process a small data table in the distributed computing environment.

The following DATA step generates a data set that contains 1,000 observations from a censored model. The model contains eight variables.

data bayes_ex;
   call streaminit(12345);
   array vars x1-x7;
   array parms{7} (3 4 2 4 -3 -5 -3);
   intercept1 = 0;
   intercept2 = 4;
   intercept3 = 10;
   do i = 1 to 1000;
      sum_xb = 0;
      do j = 1 to 7;
         vars[j] = rand('NORMAL', 0, 1);
         sum_xb = sum_xb + parms[j] * vars[j];
      end;
      g = rand('NORMAL', 0, 1);
      if g <  -0.5 then intercept = intercept1;
      if g >= -0.5 then intercept = intercept2;
      if g >   0.5 then intercept = intercept3;
      y = intercept + sum_xb + 10 * rand('NORMAL', 0, 1);
      if y > 400 then y = 400;
      if y < 0   then y = 0;
      if g <  -0.5 then group = 0;
      if g >= -0.5 then group = 1;
      if g >   0.5 then group = 2;
      output;
   end;
   keep y x1-x7 group;
run;

You can load the bayes_ex data set into your CAS session by naming your CAS engine libref in the first statement of the following DATA step:

data mycas.bayes_ex;
   set bayes_ex;
run;

These statements assume that your CAS engine libref is named mycas, but you can substitute any appropriately defined libref.

The following statements estimate a censored model by using Bayesian methods. Note that the BAYES statement controls the settings for the MCMC sampler and determines which Bayesian output is produced. The NCHAIN= option controls the number of Markov chains, and the NSAMPLE= option controls the size of the posterior sample per chain. The PRIOR statements set the prior distributions for the parameters.

proc cqlim data = mycas.bayes_ex;
   class group;
   model y = x1-x7 group / censored(lb = 0 ub = 400);
   bayes priorsummary(shownames) seed = 72342 nsample = 10000 nchain = 4
         sampler = rwm(ntune = 100 ntunestage = 20);
   prior intercept ~ normal(mean = 0, sd = 100);
   prior x1-x5 ~ normal(mean = 0, sd = 10);
   prior x6 ~ t(loc = 0, scale = 10, df = 3, lower = 0);
   prior group_0 ~ normal(mean = -4, var = 100);
   prior _sigma ~ normal(mean = 0, sd = 100);
run;

Output 11.3.1 shows the Bayesian estimation results for the censored model. The "Prior Summary" table shows detailed information about prior distributions for the parameters in the model. The "Posterior Summaries" table contains two point estimates of the parameters from the posterior samples: the posterior mean and the posterior median (50th percentile). The "MCMC Diagnostics Summaries" table contains basic convergence diagnostics to check whether the Markov chain has converged and whether the sample size is sufficient.

Output 11.3.1: Bayesian Estimation of Censored Model

The CQLIM Procedure

Prior Summary
ParameterNamePriorBoundsHyperparameters
LowerUpperNameValueNameValueNameValue
InterceptInterceptNormal-InftyInftyMean0Variance10000  
x1x1Normal-InftyInftyMean0Variance100  
x2x2Normal-InftyInftyMean0Variance100  
x3x3Normal-InftyInftyMean0Variance100  
x4x4Normal-InftyInftyMean0Variance100  
x5x5Normal-InftyInftyMean0Variance100  
x6x6Truncated t0InftyLocation0Scale10DF3
x7x7Normal-InftyInftyMean0Variance1000000  
group 0group_0Normal-InftyInftyMean-4Variance100  
group 1group_1Normal-InftyInftyMean0Variance1000000  
_Sigma_SigmaTruncated Normal0InftyMean0Variance10000  

The CQLIM Procedure

Posterior Summaries
ParameterNMeanStandard
Deviation
Percentiles
2.5%25%50%75%97.5%
Intercept4000010.21010.68818.80469.751210.226310.683711.5101
x1400002.94780.37372.22762.70012.94663.18913.7152
x2400003.66350.35492.97273.42113.66573.90174.3697
x3400002.36400.35461.71682.12292.34152.59453.1004
x4400003.71390.34403.08793.48003.69883.93914.4343
x540000-3.10580.3693-3.8217-3.3589-3.1012-2.8553-2.3860
x6400000.02820.02810.0008120.008220.01970.03900.1032
x740000-2.49300.3636-3.1820-2.7399-2.4991-2.2469-1.7793
group 040000-9.48940.9844-11.3458-10.1500-9.5118-8.8705-7.4648
group 140000-7.40070.8598-9.0624-7.9876-7.3987-6.8169-5.6735
_Sigma4000010.49330.28349.973610.297310.481810.678511.0791

The CQLIM Procedure

MCMC Diagnostic Summaries
ParameterMCSEMCSE/SDESSAutocorrelation
Time
ESS/N
Intercept*0.05390.0783163.1245.30.00408
x1*0.02400.0643242.1165.20.00605
x2*0.02060.0580297.1134.60.00743
x3*0.01900.0536348.6114.70.00872
x4*0.02150.0625255.7156.40.00639
x5*0.02110.0571306.3130.60.00766
x6*0.001280.0454485.482.40620.0121
x7*0.02360.0650236.3169.20.00591
group 0*0.06600.0670222.4179.80.00556
group 1*0.06060.0705201.4198.60.00503
_Sigma*0.01620.0571306.4130.60.00766
 *Autocorrelation Remains


Last updated: January 27, 2023