> On Nov 4, 2015, at 7:06 PM, Qian Zhang <
qian.s...@gmail.com> wrote:
>
> For a particular hierarchical model, I derived the full conditional distributions of the parameters to implement Gibbs sampling in R.
>
> I showed that when a drawn sigmaSquared value is > 20, the variance of the full conditional distribution for a0 takes a negative value, making it impossible to make another a0 draw.
The only way this would happen is if your joint distribution is
improper.
The warning you get from Stan is probably during warmup when it's
trying to find appropriate scales. I'm not sure whether the current RStan
reports when the error occurs --- the behavior's changed recently because of
the number of complaints about too many warning messages on the fly.
You can try starting with a smaller initial
stepsize and higher target acceptance rate, which can help with numerical instability:
control = list(stepsize=0.01, adapt_delta=0.99)
You can also make the model much more efficient with vectorization.
- Bob
> Indeed, when I coded up Metropolis-within Gibbs with the full conditionals I derived, the sampler stopped after enough iterations, because it would eventually draw a sigmaSquared value > 20.
>
> I checked my full conditional derivations and they look right, but wanted to double check with STAN - The idea being if STAN could sample without any errors, then maybe there is something wrong with my derivations that I didn't find.
>
> However, I encountered an error when using STAN and I wonder if it's related at all to the full conditionals being problematic? In other words, I wonder if certain priors will give you full conditional distributions such that a drawn parameter value can result in the variance of another parameter's full conditional distribution being negative, and if the error from STAN is indicative of this?
>
> My R file is post.11.04.2015.R:
>
> set.seed(2)
>
> dat <- list(J = 2,
> n =c(1000,1000),
> a = c(200, 800))
>
> fit9 <- stan(file = 'post_11.04.2015.stan', data = dat,
> iter = 100000, chains = 4)
>
> My STAN file is post_11.04.2015.stan:
>
> data {
> int<lower=0> J; // j = 1, ..., J
> int<lower=0> a[J];
> int<lower=0> n[J];
> }
>
> parameters {
> real a0;
> real<lower=0> sigmaSquared;
> real<lower=0, upper=1> theta[J];
>
> real<lower=0, upper=1> ptilde[J];
> real<lower=0, upper=1> p;
> }
>
> model{
>
> p ~ uniform(0,1);
>
> a0 ~ normal(0, sqrt(10));
> sigmaSquared ~ inv_gamma(1,1);
>
> for(j in 1:J){
> theta[j] ~ lognormal(a0, sqrt(sigmaSquared));
> ptilde[j] ~ beta(theta[j]*p, theta[j]*(1-p));
> // beta(10*p1, 10*(1-p1));
> }
>
> for(j in 1:J){
> a[j] ~ binomial(n[j], ptilde[j]);
> }
>
> }
>
> In the output, I got the error:
>
> The following numerical problems occured the indicated number of times on chain 1
> count
> Exception thrown at line 24: lognormal_log: Scale parameter is inf, but must be finite! 1
> 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.
>
> Thanks!
>
>
> --
> 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.
> <post_11.04.2015.stan><post.11.04.2015.R>