problem sampling from uniform(1,100) prior

67 views
Skip to first unread message

tgs

unread,
Sep 30, 2012, 1:48:27 PM9/30/12
to stan-...@googlegroups.com
Hi

Strangely, I am getting error when I use a uniform(1,100) prior (and no data), while getting expected results when my prior is uniform(-100,100)!

http://pastebin.com/McHMPZHq

The error is that all "proposals" are rejected, and getting the warnings listed below.

Hopefully, I did not do an embarrassing typo or something like that.

Thanks
T






Warning (non-fatal rejection): Error in function stan::prob::uniform_log<N4stan5agrad3varE>(N4stan5agrad3varE): y is nan:0, but must not be nan!

Warning (non-fatal rejection): Error in function stan::prob::uniform_log<N4stan5agrad3varE>(N4stan5agrad3varE): y is nan:0, but must not be nan!

Warning (non-fatal rejection): Error in function stan::prob::uniform_log<N4stan5agrad3varE>(N4stan5agrad3varE): y is nan:0, but must not be nan!
Iteration: 1980 / 2000 [ 99%]  (Sampling)
Warning (non-fatal rejection): Error in function stan::prob::uniform_log<N4stan5agrad3varE>(N4stan5agrad3varE): y is nan:0, but must not be nan!

Warning (non-fatal rejection): Error in function stan::prob::uniform_log<N4stan5agrad3varE>(N4stan5agrad3varE): y is nan:0, but must not be nan!

Warning (non-fatal rejection): Error in function stan::prob::uniform_log<N4stan5agrad3varE>(N4stan5agrad3varE): y is nan:0, but must not be nan!

Ben Goodrich

unread,
Sep 30, 2012, 1:58:17 PM9/30/12
to stan-...@googlegroups.com
parameters {
  real mu
; // should be real<lower=1,upper=100> mu;
  real
<lower=0> sig;
}
model
{
  mu
~ uniform(1,100); // with above change, this line is not strictly necessary
  sig
~ inv_gamma(2,1);
}

Various bad things can happen when the prior puts zero mass on part of the support of a parameter.

Ben

tgs

unread,
Sep 30, 2012, 3:25:05 PM9/30/12
to stan-...@googlegroups.com
Here is the real reason (above one just a simplified "boiled down" case): I want to put different priors on different elements of the matrix, unif(0,0.0001) on the upper triangular, unif(0,200) on diagonal, and unif(-200,200) on lower triangular elements.

http://pastebin.com/Xzh5rtjV

Ben Goodrich

unread,
Sep 30, 2012, 3:39:38 PM9/30/12
to stan-...@googlegroups.com
If there is no prior on a parameter, it is considered uniform on its support. So, the real question is how to restrict the support of different elements of a matrix, and the answer unfortunately is that it is not as straightforward as one might hope. Marcus gave an example of doing so at this link:

https://groups.google.com/d/msg/stan-users/fZlVgP1xeU8/oPaUKlP2V2MJ

Ben

Ben Goodrich

unread,
Sep 30, 2012, 3:57:03 PM9/30/12
to stan-...@googlegroups.com
On Sunday, September 30, 2012 3:25:05 PM UTC-4, tgs wrote:
Here is the real reason (above one just a simplified "boiled down" case): I want to put different priors on different elements of the matrix, unif(0,0.0001) on the upper triangular, unif(0,200) on diagonal, and unif(-200,200) on lower triangular elements.

http://pastebin.com/Xzh5rtjV

Or you can do something like

data {
  int<lower=1> K;
}
transformed data {
  int K_choose_2;
  K_choose_2 <- K * (K - 1) / 2;
}
parameters {
  real<lower=-200,upper=200> lowers[K_choose_2];
  real<lower=0,upper=0.001>  uppers[K_choose_2];
  real<lower=0,upper=200>     diagonals[K];
}
transformed parameters {
  matrix[K,K] mu;
  // for loops to put lowers, uppers, and diagonals into mu
}

Ben

Reply all
Reply to author
Forward
0 new messages