@@ -459,18 +459,26 @@ create_initial_conditions <- function(stan_data, params) {
459459 }
460460 }
461461 }
462+ # # initial draws stay within each prior's truncation bounds (b = *_upper),
463+ # # otherwise a bounded prior gives -Inf density at the initial value
462464 out $ state_rw_sd <- array (
463- rtruncnorm0(stan_data $ n_rw_states %|| % 0L , a = 0 , mean = 0 , sd = 0.1 )
465+ rtruncnorm0(
466+ stan_data $ n_rw_states %|| % 0L , a = 0 , b = stan_data $ rw_sd_upper ,
467+ mean = 0 , sd = 0.1
468+ )
464469 )
465470 out $ state_rw_steps <- array (rnorm(n_rw_steps , 0 , 0.1 ))
466471 out $ state_gp_eta <- array (rnorm(n_gp_coef , 0 , 0.1 ))
467472 out $ state_gp_alpha <- array (
468- rtruncnorm0(stan_data $ n_gp_states %|| % 0L , a = 0 , mean = 0 , sd = 0.1 )
473+ rtruncnorm0(
474+ stan_data $ n_gp_states %|| % 0L , a = 0 , b = stan_data $ gp_alpha_upper ,
475+ mean = 0 , sd = 0.1
476+ )
469477 )
470478 rho_scale <- if (length(gp_free ) > 0 ) mean(gp_free ) else 1
471479 out $ state_gp_rho <- array (
472480 rtruncnorm0(
473- stan_data $ n_gp_states %|| % 0L , a = 0 ,
481+ stan_data $ n_gp_states %|| % 0L , a = 0 , b = stan_data $ gp_rho_upper ,
474482 mean = rho_scale / 2 , sd = rho_scale / 4
475483 )
476484 )
0 commit comments