Hi everyone,
We are working with a Bayesian model in Stan that includes two sets of Cholesky factorized correlation matrices:
parameters {
array[M-1] cholesky_factor_corr[how_many_factors_in_random_design[1]] sigma_correlation_factor;
array[M-1] cholesky_factor_corr[how_many_factors_in_random_design[2]] sigma_correlation_factor_2;
}
model {
for (m in 1:(M-1)) {
sigma_correlation_factor[m] ~ lkj_corr_cholesky(2.0);
sigma_correlation_factor_2[m] ~ lkj_corr_cholesky(2.0);
}
}
The model fits without divergence issues (only 2 divergent transitions out of ~4000 draws), but we noticed unexpected behavior in the correlation structures:
- Both correlation matrices are consistently estimated as identity matrices (all correlations ≈ 1.0). : The sampled values of
sigma_correlation_factor
andsigma_correlation_factor_2
do not vary—they are always1.0
. rhat
andess_bulk
for both matrices returnNA
.
fit$summary('sigma_correlation_factor_2')
# A tibble: 13,068 × 10
variable mean median sd mad q5 q95 rhat ess_bulk ess_tail
<chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 sigma_correlation_factor_2[1,1,1] 1 1 0 0 1 1 NA NA NA
2 sigma_correlation_factor_2[2,1,1] 1 1 0 0 1 1 NA NA NA
3 sigma_correlation_factor_2[3,1,1] 1 1 0 0 1 1 NA NA NA
4 sigma_correlation_factor_2[4,1,1] 1 1 0 0 1 1 NA NA NA
5 sigma_correlation_factor_2[5,1,1] 1 1 0 0 1 1 NA NA NA
6 sigma_correlation_factor_2[6,1,1] 1 1 0 0 1 1 NA NA NA
7 sigma_correlation_factor_2[7,1,1] 1 1 0 0 1 1 NA NA NA
8 sigma_correlation_factor_2[8,1,1] 1 1 0 0 1 1 NA NA NA
9 sigma_correlation_factor_2[9,1,1] 1 1 0 0 1 1 NA NA NA
10 sigma_correlation_factor_2[10,1,1] 1 1 0 0 1 1 NA NA NA
# ℹ 13,058 more rows
# ℹ Use `print(n = ...)` to see more rows
- When performing predictive sampling (
generated quantities
block), some correlation values exceed[-1,1]
, leading to numerical errors.
Loading model from cache...
Running standalone generated quantities after 1 MCMC chain, with 1 thread(s) per chain...
Chain 1 Exception: lub_free: Correlation variable is 1.00006, but must be in the interval [-1, 1] (in '/tmp/RtmpXRypuf/model-44b176a8d7478.stan', line 184, column 1 to column 144)
Warning: Chain 1 finished unexpectedly!
Error: Generating quantities for all MCMC chains failed. Unable to retrieve the generated quantities.
Questions for the Community
- Why are both correlation matrices being estimated as identity matrices (
1.0
everywhere)? - What could be causing
rhat
andess_bulk
to returnNA
for these parameters? - Why does
sigma_correlation_factor_2
exceed[-1,1]
in predictive sampling when it was estimated as 1?
Any insights, debugging suggestions, or best practices would be greatly appreciated!
Thanks in advance for your help