Let M_{i}(t) be some summary of risk factors at time t for participant i from the longitudinal risk factor model. The hazard sub-model is h_{i}(t \vert M_{i}(t)) = h_{0}\exp\{\alpha^{'T}w_{i} + \alpha \int_{s=0}^{t} m_{i}(s) I(m_{i}(s) > \gamma)ds
where \gamma is a risk factor threshold and linear predictor of longitudinal sub-model m_{i}(t)=x_{i}^T(t)\beta+z_{i}^T(t)b_{i}.

Is there any way to specify the area above threshold feature (integration part in hazard model) like this in STAN?

Thank you for your reply! That thread is helpful but I am wondering how I can write the indicator part involving longitudinal parameters in transformed parameters block.

functions{
real indicator(real x, real c){
real ans = x > c ? 1 : 0;
return(ans);
}
real phi( real x, real x_c,
array[] real theta, array[] real x_r, array[] int x_i ) {
real ans = x^2 * exp(-x^2/2) * indicator(x, 0);
return(ans);
}
}
transformed data {
real x_c[0];
real x_r[0];
int x_i[0];
real theta[2];
}
generated quantities{
real the_int = integrate_1d (phi,
negative_infinity(), positive_infinity(), theta, x_r, x_i);
}

Thank you so much! Now, I can write the area above threshold feature in stan. Just one question to confirm that I am doing it correctly. Is it okay to compute this feature (involves indicator function) within transformed parameter block and add it as a covariate in the survival model?

I can’t see why not, but then again I’m not an expert on survival models. Maybe if @harrelfe sees this he might be able to advise. I suggest you ask a new, separate question.