Hi all,
After running a very simple model (exponential decay ODE), including two random effects for the initial value of AB and the decay rate, I am experiencing that the model runs extremely slow. (Gradient evaluation took 0.063 seconds).
I am specifying the initial values as:
rAB0 = rep(0, participants)
rmuab = rep(0, participants)
r = cbind(rAB0, rmuab)
initebl = function(){
list(muab = -0.02,
logAB0 = 5, logsigmaAB0 = 0.5, logsigmamuab = 0.5,
rho_rhobit = 0.5, sigma = 1, r = r)
}
Any idea why could that be?
functions {
real[] edecay(real t, real[] y, real[] theta, real[] x_r, int[] x_i) {
real dydt[1];
dydt[1] = -theta[1]*y[1];
return dydt;
}
}
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 {
real x_r[0];
int x_i[0];
}
parameters {
real muab;
real logAB0;
real <lower=0> logsigmaAB0;
real <lower=0> logsigmamuab;
real <lower= 0> sigma;
real rho_rhobit;
vector[2] r[nsubjects];
}
model {
real new_mu[N,1];
real mu[1,1];
real eval_time[1];
real theta[1];
vector[nsubjects] rAB0;
vector[nsubjects] rmuab;
real inits[1];
real AB0 = exp(logAB0);
real sigmaAB0 = exp(logsigmaAB0);
real sigmamuab = exp(logsigmamuab);
vector[2] mean_vec;
matrix[2,2] Sigma;
real rho = (exp(rho_rhobit) - 1)/(exp(rho_rhobit) + 1);
//prior distributions
muab ~ normal(0, 10);
logAB0 ~ normal(5, 10);
sigma ~ normal(1, 10);
logsigmaAB0 ~ cauchy(0, 1);
logsigmamuab ~ cauchy(0, 1);
rho_rhobit ~ uniform(-10,10);
mean_vec[1] = -pow(sigmaAB0, 2.0)/2;
mean_vec[2] = -pow(sigmamuab, 2.0)/2;
Sigma[1,1] = pow(sigmaAB0, 2.0);
Sigma[2,2] = pow(sigmamuab, 2.0);
Sigma[1,2] = rho*sigmaAB0*sigmamuab;
Sigma[2,1] = rho*sigmaAB0*sigmamuab;
for (subj_id in 1:nsubjects) {
r[subj_id] ~ multi_normal(mean_vec, Sigma);
rAB0[subj_id] = r[subj_id,1];
rmuab[subj_id] = r[subj_id,2];
}
for (obs_id in 1:N){
inits[1] = AB0*exp(rAB0[subj_ids[obs_id]]);
theta[1] = muab*exp(rmuab[subj_ids[obs_id]]);
eval_time[1] = ts[obs_id];
if (eval_time[1] == 0){
new_mu[obs_id,1] = log(inits[1]) - pow(sigma, 2.0)/2;
}
else{
mu = integrate_ode_rk45(edecay, inits, t0, eval_time, theta, x_r, x_i);
new_mu[obs_id,1] = log(mu[1,1]) - pow(sigma, 2.0)/2;
}
//likelihood function for AB levels
y[obs_id] ~ lognormal(new_mu[obs_id,1], sigma);
}
}
generated quantities {
real z_pred[N];
real sigma2 = sigma;
for (t in 1:N){
z_pred[t] = lognormal_rng(log(y[t] + 1e-5), sigma2);
}
}