I am running advi on a simple mixed effects model where random effects are lognormally distributed as in
model <- 'data {
int<lower=0> N;// Number of observations
vector[N] time; //predictor
vector[N] concentration; //response
real beta1_pop;
real beta2_pop;
real beta3_pop;
real<lower=0> omega_beta1;
real<lower=0> omega_beta2;
real<lower=0> omega_beta3;
real<lower=0> pres;
}
parameters {
vector[3] beta;
}
model {
//Priors
beta[1] ~ lognormal( beta1_pop , omega_beta1);
beta[2] ~ lognormal( beta2_pop , omega_beta2);
beta[3] ~ lognormal( beta3_pop , omega_beta3);
concentration ~ normal(100*beta[1]/(beta[2]*(beta[1]-beta[3]))*(exp(-beta[3]*time)-exp(-beta[1]*time)), pres);
}'
modelstan <- stan_model(model_name = "warfarin",model_code = model)
and then running advi
stan_data <- list(N = length(obs),concentration = obs
,time = time,
beta1_pop=beta1,beta2_pop=beta2,beta3_pop=beta3,
omega_beta1=omega.eta1,omega_beta2=omega.eta1,omega_beta3=omega.eta3,
pres=pres)
fit <- vb(modelstan, data = stan_data, iter = 10000)
beta1, beta2 ad beta3 are positive, yet running vb method returns
Rejecting initial value:
Error evaluating the log probability at the initial value.
Exception: lognormal_lpdf: Random variable is -0.214347, but must be >= 0! (in ‘model14f6567ff8b9_warfarin’ at line 19)
Rejecting initial value:
Error evaluating the log probability at the initial value.
Exception: lognormal_lpdf: Random variable is -1.97402, but must be >= 0! (in ‘model14f6567ff8b9_warfarin’ at line 19)
Rejecting initial value:
Error evaluating the log probability at the initial value.
Exception: lognormal_lpdf: Random variable is -0.498263, but must be >= 0! (in ‘model14f6567ff8b9_warfarin’ at line 19)
Any thoughts? Is the model not defined correctly?
Thanks