Help diagnosing/fixing error "c++ exception (unknown reason)" during sampling

413 views
Skip to first unread message

sas...@columbia.edu

unread,
May 6, 2017, 1:12:05 PM5/6/17
to Stan users mailing list

In writing an example for section 6.2 of Gelman & Hill (2006) (p. 112), I receive the following error in my example model, which compiles fine:

SAMPLING FOR MODEL 'stops_eth' NOW (CHAIN 1).
[1] "Error in sampler$call_sampler(args_list[[i]]) : "
[2] "  c++ exception (unknown reason)"                
error occurred during calling the sampler; sampling not done

I'm running rstan 2.15.1 within R 3.4.0.

I'm using R to call the Stan program: 
library(rstan)

source
("frisks.data.R")

dataList
<- c("N","stops","arrests")
stops_eth_poisson
.sf1 <- stan(file='stops_eth.stan', data=dataList,
                         iter
=1000, chains=4)



I've attached the data file, and the Stan program "stops_eth.stan" follows:

data {
 
int<lower=1> N;
 
int<lower=0> stops[N];
  vector
<lower=0>[N] arrests;
}
transformed data
{
  vector
[N] log_arrests;
  log_arrests
= log(arrests);
}
parameters
{
  vector
[2] beta;
}
model
{
  target
+= poisson_lpmf(stops | beta[1] + beta[2] * log_arrests);
}



frisks.data.R

Ben Goodrich

unread,
May 6, 2017, 5:57:23 PM5/6/17
to Stan users mailing list
On Saturday, May 6, 2017 at 1:12:05 PM UTC-4, sas...@columbia.edu wrote:
data {
  int<lower=1> N;
 
int<lower=0> stops[N];
  vector
<lower=0>[N] arrests;
}
transformed data
{
  vector
[N] log_arrests;
  log_arrests
= log(arrests);
}
parameters
{
  vector
[2] beta;
}
model
{
  target
+= poisson_lpmf(stops | beta[1] + beta[2] * log_arrests);
}


You want poisson_log_lpmf(stops | beta[1] + beta[2] * log_arrests). Also, doing log(arrests) is problematic when some observations on arrests are 0.

Ben



 

Bob Carpenter

unread,
May 7, 2017, 12:21:12 PM5/7/17
to stan-...@googlegroups.com
This is a bug people seem to be getting with new RStan installs.

Ben --- is there a fix for this on the way or a diagnosis of what's
going on?

- Bob
> --
> 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.
> To post to this group, send email to stan-...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
> <frisks.data.R>

Bob Carpenter

unread,
May 7, 2017, 12:22:11 PM5/7/17
to stan-...@googlegroups.com
That's the problem with the model, but there's also a problem with
your RStan install---it should be saying where and what the problem is.

- Bob

sas...@columbia.edu

unread,
May 7, 2017, 12:40:33 PM5/7/17
to Stan users mailing list
thanks. I thought I had followed the advise to avoid the issue by compiling rstan from source. I'll try installing again. I'm still new enough to Stan to not anticipate how detailed its messages should be.

Ben Goodrich

unread,
May 7, 2017, 3:40:37 PM5/7/17
to Stan users mailing list
On Sunday, May 7, 2017 at 12:21:12 PM UTC-4, Bob Carpenter wrote:
This is a bug people seem to be getting with new RStan installs.  

Ben --- is there a fix for this on the way or a diagnosis of what's
going on?

No. And it is a bug in Stan, not RStan

https://github.com/stan-dev/stan/issues/2294

Ben

Reply all
Reply to author
Forward
0 new messages