PROC MCMC does not have a debugger. This section covers a few ways to debug and resolve error messages.
Adding the PUT statement often helps to find errors in a program. The following statements produce an error:
data a; run; proc mcmc data=a seed=1; parms sigma lt w; beginnodata; prior sigma ~ unif(0.001,100); s2 = sigma*sigma; prior lt ~ gamma(shape=1, iscale=0.001); t = exp(lt); c = t/s2; d = 1/(s2); prior w ~ gamma(shape=c, iscale=d); endnodata; model general(0); run;
ERROR: PROC MCMC is unable to generate an initial value for the parameter w. The first parameter in the prior distribution is missing.
To find out why the shape parameter c
is missing, you can add the put
statement and examine all the calculations that lead up to the assignment of c
:
proc mcmc data=a seed=1; parms sigma lt w; beginnodata; prior sigma ~ unif(0.001,100); s2 = sigma*sigma; prior lt ~ gamma(shape=1, iscale=0.001); t = exp(lt); c = t/s2; d = 1/(s2); put c= t= s2= lt=; /* display the values of these symbols. */ prior w ~ gamma(shape=c, iscale=d); endnodata; model general(0); run;
In the log file, you see the following:
c=. t=. s2=. lt=. c=. t=. s2=2500.0500003 lt=1000 c=. t=. s2=2500.0500003 lt=1000 ERROR: PROC MCMC is unable to generate an initial value for the parameter w. The first parameter in the prior distribution is missing.
You can ignore the first few lines. They are the results of initial set up by PROC MCMC. The last line is important. The variable
c
is missing because t
is the exponential of a very large number, 1000, in lt
. The value 1000 is assigned to lt
by PROC MCMC because none was given. The gamma prior with shape of 1 and inverse scale of 0.001 has mode 0 (see Standard Distributions for more details). PROC MCMC avoids starting the Markov chain at the boundary of the support of the distribution, and it
uses the mean value here instead. The mean of the gamma prior is 1000, hence the problem. You can change how the initial value
is generated by using the PROC statement INIT=RANDOM
. Remember to take out the put
statement once you identify the problem. Otherwise, you will see a voluminous output in the log file.
You can use the HYPER statement to narrow down possible errors in the prior distribution specification. With multiple PRIOR statements in a program, you might see the following error message if one of the prior distributions is not specified correctly:
ERROR: The initial prior parameter specifications must yield log of positive prior density values.
This message is displayed when PROC MCMC detects an error in the prior distribution calculation but cannot pinpoint the specific parameter at fault. It is frequently, although not necessarily, associated with parameters that have GENERAL or DGENERAL distributions. If you have a complicated model with many PRIOR statements, finding the parameter at fault can be time consuming. One way is to change a subset of the PRIOR statements to HYPER statements. The two statements are treated the same in PROC MCMC and the simulation is not affected, but you get a different message if the hyperprior distributions are calculated incorrectly:
ERROR: The initial hyperprior parameter specifications must yield log of positive hyperprior density values.
This message can help you identify more easily which distributions are producing the error, and you can then use the PUT statement to further investigate.