Thanks a lot, this solution worked for me. Exactly what I needed! Here are the updated blocks:
data {
// cycles
int<lower = 1> nCycles; // number of cycles
}
parameters {
// clearance
real ETA_CL; // ind. iiv estimate
vector[nCycles] KAPPA_CL; // ind. iov estimates (vectorized)
// intercompartmental clearance q3
real ETA_Q3; // ind. iiv q3 estimates
vector[nCycles] KAPPA_Q3; // ind. iov q3 estimates (vectorized)
}
transformed parameters {
array[nEvents, nTheta] real theta;
for (i in 1:nEvents) {
// store thetas
theta[i, 1] = TVCL * pow(EGFR[i] / 84, TH_EGFR_CL) * exp(ETA_CL + KAPPA_CL[ CYCLE[i] ]);
theta[i, 2] = TVV1;
theta[i, 3] = TVQ2;
theta[i, 4] = TVV2;
theta[i, 5] = TVQ3 * exp(ETA_Q3 + KAPPA_Q3[ CYCLE[i] ]);
theta[i, 6] = TVV3;
}
}
model {
// informative priors for clearance
ETA_CL ~ normal(0, IIV_SD_CL); // IIV (sd) on central clearance
KAPPA_CL ~ normal(0, IOV_SD_CL); // IIV (sd) on central clearance (vectorized)
// informative priors for intercompartmental clearance Q3
ETA_Q3 ~ normal(0, IIV_SD_Q3); // IOV (sd) on intercompartimental clearance Q3
KAPPA_Q3 ~ normal(0, IOV_SD_Q3); // IIV (sd) on intercompartimental clearance Q3 (vectorized)
// likelihood function for exponential error model (expects SD for normal distribution)
logCObs ~ normal(log_cHatObs, EXP_RUV_SD);
}
It is good to know that this vectorized approach works, makes my life much easier!
Thanks a lot for the additional explanations, makes all sense now!