Ah, looks like that was the wrong way to non-center the lognormal, according to this post from Bob.
Try with the following model:
data{
int<lower=0> Ntotal;
int<lower=0> K;
vector[Ntotal] y;
int s[K];
}
parameters {
real<lower=-10,upper=10> mutheta;
real<lower=-10,upper=10> musigma;
real<lower=0,upper=10> tausigma;
real<lower=0,upper=50> tautheta;
vector<offset=mutheta,multiplier=tautheta>[K] theta;
vector[K] sigma2_raw;
}
transformed parameters {
vector[K] sigma2_jacob = musigma + sigma2_raw * tausigma;
vector<lower=0>[K] sigma2 = exp(sigma2_jacob);
}
model {
int pos;
pos = 1;
sigma2_raw ~ std_normal();
for (k in 1:K) {
segment(y, pos,s[k]) ~ normal(theta[k],sqrt(sigma2[k]));
pos = pos + s[k];
theta[k] ~ normal(mutheta, tautheta) ;
}
mutheta ~ uniform(-10,10);
musigma ~ uniform(-10,10);
tausigma ~ uniform(0,10);
tautheta ~ uniform (0,50);
target += sum(sigma2_jacob);
}
generated quantities {
real<lower=0,upper=1> Ppop ;
real<lower=0,upper=1> Ppopdiff;
real<lower=0> meanvar;
Ppop = mutheta>0;
Ppopdiff = mutheta>0.5;
meanvar = exp(-musigma+tausigma/2);
}