Model with many (correlated) varying-slopes: Sampling not done

I was trying to fit the below model with brms:

fit.1 <- brm(y ~ A * B * C * D + E + (A * B * C * D | g1) + (1 | g2),
           data = df, family = lognormal,
           cores = 1, chains = 1, iter = 300)

A, B, C and D are factors and E is a covariate. This is the dumped data set data.R (410.3 KB).

During sampling, I got errors:

Rejecting initial value:
  Log probability evaluates to log(0), i.e. negative infinity.
  Stan can't start sampling from this initial value.
Iteration:   1 / 300 [  0%]  (Warmup)
Exception: model39d27bec92db_a2c0a7231ba0e427628b016846ca7749_namespace::write_array: y is not positive definite.  (in 'model39d27bec92db_a2c0a7231ba0e427628b016846ca7749' at line 143)

After the sampling ended, I got an error saying that sampling was not done:

error occurred during calling the sampler; sampling not done

However, if I remove the correlation of varying intercepts and varying slopes, the model converges successfully:

fit.2 <- brm(y ~ A * B * C * D + E + (A * B * C * D || g1) + (1 | g2),
           data = df, family = lognormal,
           cores = 1, chains = 1, iter = 300)

Do you know what was wrong with the first model?

Thank you!


The full errors after sampling:

 [1] "Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:"                                          
 [2] "Exception: lognormal_lpdf: Scale parameter is inf, but must be finite!  (in 'model39d27bec92db_a2c0a7231ba0e427628b016846ca7749' at line 137)"           
 [3] "If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,"                  
 [4] "but if this warning occurs often then your model may be either severely ill-conditioned or misspecified."                                                
 [5] "Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:"                                          
 [6] "Exception: lognormal_lpdf: Scale parameter is inf, but must be finite!  (in 'model39d27bec92db_a2c0a7231ba0e427628b016846ca7749' at line 137)"           
 [7] "If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,"                  
 [8] "but if this warning occurs often then your model may be either severely ill-conditioned or misspecified."                                                
 [9] "Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:"                                          
[10] "Exception: lognormal_lpdf: Scale parameter is inf, but must be finite!  (in 'model39d27bec92db_a2c0a7231ba0e427628b016846ca7749' at line 137)"           
[11] "If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,"                  
[12] "but if this warning occurs often then your model may be either severely ill-conditioned or misspecified."                                                
[13] "Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:"                                          
[14] "Exception: multiply: A[37] is -nan, but must not be nan!  (in 'model39d27bec92db_a2c0a7231ba0e427628b016846ca7749' at line 79)"                          
[15] "If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,"                  
[16] "but if this warning occurs often then your model may be either severely ill-conditioned or misspecified."                                                
[17] "Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:"                                          
[18] "Exception: lognormal_lpdf: Scale parameter is inf, but must be finite!  (in 'model39d27bec92db_a2c0a7231ba0e427628b016846ca7749' at line 137)"           
[19] "If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,"                  
[20] "but if this warning occurs often then your model may be either severely ill-conditioned or misspecified."                                                
[21] "Error in sampler$call_sampler(args_list[[i]]) : "                                                                                                        
[22] "  Exception: model39d27bec92db_a2c0a7231ba0e427628b016846ca7749_namespace::write_array: y is not positive definite.  (in 'model39d27bec92db_a2c0a7231ba0e427628b016846ca7749' at line 143)"

error occurred during calling the sampler; sampling not done
  • Operating System: Ubuntu 18.04.1
  • brms Version: 2.5.0

This is likely a problem with the initial values being too extreme. Try out inits = 0 or, if that fails, init_r = 0.1 (or even some smaller value).

1 Like

The model converged without problems after setting inits = 0.
Thank you so much for your advice!

Note that when you set inits = 0 you no longer have over-dispersed starting values between chains. This is relevant, because to conclude convergence across multiple chains, these need to start from different points, which is not the case when you set inits = 0.

If you want to assure convergence across multiple chains from Rhat values you need to set init_r = r or similar values as Paul also recommended. What value of r is reasonable depends on the values of your variables. (If you specify interactions, the range of main and interaction terms is relevant)

2 Likes

Thank you so much!
I didn’t know the importance of different initial values for multiple chains!
I don’t know much about initial values, I searched through the Stan manual and it says:

[Zero initial values] can be helpful for diagnosis, and may also be a good starting point for sampling. Once a model is running, multiple chains with more diffuse starting points can help diagnose problems with convergence …

So, different starting points should be better. I tried out init_r = 0.1 and it worked for my model.

However, I still don’t understand how to decide a reasonable range for initial values.
Is that based on one’s expectation of the values of parameters?

Most of my predictors are factors and the only covariate has a range within [-1, 1].
The model with default initial values only fails when the multilevel correlations are modeled, does it mean that the failure was due to extreme initial values for the correlation parameters?
Also, the estimated multilevel correlations are very small for my model. Is this the reason that smaller initial values are recommended?

It’s because the model contains so many terms that the default initial values over all the included parameters sum up to some extremely implausible values with a density very close to zero so that log() underflows to - infinity. You don’t need to worry about this I think as long as smaller init_r values solve it for you.

3 Likes

Now I understand the concepts behind smaller init_r values. Thank you so much!