The CNTSELECT Procedure

Example 10.3 Bayesian Analysis Using NUTS with Multiple Chains

This example shows how to use the CNTSELECT procedure to estimate a model in the Bayesian framework by using the No-U-Turn Sampler (NUTS) with multiple Markov chains.

The following DATA step creates the data set DocVisit, which contains information for approximately 5,000 Australian individuals about the number and possible determinants of doctor visits that were made during a two-week interval. This data set contains a subset of variables that are taken from the data set Racd3 that was used by Cameron and Trivedi (1998).

data docvisit;
input sex age agesq income levyplus freepoor
      freerepa illness actdays hscore chcond1 chcond2
      doctorco nondocco hospadmi hospad medicine prescrib nonpresc;
datalines;
1 0.19 0.0361 0.55 1 0 0 1 4 1 0 0 1 0 0 0 1 1 0
1 0.19 0.0361 0.45 1 0 0 1 2 1 0 0 1 0 0 0 2 1 1
0 0.19 0.0361 0.9 0 0 0 3 0 0 0 0 1 0 1 4 2 1 1
0 0.19 0.0361 0.15 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0
0 0.19 0.0361 0.45 0 0 0 2 5 1 1 0 1 0 0 0 3 1 2
1 0.19 0.0361 0.35 0 0 0 5 1 9 1 0 1 0 0 0 1 1 0
1 0.19 0.0361 0.55 0 0 0 4 0 2 0 0 1 0 0 0 0 0 0
1 0.19 0.0361 0.15 0 0 0 3 0 6 0 0 1 0 0 0 1 1 0
1 0.19 0.0361 0.65 1 0 0 2 0 5 0 0 1 0 0 0 1 0 1
0 0.19 0.0361 0.15 1 0 0 1 0 0 0 0 1 0 0 0 1 1 0
0 0.19 0.0361 0.45 0 0 0 1 0 0 0 0 1 0 0 0 1 1 0

   ... more lines ...   

The variable Doctorco represents doctor visits. Additional variables in the data set that you want to evaluate as determinants of doctor visits include Sex (coded as 0=male, 1=female), Age (age in years divided by 100), Illness (number of illnesses during the two-week interval, with five or more coded as five), Income (annual income in Australian dollars divided by 1,000), and Hscore (a score on a general health questionnaire, in which a high score indicates bad health).

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

data mycas.docvisit;
   set docvisit;
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 Poisson regression model in the Bayesian framework by using the No-U-Turn Sampler (NUTS) with multiple Markov chains. NUTS is specified in the SAMPLER= option in the BAYES statement, and you can set several values that control the sampler as arguments to the SAMPLER=NUTS option. The NCHAIN= option controls the number of Markov chains, and the NSAMPLE= option controls the size of the posterior sample per chain. PROC CNTSELECT automatically aggregates the results of each chain to create the posterior statistics and MCMC diagnostics tables that you request. The BYCHAIN suboption of the STATISTICS= and DIAGNOSTICS= options additionally produces those tables separately for each chain. This example produces the "Posterior Summaries" table, the "MCMC Diagnostic Summaries" table, and the "Heidelberger-Welch Diagnostics" table for each chain as well as for all chains combined.

proc cntselect data = mycas.docvisit;
   class sex illness;
   model doctorco=sex illness income hscore;
   bayes seed = 5317 nsample = 2000 nchain = 4
         sampler = nuts(ntune = 2000)
         statistics(bychain) = summary
         diagnostics(bychain) = (summary heidel);
run;

Output 10.3.1 shows the Bayesian estimation results. The "Posterior Summaries" table displays the estimates of the posterior mean and posterior quantiles that are computed using all four chains. The other posterior summary statistics tables that the STATISTICS= option produces would similarly be computed using all four chains. The "MCMC Diagnostic Summaries" table displays basic convergence diagnostics that are aggregated across all four chains. The "Autocorrelation Diagnostics" table would also be aggregated for multiple chains. For more information about how this aggregation is performed, see the section Using Multiple Chains in Chapter 2, Introduction to Bayesian Analysis Procedures. The "Heidelberger-Welch Diagnostics" table displays a summary of all the Heidelberger-Welch tests that are performed for each chain. Specifically, for each parameter it shows the number of chains that passed each test, as well as the largest number of iterations that were discarded for the stationarity test. The "Geweke Diagnostics" table and the "Raftery-Lewis Diagnostics" table would both be summarized similarly.

Output 10.3.1: Posterior Summaries and MCMC Diagnostics

The CNTSELECT Procedure

Posterior Summaries
ParameterNMeanStandard
Deviation
Percentiles
2.5%25%50%75%97.5%
Intercept8000-0.38800.0867-0.5604-0.4459-0.3877-0.3300-0.2209
sex 08000-0.22000.0537-0.3267-0.2553-0.2202-0.1850-0.1145
illness 08000-1.93850.1220-2.1783-2.0203-1.9384-1.8551-1.7014
illness 18000-0.69810.0895-0.8773-0.7587-0.6976-0.6386-0.5215
illness 28000-0.47040.0907-0.6479-0.5321-0.4687-0.4076-0.2932
illness 38000-0.48800.0988-0.6832-0.5553-0.4863-0.4191-0.2978
illness 48000-0.27360.1088-0.4857-0.3475-0.2720-0.1998-0.0602
income8000-0.25340.0766-0.4016-0.3061-0.2530-0.2008-0.1071
hscore80000.09430.008990.07680.08820.09440.10050.1117

The CNTSELECT Procedure

MCMC Diagnostic Summaries
ParameterMCSEMCSE/SDESSAutocorrelation
Time
ESS/N
Intercept0.001950.02251983.14.03400.2479
sex 00.0007390.01375291.71.51180.6615
illness 00.002330.01912749.82.90930.3437
illness 10.001840.02052380.83.36020.2976
illness 20.001910.02102259.73.54030.2825
illness 30.001930.01952628.13.04410.3285
illness 40.001920.01773197.72.50180.3997
income0.001150.01504474.01.78810.5593
hscore0.0001390.01544209.61.90040.5262

Heidelberger-Welch Diagnostics
ParameterStationarity TestHalf-Width Test
Chains
Tested
Tests
Passed
Largest
Iterations
Discarded
Chains
Tested
Tests
Passed
Intercept44044
sex 044044
illness 044044
illness 144044
illness 244044
illness 344044
illness 444044
income44044
hscore44044


Detailed results for each chain are available in Output 10.3.2 as a result of the BYCHAIN options. The "Posterior Summaries by Chain" table displays the estimates of the posterior mean and posterior quantiles that are computed separately for each chain. Similarly, the "MCMC Diagnostic Summaries by Chain" table displays basic convergence diagnostics that are computed for each chain, and the "Heidelberger-Welch Diagnostics by Chain" table displays the Heidelberger-Welch diagnostics that are computed for each chain. For more information about the differences between the tables in Output 10.3.1 and Output 10.3.2, see the section Using Multiple Chains in Chapter 2, Introduction to Bayesian Analysis Procedures.

Output 10.3.2: Posterior Summaries and MCMC Diagnostics by Chain

The CNTSELECT Procedure

Posterior Summaries by Chain
ChainParameterNMeanStandard
Deviation
Percentiles
2.5%25%50%75%97.5%
1Intercept2000-0.38900.0889-0.5713-0.4462-0.3878-0.3280-0.2251
 sex 02000-0.21870.0529-0.3273-0.2531-0.2177-0.1839-0.1174
 illness 02000-1.93700.1222-2.1747-2.0219-1.9346-1.8559-1.6948
 illness 12000-0.69660.0915-0.8787-0.7594-0.6977-0.6374-0.5124
 illness 22000-0.47000.0934-0.6487-0.5323-0.4731-0.4078-0.2739
 illness 32000-0.48420.1011-0.6870-0.5518-0.4815-0.4145-0.2853
 illness 42000-0.27080.1131-0.4917-0.3475-0.2700-0.1955-0.0506
 income2000-0.25340.0781-0.4102-0.3058-0.2503-0.2001-0.1076
 hscore20000.09420.008890.07660.08810.09430.10020.1112
2Intercept2000-0.39520.0859-0.5615-0.4570-0.3959-0.3353-0.2266
 sex 02000-0.21930.0552-0.3321-0.2557-0.2188-0.1822-0.1138
 illness 02000-1.92950.1209-2.1668-2.0109-1.9284-1.8446-1.6998
 illness 12000-0.69060.0902-0.8674-0.7525-0.6890-0.6284-0.5204
 illness 22000-0.46330.0911-0.6502-0.5273-0.4612-0.3991-0.2961
 illness 32000-0.48280.1008-0.6834-0.5509-0.4783-0.4116-0.2915
 illness 42000-0.26720.1071-0.4802-0.3378-0.2648-0.1951-0.0595
 income2000-0.25490.0783-0.4036-0.3112-0.2565-0.1998-0.1034
 hscore20000.09450.009150.07680.08830.09460.10070.1121
3Intercept2000-0.38540.0876-0.5567-0.4421-0.3858-0.3284-0.2149
 sex 02000-0.22110.0532-0.3244-0.2561-0.2209-0.1859-0.1177
 illness 02000-1.94450.1223-2.1891-2.0227-1.9458-1.8619-1.7014
 illness 12000-0.69980.0887-0.8772-0.7594-0.6989-0.6417-0.5174
 illness 22000-0.47000.0898-0.6480-0.5313-0.4654-0.4091-0.2953
 illness 32000-0.48880.0974-0.6759-0.5570-0.4884-0.4236-0.2999
 illness 42000-0.27610.1079-0.4858-0.3522-0.2756-0.2011-0.0680
 income2000-0.25440.0746-0.4029-0.3052-0.2540-0.2038-0.1121
 hscore20000.09410.008780.07670.08810.09430.10020.1108
4Intercept2000-0.38260.0837-0.5373-0.4400-0.3828-0.3258-0.2144
 sex 02000-0.22080.0536-0.3262-0.2564-0.2223-0.1867-0.1100
 illness 02000-1.94310.1222-2.1852-2.0227-1.9432-1.8595-1.7071
 illness 12000-0.70520.0873-0.8803-0.7631-0.7051-0.6456-0.5390
 illness 22000-0.47810.0881-0.6426-0.5385-0.4774-0.4176-0.3060
 illness 32000-0.49590.0955-0.6877-0.5606-0.4930-0.4303-0.3160
 illness 42000-0.28010.1066-0.4918-0.3562-0.2784-0.2049-0.0751
 income2000-0.25100.0753-0.3888-0.3037-0.2517-0.1998-0.1045
 hscore20000.09460.009130.07700.08840.09440.10080.1126

The CNTSELECT Procedure

MCMC Diagnostic Summaries by Chain
ChainParameterMCSEMCSE/SDESSAutocorrelation
Time
ESS/N
1Intercept0.003800.0427548.73.64470.2744
 sex 00.001480.02801272.51.57170.6363
 illness 00.004330.0354796.82.50990.3984
 illness 10.003130.0342852.52.34590.4263
 illness 20.003640.0390657.83.04050.3289
 illness 30.003750.0371728.32.74590.3642
 illness 40.003270.02891198.61.66860.5993
 income0.002170.02781293.41.54630.6467
 hscore0.0002530.02841238.41.61500.6192
2Intercept0.003950.0460471.64.24070.2358
 sex 00.001550.02801276.51.56680.6382
 illness 00.004900.0405608.23.28810.3041
 illness 10.003680.0408601.83.32310.3009
 illness 20.004050.0445504.43.96520.2522
 illness 30.003670.0364755.32.64800.3776
 illness 40.004010.0374713.42.80370.3567
 income0.002430.03111035.31.93180.5176
 hscore0.0002740.02991116.41.79160.5582
3Intercept0.004250.0486423.84.71870.2119
 sex 00.001480.02791284.71.55670.6424
 illness 00.004760.0389660.83.02660.3304
 illness 10.004100.0462468.44.26990.2342
 illness 20.004080.0455483.24.13870.2416
 illness 30.004220.0433533.33.75060.2666
 illness 40.004230.0392650.33.07570.3251
 income0.002110.02831251.41.59820.6257
 hscore0.0002980.0340866.22.30900.4331
4Intercept0.003520.0420566.33.53190.2831
 sex 00.001390.02601479.31.35200.7397
 illness 00.004580.0375711.12.81250.3556
 illness 10.003650.0418571.13.50170.2856
 illness 20.003420.0388662.93.01680.3315
 illness 30.003720.0389659.73.03180.3298
 illness 40.003740.0351813.22.45930.4066
 income0.002430.0322963.42.07610.4817
 hscore0.0002810.03071060.31.88620.5302

Heidelberger-Welch Diagnostics by Chain
ChainParameterStationarity TestHalf-Width Test
Cramer-von
Mises Stat
p-ValueTest
Outcome
Iterations
Discarded
Half-WidthMeanRelative
Half-Width
Test
Outcome
1Intercept0.09330.6189Passed00.00679-0.3890-0.0174Passed
 sex 00.12560.4735Passed00.00292-0.2187-0.0133Passed
 illness 00.08680.6537Passed00.00793-1.9370-0.00409Passed
 illness 10.05890.8208Passed00.00628-0.6966-0.00902Passed
 illness 20.05620.8377Passed00.00604-0.4700-0.0128Passed
 illness 30.08300.6749Passed00.00660-0.4842-0.0136Passed
 illness 40.04200.9225Passed00.00675-0.2708-0.0249Passed
 income0.22010.2318Passed00.00446-0.2534-0.0176Passed
 hscore0.08510.6630Passed00.0004760.09420.00506Passed
2Intercept0.16320.3516Passed00.00785-0.3952-0.0199Passed
 sex 00.10640.5545Passed00.00308-0.2193-0.0140Passed
 illness 00.08450.6664Passed00.0103-1.9295-0.00535Passed
 illness 10.14390.4088Passed00.00793-0.6906-0.0115Passed
 illness 20.14920.3920Passed00.00805-0.4633-0.0174Passed
 illness 30.16010.3601Passed00.00771-0.4828-0.0160Passed
 illness 40.20570.2567Passed00.00861-0.2672-0.0322Passed
 income0.10840.5454Passed00.00460-0.2549-0.0180Passed
 hscore0.14270.4127Passed00.0005060.09450.00535Passed
3Intercept0.08490.6639Passed00.00870-0.3854-0.0226Passed
 sex 00.04510.9054Passed00.00283-0.2211-0.0128Passed
 illness 00.06420.7875Passed00.0101-1.9445-0.00520Passed
 illness 10.07610.7149Passed00.00810-0.6998-0.0116Passed
 illness 20.11870.5006Passed00.00837-0.4700-0.0178Passed
 illness 30.07550.7180Passed00.00860-0.4888-0.0176Passed
 illness 40.03790.9437Passed00.00818-0.2761-0.0296Passed
 income0.10170.5767Passed00.00457-0.2544-0.0180Passed
 hscore0.07830.7016Passed00.0006060.09410.00644Passed
4Intercept0.10590.5565Passed00.00614-0.3826-0.0160Passed
 sex 00.09660.6016Passed00.00259-0.2208-0.0117Passed
 illness 00.10860.5443Passed00.00834-1.9431-0.00429Passed
 illness 10.03110.9724Passed00.00703-0.7052-0.00996Passed
 illness 20.03340.9637Passed00.00639-0.4781-0.0134Passed
 illness 30.03140.9712Passed00.00709-0.4959-0.0143Passed
 illness 40.03540.9551Passed00.00720-0.2801-0.0257Passed
 income0.06220.8003Passed00.00464-0.2510-0.0185Passed
 hscore0.28560.1484Passed00.0005710.09460.00604Passed


Last updated: March 07, 2024