9
$\begingroup$

I tried to run a Stan model without data to get plots for the prior distributions. However, this does not seem to be possible, I get an error message about my model not containing samples. So, is there a way for getting at the prior distributions? Maybe it's possible to run Stan without the sampler?

$\endgroup$
7
$\begingroup$

As my previous answer was deleted, here is a more explicit one, with an example using a simple sampling from the prior:

library(rstan)

model = "
parameters {
  real p;
}
model {
  p ~ normal(1,3);
}
"

fit = stan(model_code = model, 
           pars = c('p'),
           control=list(adapt_delta=0.99, max_treedepth=10),
           iter = 5000, chains = 1, 
           warmup = 1000, verbose=FALSE)

print(fit)

with output:

Inference for Stan model: a067aa7e9d60dcf5fa2c08c3db339374.
1 chains, each with iter=5000; warmup=1000; thin=1; 
post-warmup draws per chain=4000, total post-warmup draws=4000.

      mean se_mean  sd  2.5%   25%   50%   75% 97.5% n_eff Rhat
p     1.02    0.07 3.0 -4.84 -1.02  1.01  3.07  6.83  1607    1
lp__ -0.50    0.02 0.7 -2.47 -0.66 -0.23 -0.05  0.00  1346    1

Hope this helps...

$\endgroup$
  • $\begingroup$ One thing I added to visualize the distribution was p <- extract(fit, "p")$p followed by a hist(p). I also set the warmup parameter to zero because I didn't think it was necessary here. $\endgroup$ – Ben Ogorek Nov 7 '16 at 1:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.