I would check that
a) the model's converging properly,
b) you're using the same parameterization of gamma (or should
that be inverse gamma?), and
c) whatever you're checking against is giving you the posterior
mean, not the posterior mode.
Could you include the Wikipedia reference?
Also, it's more efficient to use the sampling statements where
possible, replacing
> increment_log_prob( gamma_log(lambda,alpha,beta)
> + normal_log(x,mu,sigma)
> );
with
lambda ~ gamma(alpha,beta);
x ~ normal(mu,sigma);
The reason is that the sampling statement versions drop all
the unnecessary normalizing constants. Of course, if you need
those, then you need to use the increment_log_prob form.
Also, it's probably easier to break the increments apart,
as
increment_log_prob(gamma_log(lambda,alpha,beta));
increment_log_prob(normal_log(x,mu,sigma));
It's also a bit more efficient because increment_log_prob
uses an accumulator whereas the addition operator adds a new
node to the expression tree for auto-diff.
- Bob
On Mar 13, 2014, at 3:29 AM,
shota...@gmail.com wrote:
> Hi all,
>
> I have a trouble with bivariate normal-gamma distribution in stan.
>
> I wrote a simple code to sample random numbers based on bivariate normla-gamma distribution for my applications.
>
> The following is my stan code and compiled in Ubuntu 13.10.
>
> transformed data
> {
> real mu;
> real<lower=0> kappa;
> real<lower=1> alpha;
> real<lower=0> beta;
> mu <- -4.3;
> kappa <- 3.1;
> alpha <- 1.1;
> beta <- 0.5;
> }
> parameters
> {
> real<lower=0> lambda;
> real x;
> }
> transformed parameters
> {
> real<lower=0> sigma;
> sigma <- sqrt(lambda*kappa);
> }
> model
> {
> // Normal-Gamma distribution
> increment_log_prob( gamma_log(lambda,alpha,beta)
> + normal_log(x,mu,sigma)
> );
> }
>
> I ran the executable with
>
> ./normal-gamma.exe sample thin=10 num_warmup=1000000 num_samples=10000000
>
> and I got a slightly off value which is
>
> lambda = 2.251 with MCSE 2.323e-3
>
> which is supposed to be 2.200 according to wikipedia.
>
> Could anyone point me what is wrong with my code? Thank you for your help and kindness.
>
> Note: My notation is based on this paper.
>
> --
> 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.
> For more options, visit
https://groups.google.com/d/optout.
> <normal-gamma.stan>