Dear All,
I am a new user of STAN (today), and can confirm the new user material, online examples and R code provided are excellent, and have allowed me to fit and assess models on day 1.
I have a query, and my apologies if this message is poorly structured or overly naive.
I wish to fit complex non-linear mixed effect meta-analysis type models that I current fit using SAS PROC MCMC. In the toy example code below, I am looking to fit a very simple model, where we read in a “drugnum” variable (as integer) in the Data Block, which is either 0 or 1 in the dataset (representing the drug treatment (yes/no). In the Model Block, we then use an IF statement to define the model (“mymod”) differently depending on this variable. This works (great!), however I would need to read in a different variable, say “DrugName” which contains “Placebo”, “Drug 1”, “Drug 2” etc., and then have code in the Model Block such as:
if (DrugName[n] == “Placebo”) mymod = myint ;
if (DrugName[n] == “Drug 1”) mymod = myint + drugeff ;
Is it possible to read in character strings like this in the Data Block, and use them in the Model Block?
I appreciate this may be slow computation wise, but I have over 40 drugs, and many parts to the “mymod” computation, and hence trying to do this with (integer) flag variables for each drug would not be feasible.
I hope this is sufficiently clear and concise, and look forward to any suggestions.
Best wishes
Al
data {
int N;
real y[N];
real myse[N];
int drugnum[N];
}
model {
real mymod;
myint ~ normal(0, 100);
drugeff ~ normal(0, 100);
for (n in 1:N) {
if (drugnum[n] == 0) mymod = baseline[n] + myint ;
if (drugnum[n] == 1) mymod = baseline[n] + myint + drugeff ;
y[n] ~ normal( mymod, myse[n]);
}
Data looks like:
y, myse, drugnum, drugname
8, 1, 0, “Placebo”
9, 1, 1, “Drug 1”
etc.