error message: Error in function stan::prob::student_t_log(N4stan5agrad3varE): Scale parameter is 1.

384 views
Skip to first unread message

Yingjie Hu

unread,
May 6, 2014, 5:22:02 PM5/6/14
to stan-...@googlegroups.com
I want to run the program in https://github.com/stan-dev/stan/blob/master/src/models/bugs_examples/vol1/blocker/blocker.stan


Here is my code:

code <- '
data {
  int<lower=0> N; 
  int<lower=0> nt[N]; 
  int<lower=0> rt[N]; 
  int<lower=0> nc[N]; 
  int<lower=0> rc[N]; 
parameters {
  real d; 
  real<lower=0> sigmasq_delta; 
  vector[N] mu;
  vector[N] delta;
  real delta_new;
transformed parameters {
  real<lower=0> sigma_delta; 
  sigma_delta <- sqrt(sigmasq_delta); 
model {
  rt ~ binomial_logit(nt, mu + delta);
  rc ~ binomial_logit(nc, mu);
  delta  ~ student_t(4, d, sigma_delta); 
  mu ~ normal(0, sqrt(1E5));
  d ~ normal(0, 1E3); 
  sigmasq_delta ~ inv_gamma(1E-3, 1E-3); 
  // FIXME: sample in generated quantities in later version
  delta_new ~ student_t(4, d, sigma_delta); 
}'

# data
data <- list(rt = c(3, 7, 5, 102, 28, 4, 98, 60, 25, 138, 64, 45, 9, 57, 25, 33, 28, 8, 6, 32, 27, 22),
            nt = c(38, 114, 69, 1533, 355, 59, 945, 632, 278, 1916, 873, 263, 291, 858, 154, 207, 251, 151, 174, 209, 391, 680),
            rc = c(3, 14, 11, 127, 27, 6, 152, 48, 37, 188, 52, 47, 16, 45, 31, 38, 12, 6, 3, 40, 43, 39),
            nc = c(39, 116, 93, 1520, 365, 52, 939, 471, 282, 1921, 583, 266, 293, 883, 147, 213, 122, 154, 134, 218, 364, 674),
            N = 22)


fit <- stan(model_code = code, data = data, iter = 1000, chains = 4,ini=0, seed=30)

I get two kinds of errors.

Informational Message: The current Metropolis proposal is about to be rejected becuase of the following issue:
Error in function stan::prob::student_t_log(N4stan5agrad3varE): Scale parameter is 1.#INF:0, but must be finite!
If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.

Informational Message: The current Metropolis proposal is about to be rejected becuase of the following issue:
Error in function stan::prob::student_t_log(N4stan5agrad3varE): Scale parameter is 0:0, but must be > 0!
If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.



The difference of the errors are bold texts in the above.

I do not know how to solve the issue. There is no student_t_log function in my code.

If you can help me, thank you beforehand.

Christian Roy

unread,
May 6, 2014, 5:35:33 PM5/6/14
to stan-...@googlegroups.com
you can't initialise your model with only zeroes since you put a constraint on sigmasq_delta.

 real<lower=0> sigmasq_delta;

You will need to pick something bigger than zero for this parameter for the initialisation

Chris
-----------------




--
You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Christian Roy

unread,
May 6, 2014, 5:41:37 PM5/6/14
to stan-...@googlegroups.com
Oh and you do have a student t distribution in your code:

delta  ~ student_t(4, d, sigma_delta); 

student_t_log is how the sampler is called for a student_t distribution (and the syntax is pretty similar for all the distribution). 
The manual explain has a section that explain how (and why) the sampler is called this way

Good luck

Chris
----------

 

Michael Betancourt

unread,
May 6, 2014, 5:51:32 PM5/6/14
to stan-...@googlegroups.com
init=0 initializes to zero on the unconstrained scale, so this is fine here.  Indeed, unless
you specify explicit initialization values for each parameter the initialization is always
done on the unconstrained scale.

The problem is in one these two lines,

  delta  ~ student_t(4, d, sigma_delta); 
  delta_new ~ student_t(4, d, sigma_delta); 

The value of sigma_delta is overflowing/underflowing and causing the call to student_t
to fail.  If this is happening rarely then there’s no problem as the failures are handled
appropriately by the Markov chain, but if it’s happening often (say, more than 10% of
iterations) then the model has some issues.

You’ll want to use the right initializations, 
which give reasonable results.

Yingjie Hu

unread,
May 6, 2014, 6:27:25 PM5/6/14
to stan-...@googlegroups.com
Thank you, Michael.

I added initial values in the link to the code. My code now becomes as follows. But the error still exists. 

# initial
ini <- list(d = 0, 
            delta = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
            sigmasq_delta = 1, 
            mu = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), 
            delta = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
            delta_new = 0
            )

iniLIst <- rep(list(ini),4)
fit <- stan(model_code = code, data = data, iter = 1000, chains = 4,ini=iniLIst)

Michael Betancourt

unread,
May 6, 2014, 6:58:45 PM5/6/14
to stan-...@googlegroups.com
But does it happen intermittently (and only during warmup) or does it
happen at every iteration?  It’s only a warning not an error.

Yingjie Hu

unread,
May 6, 2014, 11:19:27 PM5/6/14
to stan-...@googlegroups.com
It varies. Sometime one chain has one error while sometimes two or three chains have errors.

Why did you think it is not an error? I thought it was an error because it said "Error in function stan::prob::student_t_log".

Bob Carpenter

unread,
May 7, 2014, 5:08:57 AM5/7/14
to stan-...@googlegroups.com

On May 7, 2014, at 5:19 AM, Yingjie Hu <bynbut...@gmail.com> wrote:

> It varies. Sometime one chain has one error while sometimes two or three chains have errors.

That's fine. Read the rest of the message.

It's an error being spit out by the student_t function, but not an
error for the sampler. The sampler swallows the error from the
function, Metropolis rejects the proposal, and continues. This doesn't
cause a problem in the posterior unless it's happening very frequently.
If it does happen very frequently, it can indicate a problem in the model
specification, which is why we're dumping the message out.

But I really think we need to just eliminate it or make it optional,
or figure out how to get rid of the word "error", because a large
segment of our user population focuses on the fact that something's
getting spit out and thinks Stan or their model is broken.

- Bob

Yingjie Hu

unread,
May 7, 2014, 10:59:31 AM5/7/14
to stan-...@googlegroups.com
Thank you, Bob.

What is the definition of "sporadically“? Can it be called "sporadically“ that every chain has one informational message? 

Michael Betancourt

unread,
May 7, 2014, 11:02:02 AM5/7/14
to stan-...@googlegroups.com
The relevant ratio is not messages / per chain but message / iteration.  If every
transition of the Markov chain rejects because of this problem you have a bad
model, if only a few transitions are rejected because of it then you’re okay.

Yingjie Hu

unread,
May 7, 2014, 11:59:40 PM5/7/14
to stan-...@googlegroups.com
Thank you. I get it.
Reply all
Reply to author
Forward
0 new messages