Divergent issues; R-hat issues; ESS issues. Any tips/advice is much appreciated.
My thoughts on potential issues:
- Maybe it’s how I’m dealing with unbalanced longitudinal data portion i.e. if (i != previous\_id)? I thought the logic makes sense here so I sample random effects whenever ‘ID’ in the dataset changes to a new value.
- Maybe it’s that I’m trying to deal with the model’s function of ‘age’ by having two indexing: i for the unique subject Id’s + row\_index for the rows of my dataset. Is there a better way to do this (anything in the STAN manual for modeling subject-specific observed data that are functions of time)?
I attached snippet of data, full code, and full math:
data {
int<lower=0> NJ; // dataset has NJ rows; $\sum_{i=1}^{N} j_{i}$ <=> each subject has different number of observations)
int<lower=0> N; // number of subjects
array[NJ] int<lower=0> all_subject_ids;
array[NJ] real<lower=0> ages;
array[NJ] real<lower=0> y_obs;
array[NJ] real<lower=0> y_obs_bool;
}
parameters {
real<lower=0,upper=1> tau; // RV
real<lower=log(10),upper=log(550)> log_bar_thetaA; // fixed effect
real<lower=log(5), upper=log(20)> log_bar_thetaB; // fixed effect
real<lower=log(40), upper=log(70)> log_bar_thetaC; // fixed effect
real<lower=0, upper=1> omega_thetaA; // s.d. for between-subject variability (BSV) random effect
real<lower=0, upper=1> omega_thetaB; // s.d. for BSV random effect
real<lower=0, upper=1> omega_thetaC; // s.d. for BSV random effect
vector[N] log_thetaA; // BSV random effect
vector[N] log_thetaB; // BSV random effect
vector[N] log_thetaC; //BSV random effect
}
model {
int previous_id;
previous_id = 0;
int i;
vector[NJ] y_pred;
for (row_indx in 1:NJ) {
if (y_obs_bool[row_indx]==1) { // baseline observations (at first age) are always observed
i = all_subject_ids[row_indx]; // can repeat
if (i!=previous_id) {
log_thetaA[i] ~ normal(log_bar_thetaA, omega_thetaA);
log_thetaB[i] ~ normal(log_bar_thetaB, omega_thetaB);
log_thetaC[i] ~ normal(log_bar_thetaC, omega_thetaC);
previous_id = i;
}
y_pred[row_indx] = exp(log_thetaA[i]) * (1 - ( ( 1 * ( ages[row_indx] ^ exp(log_thetaC[i]) ) ) / ( exp(log_thetaB[i]) ^ exp(log_thetaC[i]) + ages[row_indx] ^ exp(log_thetaC[i]) ) ) );
target += normal_lpdf(y_obs[row_indx] | y_pred[row_indx], y_pred[row_indx] * tau);
}
}
}
Sigmoid \text{I}_\text{max} model:
y_{i}(\text{age})= \theta_{iA}\cdot \Bigg(1-\frac{1*\cdot\text{age}_{i}^{\theta_{iC}}}{\theta_{iB}^{\theta_{iC}}+\text{age}_{i}^{\theta_{iC}}}\Bigg)\cdot(1+\epsilon_{i}), \ \ \ \epsilon_{i}\sim\text{N}(0,\tau^{2})
for j=A, B, C:
\ln(\theta_{ij})\sim\text{N}(\ln(\bar{\theta}_{j}),\omega_{j}^{2})
where \bar{\theta}_{j} is fixed effect, \omega_{j} is s.d. for between-subject variability (BSV) of random effect; \tau is s.d. for residual variability (RV)