stan-dev / rstan

RStan, the R interface to Stan
https://mc-stan.org
1.04k stars 269 forks source link

Modeling inter-occasion variabile #908

Open ghost opened 3 years ago

ghost commented 3 years ago

Hello, I am working on modeling meta-analysis data that have studies that is considered as individuals and response collected one a few time points. Also each study has two arms 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:

//doseResponseMBMA1 data{ int nStudies; int nArms; int study[nArms]; real dose[nArms]; vector[nArms] n; vector[nArms] response; }

transformed data{ vector[nArms] logResponse;

logResponse = log(response); }

parameters{ real e0Hat; real emaxHat; real ed50; real sigma; real omegaE0; real omegaEmax;

vector[nStudies] e0;// arrays works too vector[nStudies] emax; // arrays works too } transformed parameters{ vector[nArms] responseHat;

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

}

model{
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[nStudies] e0Pred; vector[nStudies] emaxPred; real responseCond[nArms]; real responseHatPred[nArms]; real 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

jeffreypullin commented 3 years ago

Hi @melagha I think you might have more success posting this sort of question on the stan forums here: https://discourse.mc-stan.org/.

All the best!

ghost commented 3 years ago

Thank you for the advice, I will dose that. Regards.