Inter-occasion variability

I am working on modeling meta-analysis data that have studies that is considered as individuals and response collected on a few time points. Also each study has two arms (treatment and placebo) which will be defined as an occasion and estimate IOV.
My question is how to add IOV to the model. I am using the Metrum institute as template as shown below:

int<lower = 1> nStudies;
int<lower = 1> nArms;
int<lower = 1> study[nArms];
real<lower = 0> dose[nArms];
vector<lower = 1>[nArms] n;
vector<lower = 0>[nArms] response;

transformed data{
vector[nArms] logResponse;

logResponse = log(response);

real<lower = 0> e0Hat;
real<lower = 0> emaxHat;
real<lower = 0> ed50;
real<lower = 0> sigma;
real<lower = 0> omegaE0;
real<lower = 0> omegaEmax;

vector<lower = 0>[nStudies] e0;// arrays works too
vector<lower = 0>[nStudies] emax; // arrays works too
transformed parameters{
vector<lower = 0>[nArms] responseHat;

for(i in 1:nArms){
responseHat[i] = e0[study[i]] + emax[study[i]] * dose[i] / (ed50 + dose[i]);


e0Hat ~ normal(0, 10);
emaxHat ~ normal(0, 50);
ed50 ~ normal(0, 50);
sigma ~ cauchy(0, 2);
omegaE0 ~ cauchy(0, 2);
omegaEmax ~ cauchy(0, 2);

e0 ~ lognormal(log(e0Hat), omegaE0);
emax ~ lognormal(log(emaxHat), omegaEmax);

logResponse ~ normal(log(responseHat), sigma ./ exp(log(n) / 2));

generated quantities{
vector<lower = 0>[nStudies] e0Pred;
vector<lower = 0>[nStudies] emaxPred;
real<lower = 0> responseCond[nArms];
real<lower = 0> responseHatPred[nArms];
real<lower = 0> responsePred[nArms];

Individual predictions

for(i in 1:nArms){
responseCond[i] = exp(normal_rng(log(responseHat[i]), sigma / sqrt(n[i])));

Population predictions

for(i in 1:nStudies){
e0Pred[i] = lognormal_rng(log(e0Hat), omegaE0);// generate new e0
emaxPred[i] = lognormal_rng(log(emaxHat), omegaEmax);// generate new emax
for(i in 1:nArms){
responseHatPred[i] = e0Pred[study[i]] + emaxPred[study[i]] * dose[i] / (ed50 + dose[i]);
responsePred[i] = exp(normal_rng(log(responseHatPred[i]), sigma / sqrt(n[i])));


Best regards

Hi, welcome to the community! Whenever a post isn’t answered it’s mostly because people don’t have the time or there are some things lacking to the post. Let’s try to increase the probability of someone answering you by me replying to this post which means your post will be moved up and become visible again. Next,

  1. create a minimal working example (with fake data) so people can run the code with data,
  2. please use three backticks (```) at the start and end of code (block code formatting). It might make it easier to read and the probability of someone reading the code could increase :),
  3. put all stan code in code block so it’s not chopped up, and
  4. by writing stan immediately after the first three backticks ```stan I think it will even highlight the code for you.

Best of luck with your model!

1 Like