After trying several times, I found that when passing array of matrix from R to Stan, the dimensions mismatch.
For example, in R, I construct a one-dimensional array of size 1 containing a value that is a 2\times 2 matrix. The R code is as the following:
I <- 2
J<-2
T <- 1
X <- array(c(1,2,3,4),dim=c(I,J,T))
fit = stan('test_pass_matrix.stan',data=list(X=X,I=I,J=J,T=T))
In the Stan, I declare an array of the same size containing a Matrix with the same dimension as the that in the R code, as the following:
data {
int<lower=1> I;
int<lower=2> J;
int<lower=1> T;
matrix[J,I] X[T];
}
After running the R code, an error of dimension mismatch appears, as the following: **Error in mod$fit_ptr() :
Exception: mismatch in dimension declared and found in context; processing stage=data initialization; variable name=X; position=0; dims declared=(1,2,2); dims found=(2,2,1) (in ‘modela515adfc8a6_test_pass_matrix’ at line 21)
failed to create the sampler; sampling not done**
The dimension of the array containing matrix is (2,2,1) in R, which should be the same as the dimension (1,2,2) of the array containing matrix declared in Stan. Also, the first index of an array declared in Stan is the last index of the array declared in R. But when passing the data from R to Stan, it seems that the Stan code regards this difference in syntax of dimension between R and Stan as an error in dimension mismatch.
Is there any expert or developer of Stan who can help confirm whether this is an issue? Alternatively, is there any solution to this error of dimension mismatch?