Is there a useful non-centered parameterisation of the gamma distribution that can be used in this case, rather than assuming that the stdev variables have a normal hierarchical prior?
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.
Code is below for both the R version which calls it, and the Stan code.
I think that these two examples should give the same answer for hp, but they vary slightly. Why is this? Have I implicitly assumed slightly different priors here?
Results from 15 million iterations below. Note that hp and hp_alt (the two different versions of this) differ very slightly, and more than can reasonably be explained by sampling variation.
(sig1 is similar to sig1_alt, and sig2 is similar to sig2_alt, as expected).
mean se_mean sd 2.5% 25% 50% 75% 97.5% n_eff Rhat hp 2.633 0.001 2.608 0.706 1.337 1.974 3.061 8.501 3131450 1 hp_alt 2.618 0.002 2.648 0.698 1.329 1.963 3.046 8.447 1613607 1 sig1 3.398 0.000 0.820 2.232 2.828 3.257 3.805 5.392 4184178 1 sig2 1.933 0.000 0.489 1.246 1.593 1.846 2.172 3.128 4206156 1 c1_alt 1.897 0.001 1.097 0.400 1.097 1.687 2.468 4.587 2640897 1 c2_alt 1.091 0.000 0.663 0.219 0.612 0.955 1.420 2.746 2686321 1 sig1_alt 3.397 0.000 0.827 2.218 2.818 3.255 3.814 5.400 7500000 1 sig2_alt 1.933 0.000 0.494 1.239 1.588 1.845 2.177 3.135 7500000 1 lp__ -58.512 0.001 1.726 -62.730 -59.425 -58.185 -57.245 -56.152 2659432 1
---
Stan code:
data{
int n;
vector[n] dat1;
vector[n] dat2;
}
parameters{
real<lower=0> hp;
real<lower=0> hp_alt;
real<lower=0> sig1;
real<lower=0> sig2;
real<lower=0> c1_alt;
real<lower=0> c2_alt;
}
transformed parameters{
real sig1_alt;
real sig2_alt;
sig1_alt = c1_alt*hp_alt;
sig2_alt = c2_alt*hp_alt;
}
model{
// Standard version
dat1 ~ normal(0, sig1);
dat2 ~ normal(0, sig2);
sig1 ~ gamma(2,1/hp);
sig2 ~ gamma(2,1/hp);
// Alternate version
dat1 ~ normal(0, sig1_alt);
dat2 ~ normal(0, sig2_alt);
c1_alt ~ gamma(2, 1);
c2_alt ~ gamma(2, 1);
}
library(rstan)
set.seed(12345)
rstan_options(auto_write = TRUE)
n <- 10
modegen_1 <- 4
modegen_2 <- 2
gendat_1 <- rnorm(n, 0, modegen_1)
gendat_1
gendat_2 <- rnorm(n, 0, modegen_2)
DatForStan <- list(n=n, dat1=gendat_1, dat2=gendat_2)
niter <- 15000000
#StanFit <- stan(file = 'Survival_model_STAN_v06.stan', data=DatForStan, iter=niter, chains=1, refresh=20, control=list(adapt_delta=0.9))
StanModel <- stan_model(file = 'NCP gamma STAN v01.Stan')
StanFit <- sampling(StanModel, data=DatForStan, iter=niter, chains=1, refresh=1000)
print(StanFit,digits=3)