Hi all,

Thanks a lot for the nice tool. I need some feedback in regard to inserting 3d MRI data into Stan. See my model below :

The error that I receive is always for all 4 output csv files:

output-4.csv: Exception: variable does not exist; processing stage=data initialization; variable name=yy; base type=double (in ‘/Users/Documents/MATLAB/pat_test_one.stan’, line 5, column 0 to column 22)

The array that I try to insert is of dimensions: 268, 16, 6 as shown below… (268 voxels, 16 b values and 6 directions)

Is there something with my array[N,16,6] real yy

wrong, why the above error message shows up ?

Thanks !

# error message in Matlab

Warning: Stan seems to have exited badly.

In StanFit/process_exit_failure (line 290)

In StanFit/process_exit (line 170)

In StanFit>@(src,evnt)process_exit(self,src,evnt) (line 71)

In processState/set.exitValue (line 30)

In processManager.pollTimerStop (line 508)

In timer/timercb (line 90)

Warning: Stan seems to have exited badly.

In StanFit/process_exit_failure (line 290)

In StanFit/process_exit (line 170)

In StanFit>@(src,evnt)process_exit(self,src,evnt) (line 71)

In processState/set.exitValue (line 30)

In processManager.pollTimerStop (line 508)

In timer/timercb (line 90)

Warning: Stan seems to have exited badly.

In StanFit/process_exit_failure (line 290)

In StanFit/process_exit (line 170)

In StanFit>@(src,evnt)process_exit(self,src,evnt) (line 71)

In processState/set.exitValue (line 30)

In processManager.pollTimerStop (line 508)

In timer/timercb (line 90)

Warning: Stan seems to have exited badly.

In StanFit/process_exit_failure (line 290)

In StanFit/process_exit (line 170)

In StanFit>@(src,evnt)process_exit(self,src,evnt) (line 71)

In processState/set.exitValue (line 30)

In processManager.pollTimerStop (line 508)

In timer/timercb (line 90)

# code

y_dti = back3dti;

##### size(y_dti) 268,16,6

N = ni1;

model = StanModel(‘verbose’,true);

model.compile(‘stanc’);

dti_code = {

‘data {’

‘int<lower=0> N;’

'vector[16] x; ’ % 16 b-values

‘matrix[6,3] G;’ % gradient direction

‘array[N,16,6] real yy;’

‘}’

‘parameters {’

'vector[N] S0; ’

‘real <lower=0> sigma;’

'vector[N] Dxx; ’

'vector[N] Dxy; ’

'vector[N] Dxz; ’

…

‘}’

‘model {’

‘for (s in 1:N){’

‘Dxx[s] ~ uniform(-2.5e-3,2.5e-3);’ % for all Ns

‘Dxy[s] ~ uniform(-2.5e-3,2.5e-3);’

‘Dxz[s] ~ uniform(-2.5e-3,2.5e-3);’

‘Dyx[s] ~ uniform(-2.5e-3,2.5e-3);’

…

‘}’

‘sigma ~ uniform(0,10);’

```
'for (v in 1:N){'
'for (n in 1:16){'
'for (k in 1:6){'
'yy[v,n,k] ~ normal(S0[v]*exp(-x[n]*(G[k,1]^2*Dxx[v] + G[k,2]^2*Dyy[v] + G[k,3]^2*Dzz[v] + 2*G[k,1]*G[k,2]*Dxy[v] + 2*G[k,1]*G[k,3]*Dxz[v] + 2*G[k,2]*G[k,3]*Dyz[v])),sigma);'
```

‘}’

‘}’

‘}’

‘}’

};

% for initialising parameters

model.set(‘model_code’,dti_code);

model.compile();

data_S = struct(‘N’,ni1,‘G’,g,‘yy’,y_dti,‘x’,bval);

fit_S = stan(‘fit’,model,‘data’,data_S,‘init’,struct(‘Dxx’,1.5e-3*ones(ni1,1),‘Dxy’,1.5e-3*ones(ni1,1),‘Dxz’,1.5e-3*ones(ni1,1),‘Dyx’,1.5e-3*ones(ni1,1),‘Dyy’,1.5e-3*ones(ni1,1),‘Dyz’,1.5e-3*ones(ni1,1),‘Dzx’,1.5e-3*ones(ni1,1),‘Dzy’,1.5e-3*ones(ni1,1),‘Dzz’,1.5e-3*ones(ni1,1),‘S0’,150*ones(ni1,1),‘sigma’,5));