I get this strange error when trying to compile the code. I haven’t yet seen such an error where it asks for generated quantities block with regard to the line where model block starts
Huh. Very strange. Because that message is saying it thought it reached the end of the model block (by seeing a } to match the block’s opening {), and then encountered text that was not the only valid text allowed after the end of the model block (generated quantities {).
That’s because partial_sum expects rbeta as a matrix but you pass rbeta as as an array of vectors. Maybe that’s the whole problem? The error message you’re seeing certainly isn’t a helpful one. Maybe a later version of rstan or cmdstan would fix that?
Wait, if you were able to compile this without turning on multithreading it strongly suggests to me that the Stan program that you included above is not identical to the one you’re actually using. No way should this one compile with or without multithreading, due to the mis-typed argument in partial_sum
Interestingly, I was able to reproduce your original error with rstan 2.26. Updating to 2.27 eliminated the issue. I cannot be certain whether the issue was a bug in 2.26 or whether it was a problem with my rstan installation that was fixed by re-installing.
So either there is a bug in earlier versions that is fixed in 2.27 or there’s a problem (apparently a common one) with your rstan installation. In either case, updating to the latest Stan seems to be a fix. To update to the latest rstan, do
I have no issues compiling your model copy-pasted from your discourse post. I don’t have access to your data, so I cannot attempt to sample the compiled model. In a very cursory glance at the images of the output from the compiler that you posted above I didn’t see an error message, so maybe compiling is working fine on your end as well.
So after some experimenting, I have realised the problem is to do with random effects.
Since I was able to compile and sample from the model with all effects being fixed but when I introduced even a single random effect like only random intercept I got errors like before :
Edit, if I replace $bought with $y I can run and reproduce your error
Edit 2: Nevermind, I still can’t reproduce. I error because y, L, and ll are all the wrong size in the data. If I replace the associated [1:500]s with [1:1000]s, I progress to a new set of errors that still aren’t your error. These new errors are probably related to the fact that in your partial_sum function, you are indexing into rbeta, a matrix, using a single index instead of two indices.
My sense here, and this is consistent with all of the various error messages that you’ve reported, is that your problems all have to do with your indexing. I suggest you try to go over the indexing with a fine-toothed comb using synthetic, shareable data. If you can’t get it working, then if you could re-post exactly the data file, stan file, and and R script that reproduces the error, with no changes from the version that you are running in order to see the error, then we can take a look and try to troubleshoot the issue.