Hello,
I am attempting to fit discrete time event models to some frog tadpole metamorphosis data.
I have been able to successfully fit the model, but LOO for model comparisons demonstrate high pareto K values for roughly 0.3% of observations (10 out of n = 2879).
I have tried moment-matching, using non-random intercepts, longer chain iterations and predictor transformations but that only really removes on k > 0.7 observation if at all. I know the standard is to remove outliers, but the outliers correspond to metamorphosis observations (specifically high abundance of competitors), which I think is what is driving the event to occur so removing the observations seems ill-advised.
I know there are some alternatives, such as Mixture Importance sampling or using exact leave-one-out, a la reloo in brms, but since I am computing directly through rstan I am lost on how to achieve this.
I know that with high k values, that the output of resulting LOO comparisons are unreliable, but I don’t have the know-how to determine if the 10 observations are “that bad” and can be “ignored” or implement mixis or reloo methods through rstan.
I have attached my model and resulting outputs. Any help is appreciated!
Stan Model Code
data {
int<lower=1> N; // Number of data rows
int<lower=1> T; // Number of time steps
int<lower=1> K; // Number of predictors
int<lower = 1> Ta; // Number of tanks
int<lower = 1, upper = Ta> Tank[N];// Tank ID
int<lower = 1> En; // Number of enclosures
int<lower = 1, upper = En> Enclosure[N];// Enclosure ID
int<lower=1> Time[N]; // Time interval (e.g., 1, 2, 3,...)
int<lower=0> M[N]; // Metamorphosis (0 or 1)
matrix[N,K] X; // Predictors
}
parameters {
vector[T] alpha; // Time-specific intercepts
vector[K] beta; // Coefficients for predictors
vector[Ta] gamma; // random effects for tank
vector[En] tau; // random effects for enclosure
real <lower=0> sigma_gamma; // standard deviation of tank random effects
real <lower=0> sigma_alpha; // standard deviation of temporal random effects
real <lower=0> sigma_tau; // standard deviation of enclosure random effects
}
transformed parameters {
vector[N] h; // Hazard probabilities
for (i in 1:N) {
int t = Time[i];
int ta = Tank[i];
int en = Enclosure[i];
h[i] = 1 - exp(-exp(alpha[t] + gamma[ta] + tau[en] + X[i]* beta));
}
}
model {
// Priors (modify these as appropriate)
beta ~ normal(0, 1);
// Random effects
gamma ~ normal(0, sigma_gamma);
sigma_gamma ~ exponential(1);
alpha ~ normal(0, sigma_alpha);
sigma_alpha ~ exponential(1);
tau ~ normal(0, sigma_tau);
sigma_alpha ~ exponential(1);
// Likelihood
M ~ bernoulli(h);
}
generated quantities {
vector[N] log_lik;
int M_rep[N]; // simulated metamorphosis outcomes
for (i in 1:N) {
log_lik[i] = bernoulli_lpmf(M[i] | h[i]);
M_rep[i] = bernoulli_rng(h[i]); // simulate new dataset from the model
}
}
An example of LOO output is (which is identical to moment matched LOO):
Computed from 8000 by 2879 log-likelihood matrix.
Estimate SE
elpd_loo -222.6 21.7
p_loo 43.4 6.5
looic 445.2 43.4
------
MCSE of elpd_loo is NA.
MCSE and ESS estimates assume independent draws (r_eff=1).
Pareto k diagnostic values:
Count Pct. Min. ESS
(-Inf, 0.7] (good) 2869 99.7% 365
(0.7, 1] (bad) 10 0.3% <NA>
(1, Inf) (very bad) 0 0.0% <NA>
See help('pareto-k-diagnostic') for details.```
with the LOO compare table being:
elpd_diff se_diff elpd_loo se_elpd_loo p_loo se_p_loo looic se_looic
g1 0.00 0.00 -222.60 21.72 43.35 6.50 445.20 43.44
g2 -2.33 1.87 -224.93 22.04 45.20 6.84 449.86 44.07