Hi there, I am trying to run a model in the Bayesian framework using PROC GENMOD with a BAYES statement. I am specifying my priors using a data step to create a reference data set with the values of interest for my priors. However, when I call that dataset into my proc genmod + bayes using the coeffprior=normal(input=dataset), the values shown in the output are still the defaults.
The output shows the "Independent Normal Prior for Regression Coefficients" table with mean=0 and precision=1e^-6, which is not equivalent to my specified variance=1. I have tried changing the input to be precision=1 in the dataset, mean to a non-zero value, and still no changes in the output.
Can anyone assist me on how to get SAS to process the desired priors? I am running multiple models (both simple and multiple linear and logistic regressions). Thank you.
CODE:
* Normal prior (0,1) PROC GENMOD USING BAYES;
data Prior;
input _TYPE_ $ group ;
datalines;
Mean 1
Var 1
;
run;
title1 "Bayesian Unadjusted Model";
title2 "Normal (0, 1) Priors";
proc genmod data=dataproc.trial2 DESCENDING ;
class groupn(ref="Fentanyl");
model blockn = groupn / dist = bin
link = logit ;
format groupn groupn_f. blockn yesno.;
bayes seed=123 nbi=0 DIAG=ALL coeffprior=normal(input=Prior);
run;
LOG:
26 * Normal prior (0,1) PROC GENMOD USING BAYES; run; 27 data Prior; 28 input _TYPE_ $ group ; 29 datalines; NOTE: The data set WORK.PRIOR has 2 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.00 seconds 32 ; 33 run; 34 35 title1 "Bayesian Unadjusted Model of Block = Beta0+Beta1(Group)"; 36 title2 "Normal (0, 1) Priors"; 37 proc genmod data=dataproc.trial2 DESCENDING ; 38 class groupn(ref="Fentanyl"); 39 model blockn = groupn / dist = bin 40 link = logit ; 41 format groupn groupn_f. blockn yesno.; 42 bayes seed=123 nbi=0 DIAG=ALL coeffprior=normal(input=Prior); 43 run; NOTE: The default sampling algorithm is the Gamerman algorithm, which is different from the default in SAS/STAT 9.3 and earlier releases. To revert to the previous behavior, specify the SAMPLING=ARMS option in the BAYES statement. NOTE: PROC GENMOD is modeling the probability that blockn='Yes'. NOTE: Algorithm converged. NOTE: The scale parameter was held fixed. NOTE: Algorithm converged. NOTE: PROCEDURE GENMOD used (Total process time): real time 0.62 seconds cpu time 0.37 seconds
The problem is the format of your Prior data set. It should look something like the example in the documentation.
SAS Help Center: Bayesian Analysis of a Poisson Regression Model
Using an artificial data set, similar to your code, it would need to look something like this:
data trial2;
seed=2534565;
do groupn=1 to 3;
do i=1 to 250;
logit=-2 + .05*groupn;
p=exp(-logit)/(1+exp(-logit));
if ranuni(seed)>p then blockn=1; else blockn=0;
output;
end;
end;
run;
title1 "Bayesian Unadjusted Model";
title2 "Normal (0, 1) Priors";
data NormalPrior;
input _type_ $ Intercept groupn2 groupn3;
datalines;
Var 1e6 0.0005 1e6
Mean 0.0 0.1385 0.0
;
proc genmod data=trial2 DESCENDING ;
class groupn(ref="1");
model blockn = groupn / dist = bin
link = logit ;
bayes seed=123 nbi=0 DIAG=ALL coeffprior=normal(input=NormalPrior);
run;
The problem is the format of your Prior data set. It should look something like the example in the documentation.
SAS Help Center: Bayesian Analysis of a Poisson Regression Model
Using an artificial data set, similar to your code, it would need to look something like this:
data trial2;
seed=2534565;
do groupn=1 to 3;
do i=1 to 250;
logit=-2 + .05*groupn;
p=exp(-logit)/(1+exp(-logit));
if ranuni(seed)>p then blockn=1; else blockn=0;
output;
end;
end;
run;
title1 "Bayesian Unadjusted Model";
title2 "Normal (0, 1) Priors";
data NormalPrior;
input _type_ $ Intercept groupn2 groupn3;
datalines;
Var 1e6 0.0005 1e6
Mean 0.0 0.1385 0.0
;
proc genmod data=trial2 DESCENDING ;
class groupn(ref="1");
model blockn = groupn / dist = bin
link = logit ;
bayes seed=123 nbi=0 DIAG=ALL coeffprior=normal(input=NormalPrior);
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.