Hello Stan community!
I am trying to fit a “two-horse” linear approach to threshold with ergodic rate (LATER) model to reaction time data (similar to this paper: Adam, Bays & Husain, Cognitive Neuroscience 2012).
The model posits two recinormal processes racing to generate a response. The anticipatory process ( A ) starts at t=0 and the reactive process ( R ) starts at t=t_0. Whichever process reaches threshold first triggers the response (“OR” rule). The resulting cumulative probability distribution is given by:
Pr(T \leq t) = \Psi(t | \mu_A, \sigma_A) + \Psi(t-t_0 | \mu_R, \sigma_R)-\Psi(t | \mu_A, \sigma_A)\Psi(t-t_0 | \mu_R, \sigma_R)
where \Psi are the recinormal CDF, defined as \Psi(t | \mu_i, \sigma_i) = 1 - \Phi(\frac{1}{t} | \mu, \sigma) based on the normal CDF \Phi.
The likelihood function is obtained by differentiating the CDF (note: it is not a mixture of PDFs):
Pr(t) = \psi(t | \mu_A, \sigma_A) + \psi(t - t_0 | \mu_R, \sigma_R) - \Psi(t | \mu_A, \sigma_A)\psi(t-t_0 | \mu_R, \sigma_R) - \Psi(t-t_0 | \mu_R, \sigma_R)\psi(t | \mu_A, \sigma_A)
where \psi is the recinormal PDF, defined as \psi(t | \mu_i, \sigma_i) = \phi(\frac{1}{t} | \mu, \sigma)/t^2 based on the normal PDF \phi.
I have written the model as follows:
data {
int<lower=1> P; // number of participants
int<lower=1> N; // total number of datapoints
int<lower=1,upper=P> subjID[N]; // person index for all the datapoints
vector[N] G; // t0 (in ms)
vector[N] Y; // all RT data (in ms)
}
parameters {
vector<lower=0>[P] mu_anticip;
vector<lower=0>[P] sigma_anticip;
vector<lower=0>[P] mu_react;
vector<lower=0>[P] sigma_react;
real<lower=0> MU_mu_anticip;
real<lower=0> MU_sigma_anticip;
real<lower=0> MU_mu_react;
real<lower=0> MU_sigma_react;
real<lower=0> SIGMA_mu_anticip;
real<lower=0> SIGMA_sigma_anticip;
real<lower=0> SIGMA_mu_react;
real<lower=0> SIGMA_sigma_react;
}
model {
// Priors
mu_anticip ~ normal(MU_mu_anticip,SIGMA_mu_anticip);
sigma_anticip ~ normal(MU_sigma_anticip,SIGMA_sigma_anticip);
mu_react ~ normal(MU_mu_anticip,SIGMA_mu_anticip);
sigma_react ~ normal(MU_sigma_anticip,SIGMA_sigma_anticip);
// Likelihood
for (i in 1:N) {
Y[i] ~ twoHorses_lpdf(G[i],mu_anticip[subjID[i]],sigma_anticip[subjID[i]],mu_react[subjID[i]],sigma_react[subjID[i]]);
}
}
However, I am struggling to define the log probability function twoHorses_lpdf. I think I have managed to write log(\Psi(t | \mu_i, \sigma_i)) and log(\psi(t | \mu_i, \sigma_i)) properly as:
functions {
real recinormal_lpdf(real y, real mu, real sigma) {
if (y>0)
return normal_lpdf(1/y, mu, sigma)-2*log(y);
else
return negative_infinity();
}
real recinormal_lcdf(real y, real mu, real sigma) {
if (y>0)
return log(1-normal_cdf(1/y, mu, sigma));
else
return negative_infinity();
}
}
But I don’t know how to define the log probability function based on the equations above. Could you provide some guidance on how to do so?
Thanks a lot!
Pierre