Stan model 'model' does not contain samples. What to do?

3,403 views
Skip to first unread message

Nikolay Evdokimov

unread,
Mar 29, 2016, 10:13:42 AM3/29/16
to Stan users mailing list
Hello! 
Please help!

I have model:

data {
  vector[500] yObserved; // s.e. of effect estimates 
  vector[500] xObserved;
}

parameters {
  real<lower=0.1, upper=5> k; 
  
}

transformed parameters
{
    vector[500] epsilon; 
     epsilon <- yObserved / k - xObserved;
}

model {
    epsilon ~ uniform(-10,10);
   // (yObserved / k - xObserved) ~ uniform(-30,30);
}




And R-script:

rm(list=ls())
library(rstan)
rstan_options(auto_write = TRUE)
options(mc.cores = parallel::detectCores())

n <- 500
x <- runif(n, min=-30, max=30)
k <- 2
epsilon <- runif(n, min=-10, max=10)
y1 <- x * k + epsilon
y2 <- (x + epsilon) * k

plot(x,y1,col="red")
points(x,y2,col="blue")

fitlm1 = lm(y1 ~ x)
fitlm2 = lm(y2 ~ x)

fitlm1
fitlm2




inpData <- list(yObserved = as.array(y2), xObserved = as.array(x))
fit <- stan(file = 'D:\\RProjects\\LineWithNoise\\model.stan', data = inpData, iter = 200)
la <- extract(fit, permuted = TRUE) # return a list of arrays
from_model_k <- la$k
from_model_epsilon <- la$epsilon

hist(from_model_k,  breaks=seq(0,5,l=50))

I want to determine what are epsilon and k from observed x and y2.

And for some data it gives me following errors:


here are whatever error messages were returned
[[1]]
Stan model 'model' does not contain samples.

[[2]]
Stan model 'model' does not contain samples.

[[3]]
Stan model 'model' does not contain samples.

Warning messages:
1: In .local(object, ...) :
  some chains had errors; consider specifying chains = 1 to debug
2: There were 98 divergent transitions after warmup. Increasing adapt_delta above 0.8 may help. 
3: Examine the pairs() plot to diagnose sampling problems

For some data (size = 300) it works ok and for some data (size=500) it fails.

What does it mean? And how to fight it?

Bob Carpenter

unread,
Mar 29, 2016, 10:32:06 AM3/29/16
to stan-...@googlegroups.com
I'd guess you're generating data for which epsilon is not in (-10, 10)
and therefore your uniform sampling (which isn't doing anything because
epsilon is data and the bounds are data), will cause it to fail.

You need a constraint on epsilon, <lower=-10, upper=10>, you'll probably
find the bad data items.

We generally prefer naturally constrained parameters and proper continuous
priors rather than intervals, which are dangerous both statistically and
computationally.

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

Reply all
Reply to author
Forward
0 new messages