My question is not how these values are fit by STAN, but only about how STAN knows that b1 is the patient level residual and b the patient by visit residual. My guess is that this is because b1 is declared OUTSIDE of the do-loop, so that it sees that it has N levels, whereas b is declared INSIDE of the do-loop, so that it sees that, at each level of N, there are four (visit) levels. I think that this is corroborated by the fact that at each draw, STAN draws N sample values for b1, but N * 4 values for b.
...
real b1[N];
vector[T] b[N];
...
Based on yesterday's discussion, I thought that I understood that the prior for b: "b[n] ~ normal(0, sigma_b);" could be put pretty much anywhere, since the shape of b had been set by its earlier declaration in the parameters section.
for(n in 1:N) {
b[n] ~ normal(0, sigma_b);
...
There are some ways that this could be improved upon:
and add (outside the for loop) the line to_array_1d(b) ~ normal(0, sigma_b);. This concatenates all the elements of b into a one-dimensional array and asserts the prior is iid normal with mean 0 and standard deviation sigma_b. and the line that says b1 ~ normal(0, sigma_b1); Add (outside the for loop) the line to_array_1d(b) ~ normal(0, 1); and the line b1 ~ normal(0,1). Finally, change the last line of the likelihood to say + b1[n] * sigma_b1 + alpha_V4 * V4_c + b[n] * sigma_b); . This basically redefines b[n] and b1 to be standard normal shifts that are scaled by the unknowns sigma_b and sigma_b1 respectively, which often improves the efficiency of the sampling by reducing the dependence between these unknown parameters.You can always print things to the screen if you are having trouble understanding the structure:
print("b is");
for(n in 1:N) print(b[n]);
Ben
And yes. I discovered this, too. I had to kill my R instance to stop the torrent of red. I'll try your suggestion above.
I think that that is, finally, the end of this thread. Many, many thanks.
Larry Hunsicker