Hello there,
I've tried a simple regression on both SAS and Winbugs, but SAS generated different estimates everytime I hit "run" even though I didn't change any values (just press "run" again and again), while Winbugs gave me quite stable results.
Here is my SAS code, would someone tell me anything I missed in the program? Or SAS MCMC itself is not functioning well?
Thank you.
===============================
Data Base;
Input ID $ Y X_mu X_sigma;
Datalines;
A 15 4 1.1
B 8 1.2 0.8
C 12 2.8 1
;
run;
Proc MCMC Data=base nmc=10000 Autocorlag=10000 thin=1 nbi=10000 monitor = (intercept beta X);
Parms intercept beta X;
Model Y ~ normal(Intercept + beta * X , sd=1);
Prior Intercept ~ normal(0, sd=100);
Prior beta ~ normal(0, sd=100);
Prior X ~ lognormal(X_mu, sd= X_sigma);
Run;
===================================
For running five times, SAS generated estimates of beta as -1.3, 7.8, -2.3, 0.4, 2.3 (and kept changing...),
and Winbugs generated a stable range 0.70, 0.75, 0.70, 0.70, 0.70.
If you want the same results, use the SEED= option in the PROC MCMC statement:
proc MCMC Data=base SEED=12345 ...;
This sets the random number seed. By default, SEED=0, and PROC MCMC gets a random number seed from the time of day.
Thank you, @Rick_SAS. The Seed option did work, and the results are the same now.
But I checked the posterior values for each iteration, found that the values were barely moved no matter the seed was set or not (the first 20 values are as belows.) I need to increase the thinning rate, say 10, or the nmc to 200,000 to maker sure the results are right, but then it takes a lot of running time. Is this normal for SAS?
Thanks.
| Iteration | intercept | beta | x | Log Prior Density | Log-Likelihood | Log Posterior |
| 1 | 9.6 | 0.1 | 23.7 | -14.3 | -15.8 | -30.2 |
| 2 | 9.5 | 0.1 | 23.7 | -14.3 | -15.4 | -29.8 |
| 3 | 9.4 | 0.1 | 23.5 | -14.4 | -15.4 | -29.8 |
| 4 | 9.4 | 0.1 | 23.5 | -14.4 | -15.4 | -29.8 |
| 5 | 9.4 | 0.1 | 23.5 | -14.4 | -15.4 | -29.8 |
| 6 | 9.1 | 0.1 | 23.9 | -14.3 | -15.9 | -30.2 |
| 7 | 9.2 | 0.1 | 23.8 | -14.3 | -15.8 | -30.1 |
| 8 | 9.2 | 0.1 | 23.8 | -14.3 | -15.8 | -30.1 |
| 9 | 9.5 | 0.1 | 25.2 | -14.3 | -15.8 | -30.1 |
| 10 | 9.5 | 0.1 | 26.0 | -14.3 | -15.1 | -29.4 |
| 11 | 9.1 | 0.1 | 27.0 | -14.3 | -15.2 | -29.5 |
| 12 | 9.0 | 0.1 | 27.4 | -14.3 | -15.2 | -29.5 |
| 13 | 9.0 | 0.1 | 27.4 | -14.3 | -15.2 | -29.5 |
| 14 | 9.0 | 0.1 | 27.4 | -14.3 | -15.2 | -29.5 |
| 15 | 9.0 | 0.1 | 27.4 | -14.3 | -15.2 | -29.5 |
| 16 | 9.0 | 0.1 | 27.4 | -14.3 | -15.2 | -29.5 |
| 17 | 9.0 | 0.1 | 27.4 | -14.3 | -15.2 | -29.5 |
| 18 | 9.0 | 0.1 | 27.4 | -14.3 | -15.2 | -29.5 |
| 19 | 8.9 | 0.1 | 25.5 | -14.3 | -15.7 | -30.0 |
| 20 | 8.9 | 0.1 | 25.5 | -14.3 | -15.7 | -30.0 |
You are not getting any mixing at all in the chain. Your profile plots must look very strange. It is probably related to the fact that you do not have a free residual variance parameter. You are fixing the standard deviation (variance) at a constant in the model. This usually is a parameter with a prior.
I don't know why you are treating X as a parameter rather than as a fixed predictor variable. I assume you have a good reason (perhaps, as a measurement-error model).
The problem is your treatment of X as a parameter. I tried this with some data, and MCMC cannot mix. If you just had a model with X_mu as the predictor variable, it runs fine. Of course, you may have a reason to treat the predictor as a variable, although I am not aware of a reason for doing so.
Thank you, @lvm. This helps a lot.
yeah, I was guessing the "X" was the reason. When I set X constant, everything looks fine. But since X is an estimation instead of an observation in my work, I need to assign a distribution for X. I may need to figure out a way to solve this problem.