turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- Analytics
- /
- Stat Procs
- /
- Proc MCMC cannot generate stable results

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-26-2015 08:53 PM - edited 11-26-2015 09:49 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-28-2015 06:21 AM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-29-2015 09:56 PM - edited 11-29-2015 09:57 PM

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 |

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-30-2015 01:53 PM

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).

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-30-2015 04:21 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-30-2015 09:03 PM

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.