Hello! I am utilizing Bessel Regression to model mean essay scores from a standardized exam across various Brazilian municipalities. The response variable is bounded between 0 and 1, and my covariates are municipal indices (economy, health, and education) that also range from 0 to 1. While the overall municipal index is an average of these three components, I am including each as a separate covariate in the model. Similar to the Beta distribution, the Bessel regression is well-suited for modeling data on the (0, 1) interval. When testing the model with synthetic data, Stan successfully recovers the parameters; however, when applied to my real dataset, the following errors occur:
1: There were 19466 divergent transitions after warmup. See
https://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
to find out why this is a problem and how to eliminate them.
2: There were 278 transitions after warmup that exceeded the maximum treedepth. Increase max_treedepth above 10. See
https://mc-stan.org/misc/warnings.html#maximum-treedepth-exceeded
3: Examine the pairs() plot to diagnose sampling problems
4: The largest R-hat is 1.16, indicating chains have not mixed.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#r-hat
5: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#bulk-ess
6: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#tail-ess
I have included the R and Stan code, along with the dataset, below for reference.
dados1 = c(t(dados_enem_2018[,-1]))
N = 188
X = as.matrix(tibble(rep(1,N),c(t(Economia_mg_2018[, -1])),c(t(Educacao_mg_2018[, -1])),
c(t(Saude_mg_2018[, -1])) ))
V = X
stan_data1 <- list(
N = N,
y = dados1,
M = 4,
X = X,
V = V
)
##################################
fit1 <- stan(file = "Modelo_Bessel.stan", data = stan_data1,
iter = 10000, warmup = 5000, chains = 4, cores = 4)
Stan:
functions{
real zeta(real z, real mu) {
return sqrt(1 + (((z-mu)^2) / (z*(1-z))));
}
real bessel_lpdf(real z, real mu, real phi){
return log(mu)+log(1-mu)+log(phi)+phi-log(pi())-(3.0/2.0)*(log(z)+log(1-z))+
log(modified_bessel_second_kind(1, (phi*zeta(z,mu)))) - log(zeta(z,mu));
}
}
data {
int<lower=0> N;
int<lower=0> M;
vector[N] y;
matrix[N,M] X;
matrix[N,M] V;
}
parameters {
vector[M] kap;
vector[M] lam;
}
transformed parameters{
vector<lower = 0, upper = 1>[N] mu;
vector<lower = 0>[N] phi;
for (i in 1:N){
mu[i] = exp(X[i]*kap)/(1+exp(X[i]*kap));
phi[i] = exp(V[i]*lam);
}
}
model {
kap ~ multi_normal(rep_vector(0, M), (10*identity_matrix(M)));
lam ~ multi_normal(rep_vector(0, M), (10*identity_matrix(M)));
for (i in 1:N){
y[i] ~ bessel(mu[i],phi[i]);
}
}
dados_enem_2018.csv (5.7 KB)
Economia_mg_2018.csv (3.5 KB)
Educacao_mg_2018.csv (3.5 KB)
Saude_mg_2018.csv (3.5 KB)