I tried to run my model with parallelization but without success. Clarification: the stan code I am using was generated using the rethinking package.
When I change a bit the functions segment so that corr_matrix[]
becomes just matrix[],
still I don’t know what to do with the rest of the code to avoid semantic errors (sorry, I am new at this):
functions{
real reducer(
vector mx,
int start , int end ,
int N,
vector mx_sd,
int[] time_period,
int[] period,
int[] time,
int[] county,
vector b_time_period_county,
vector b_period_county,
vector b_time_county,
vector a_county,
real b_time_period,
real b_period,
real b_time,
real a,
real sigma,
vector sigma_county,
# corr_matrix[] Rho) {
matrix[] Rho) {
vector[size(mx)] mu;
for ( i in 1:size(mx) ) {
mu[i] = a_county[county[start+i-1]] + b_time_county[county[start+i-1]] * time[start+i-1] + b_period_county[county[start+i-1]] * period[start+i-1] + b_time_period_county[county[start+i-1]] * time_period[start+i-1];
}
return normal_lpdf( mx | mu , sigma );
}
}
Semantic error in '/tmp/RtmphvQFFv/model-387cb4564bdf94.stan', line 66, column 14 to line 83, column 17:
-------------------------------------------------
64: YY ~ multi_normal( MU , quad_form_diag(Rho , sigma_county) );
65: }
66: target += reduce_sum( reducer , mx , 1 ,
^
67: N,
68: mx_sd,
-------------------------------------------------
Ill-typed arguments supplied to function 'reduce_sum':
(<F1>, vector, int, int, vector, array[] int, array[] int, array[] int,
array[] int, vector, vector, vector, vector, real, real, real, real, real,
vector, matrix)
where F1 = (vector, int, int, int, vector, array[] int, array[] int,
array[] int, array[] int, vector, vector, vector, vector, real,
real, real, real, real, vector, array[] matrix) => real
Available signatures:
(<F2>, array[] real, int) => real
where F2 = (array[] real, data int, data int) => real
The first argument must be
(array[] real, data int, data int) => real
but got
(vector, int, int, int, vector, array[] int, array[] int, array[] int,
array[] int, vector, vector, vector, vector, real, real, real, real,
real, vector, array[] matrix) => real
These are not compatible because:
The types for the first argument are incompatible: one is
vector
but the other is
array[] real
make: *** [make/program:50: /tmp/RtmphvQFFv/model-387cb4564bdf94.hpp] Error 1
Error: An error occurred during compilation! See the message above for more information.
I have been looking for examples using correlation matrices without success. Any suggestion or guidance will be welcome. Thank you again!
Here the data: example.csv (773.9 KB)