On June 13, 2013 09:15:18 PM EDT,
kris2...@gmail.com wrote:
> Thanks for picking up that silly error on my part. However, when I added
> the same distribution I had in Jags (i.e., r[i] ~ gamma(theta,theta)) ,
>
>
> test_code <- '
> data {
> int<lower=0> n; //number of sites
> real gradient[n]; //gradient value at each site
> int<lower=0> taxon_ct[n]; //count of taxon at each site
> }
> parameters {
> real beta1;
> real beta0;
> real<lower=0> theta;
> real<lower=0> h;
> real<lower=0> r[n];
> }
> transformed parameters{
> real<lower=0> mustar[n];
> for (i in 1:n) {
> mustar[i] <- r[i]*exp(beta0 + beta1*gradient[i]);
> }
> }
> model {
> for (i in 1:n){
> r[i] ~ gamma(theta,theta);
> taxon_ct[i] ~ poisson(mustar[i]);
I'd suggest here using poisson_log, with
transformed parameters {
...
for (i in 1:n)
mustar[i] <- log(r[i]) + beta0 + beta1*gradient[i];
...
model {
for (i in 1:n)
taxon_ct[i] ~ poisson_log(mustar[i]);
If you don't want mustar[i] written out, you can do this all
inside poisson_log, using:
for (i in 1:n)
taxon_ct[i] ~ poisson_log(log(r[i]) + beta0 + beta1 * gradient[i]);
In fact, you can go one step further in efficiency and use
vectorization,
taxon_ct ~ poisson_log(log(r) + beta0 + beta1 * gradient);
but to do that, you need to define the relevant real arrays as vectors
instead, e.g.,
vector[n] gradient;
vector[n] r;
> }
> beta0 ~ normal(0,sqrt(1000));
> beta1 ~ normal(0,sqrt(1000));
> theta ~ gamma(0.01,h);
> h ~ gamma(0.01,0.01);
> }
> '
> I began getting this (which can be ignored?)
>
> Informational Message: The parameter state is about to be Metropolis
> rejected due to the following underlying, non-fatal (really) issue
> (and please ignore that what comes next might say 'error'): Error in
> function stan::prob::gamma_log(N4stan5agrad3varE): Inverse scale
> parameter is 0:0, but must be > 0!
> If the problem persists across multiple draws, you might have a
> problem with an initial state or a gradient somewhere.
> If the problem does not persist, the resulting samples will still be
> drawn from the posterior.
Yes, these can be ignored as long as they don't persist.
It's an HMC proposal that because of the discretization of
the Hamiltonian we need for computation runs outside of the
support of some constrained variables.
It can also be a sign of a problem with the model if you don't
want these parameters near 0.
> I'm still also having issues with convergence:
>
> n_eff Rhat
> beta1 2 1.746000e+03
> beta0 2 2.060000e+01
> theta 16 1.100000e+00
> h 2 2.200000e+01
>
>
> Thanks for any help you can provide.
I think there may be an identifiabilty problem
with the
log(r[i]) + beta0
term because both r[i] and beta0 are parameters, so
there seems to be additive non-identifiability.
- Bob