Hi all,
The following stan code, is working. However, when I call it from R, I get the following error regarding to the parameters pAB, uAB, and uASC that are found in the transformed parameters:
[2] " Exception: multiply: Columns of rv (1) and Rows of v (60) must match in size (in ‘string’, line 33, column 2 to column 18)"
[1] “error occurred during calling the sampler; sampling not done”
pAB0, needs to have only one value, hence [1], and rpAB needs to have the dimension of each individual. I based this multiplication on: 4.1 Reductions | Stan Functions Reference
There, I can define a real that can multiply a row_vector and a vector[]. However, a row_vector alone does not work and I need to specify a dimension. Any idea why this error?
functions {
vector model3(real t, vector y, real pAB, real uAB, real uASC) {
vector[2] dydt;
dydt[1] = pAB*y[2]-uAB*y[1];
dydt[2] = -uASC*y[2];
return dydt;
}
}
data {
int <lower=1> nobs;
real t0;
vector[2] y0;
array[nobs] real ts;
int <lower=1> indivs;
array[nobs] real antib;
//real <lower=1, upper=indivs> subj[nobs];
}
parameters {
row_vector[1] pAB0;
row_vector[1] uAB0;
row_vector[1] uASC0;
real <lower=0> sigma;
real <lower=0> sigmapAB;
real <lower=0> sigmauAB;
real <lower=0> sigmauASC;
vector[indivs] rpAB;
vector[indivs] ruAB;
vector[indivs] ruASC;
}
transformed parameters {
real pAB;
pAB = pAB0*rpAB;
real uAB;
uAB = uAB0*ruAB;
real uASC;
uASC = uASC0*ruASC;
array[nobs] vector[2] yhat = ode_bdf(model3, y0, t0, ts, pAB, uAB, uASC);
}
model {
rpAB ~ lognormal(-2, sigmapAB);
ruAB ~ lognormal(-1, sigmauAB);
ruASC ~ lognormal(-0.1, sigmauASC);
sigmapAB ~ gamma(0.001, 0.001);
sigmauAB ~ gamma(0.001, 0.001);
sigmauASC ~ gamma(0.001, 0.001);
sigma ~ normal(0, 1);
//for (i in 1:nobs) {
//antib[i] ~ lognormal(yhat[i,1], sigma);
//}
antib ~ lognormal(log(yhat[ : , 2]), sigma);
}
generated quantities {
array[nobs] real z_pred;
for (j in 1:nobs) {
z_pred[j] = lognormal_rng(log(yhat[j,2]), sigma);
}
}