// Model 1: NO MATRIX
data {
int<lower=0> N; // number of observations
int<lower=0> J; // number of subjects
int subj[N]; // subjects
vector[N] rt; // predictor vector
vector[N] dp; // outcome vector
}
parameters {
vector[J] incp; // intercept
vector[J] rate; // rate
vector[J] asym; // asymptote
real<lower=0> sigma; // L1 error
real mu_ua;
real mu_ur;
real mu_ui;
real<lower=0> sigma_ua; // L2 error asy
real<lower=0> sigma_ur; // L2 error rate
real<lower=0> sigma_ui; // L2 error int
}
transformed parameters {
vector[N] mu;
vector[N] ast;
vector[N] rat;
vector[N] itt;
for (n in 1:N) {
ast[n] = asym[subj[n]];
rat[n] = rate[subj[n]];
itt[n] = incp[subj[n]];
mu[n] = fmax(0, ast[n] * (1.0 - exp( -rat[n] * (rt[n] - itt[n] ) )) );
}
}
model {
asym ~ normal(mu_ua, sigma_ua);
incp ~ normal(mu_ui, sigma_ui);
rate ~ normal(mu_ur, sigma_ur);
mu_ua ~ normal(0,100);
mu_ui ~ normal(0,100);
mu_ur ~ normal(0,100);
sigma ~ cauchy(0,5);
sigma_ua ~ cauchy(0,5);
sigma_ui ~ cauchy(0,5);
sigma_ur ~ cauchy(0,5);
dp ~ normal(mu, sigma);
}// Model 2: MATRIX
data {
int<lower=0> N; // number of observations
int<lower=0> J; // number of subjects
int subj[N]; // subjects indicator
vector[N] rt; // predictor vector
vector[N] dp; // outcome vector
// these matrices have only one column with the value of 1 (for intercept)
matrix[N,1] int_x; // interc: fixed effects model
matrix[N,1] rat_x; // rate: fixed effects model
matrix[N,1] asy_x; // asym: fixed effects model
}
parameters {
matrix[J,1] inte; // interc: fixed effects coefficients
matrix[J,1] rate; // rate: fixed effects coefficients
matrix[J,1] asym; // asym: fixed effects coefficients
real<lower=0> sigma; // L1 error
real<lower=0> sigma_i; // subj inte ranef
real<lower=0> sigma_r; // subj rate ranef
real<lower=0> sigma_a; // subj asym ranef
real mu_i;
real mu_r;
real mu_a;
}
transformed parameters{
vector[N] mu;
vector[N] ast;
vector[N] rat;
vector[N] itt;
itt = rows_dot_product(int_x, inte[subj] );
rat = rows_dot_product(rat_x, rate[subj] );
ast = rows_dot_product(asy_x, asym[subj] );
for (n in 1:N) {
mu[n] = fmax(0, ast[n] * (1.0 - exp( -rat[n] * (rt[n] - itt[n] ) )) );
}
}
model {
sigma ~ cauchy(0,5);
sigma_a ~ cauchy(0,5);
sigma_i ~ cauchy(0,5);
sigma_r ~ cauchy(0,5);
mu_i ~ normal(0,100);
mu_r ~ normal(0,100);
mu_a ~ normal(0,100);
inte[,1] ~ normal(mu_i, sigma_i);
rate[,1] ~ normal(mu_r, sigma_r);
asym[,1] ~ normal(mu_a, sigma_a);
dp ~ normal(mu, sigma);
}
Thank you for your answer, Bob.
I finally found the problem. It was that my init values were correctly passed in model 1, but not in model 2 - and given the nature of the model without good init values things don’t work.
I was passing vectors while the parameters were matrices, and given the absence of warnings or errors messages I thought things were working. Then I looked at get_inits() and saw the problem.
Re your suggestion to recode asym etc, that would be the same model, we are just moving them outside of the loop. It’s only an efficiency issue, correct?