> vector[128] ONES[337]; // an array of vectors filled with 1's (for relating model predictions to the "virtual data" = all successes)
You should declare just a single vector[128] in transformed data,
fill it with ones using rep_vector(0,128), and then re-use it.
Why are you only setting a[1] and then using a[t]? This will be a bug
because a[t] will be undefined for t > 1.
If you want each to be 1/3, then again, just declare a transformed
data variable and reuse it.
Again, Stan is not R. Evaluating 1/3 yields 0. Stan uses C++-style
arithmetic. You need to use 1/3.0 or 1.0/3 or 1.0/3.0. See the
manual for a discussion. If you do it as above, the compiler will
give you a warning about trying to use division on integers.
>
> for ( t in 1:nTrials) {
> prob[t] <- dot_product(m[t],a[t]^d[sub]) / ( sum(a[t]^d[sub]) + machine_precision() ); // m = data, a = internal variable, d = model parameter
If you're going to use m[t], then just declare M
as a two-dimensional array of vectors and use
M[s,t] in this expression. There is no copying involved
in just accessing an array.
I have no idea what you're trying to do by adding machine_precision to this.
> ones[t] ~ bernoulli(prob[t]);
Again, you don't need to assign prob[t] to a local variable. You can just
drop the expression inside as an argument.
Again, Stan is not R. Stan variables are typed. And bernoulli
requires integer arguments, not real arguments. I think what you
really want to do is this:
1 ~ bernoulli(prob[t]);
But it's probably better if you just vectorize and use
1 ~ bernoulli(prob);
> 2. Would the declaration in the data block work, if a re-ordered by data in R to be M[nSubjects,nTrials,3] and FB[nSubjects,nTrials]?
As long as everything evaluates to the right type.
> 3. Do I have to pay attention to the vector orientation (row,column) in the dot_product(m[t],a[t]^d[sub]) expression?
No, but you might be able to simplify and speed things up by using
matrix arithmetic rather than repeated vector arithmetic and then
using a vectorized form of Bernoulli.
Cheers,
Jan