Hi everyone,
I have been running the following code, under the following initial values. I achieve convergence in all the values, except for the log posterior, AB0, and omega[2]. These do not go really even beyond Rhat of 1.5, but I can see in the traceplots that they do not converge. Any ideas on how to fix this?
Thanks.
initebl = function(){
nsubjects ← length(unique(newebl$SUBJID))
pop_var = c(0.5, 0.5)
mua_pop = rnorm(1, 0, pop_var[1])
AB0_pop = exp(rnorm(1, log(37), pop_var[2]))
omega ← abs(rnorm(2, 0, pop_var))
theta_pop ← c(mua_pop, AB0_pop)
theta ← matrix(NA, nsubjects, length(theta_pop))
for (i in 1:nsubjects){
theta[i, ] = rlnorm(length(theta_pop), log(theta_pop), omega)
}
list(mua_pop = mua_pop, AB0_pop = AB0_pop, realsigmaA = abs(rnorm(1, 0, 1)),
sigma = abs(rnorm(1, 0, 1)), omega = omega, theta = theta)
}
functions{
real[] numerical_int(real t0, real ts, real[] theta){
real dt = ts - t0;
real y[1];
y[1] = theta[2]*exp(-theta[1]*dt);
return y;
}
}
data{
int <lower=1> N;
int <lower=1> nsubjects;
int <lower=1> subj_ids[N];
real <lower=0> y[N];
real ts[N];
real t0;
}
transformed data{
int nTheta = 2;
int niv = 2;
//prior sd
real prior_sd[niv] = {0.5, 0.5};
}
parameters{
//population parameters
real <lower=0> mua_pop;
real <lower=0> AB0_pop;
//residual error
real <lower=0> realsigmaA;
real <lower=0> sigma;
//inter-individual variability
vector <lower=0>[niv] omega;
real <lower=0> theta[nsubjects, nTheta];
}
transformed parameters{
vector <lower=0>[nTheta] theta_pop = to_vector({mua_pop, AB0_pop});
real mu[N, 1];
//vector [new_mu];
//individual parameters
vector <lower=0> [nsubjects] mua = to_vector(theta[, 1]);
vector <lower=0> [nsubjects] AB0 = to_vector(theta[, 2]);
for (j in 1:N){
mu[j, ] = numerical_int(t0, ts[j], {mua[subj_ids[j]], AB0[subj_ids[j]]});
}
}
model{
//priors
mua_pop ~ normal(0, prior_sd[1]);
AB0_pop ~ lognormal(log(37), prior_sd[2]);
realsigmaA ~ normal(0, 1);
sigma ~ normal(0, realsigmaA);
omega ~ normal(0, 1);
// interindividual variability
for (j in 1:nsubjects){
theta[j, ] ~ lognormal(log(theta_pop), omega);
}
// likelihood
y ~ lognormal(log(mu[N, 1]), sigma);
}
generated quantities {
real pred_antibody[N];
for (i in 1:N) {
pred_antibody[i] = exp(normal_rng(log(y[i]), sigma));
}
}