@@ -814,7 +814,7 @@ stan_prior <- function(prior, class, coef = "", group = "",
814814 # for a given class of parameters. If a parameter has has
815815 # no corresponding prior in prior, an empty string is returned.
816816 tp <- tp(wsp )
817- wsp <- collapse(rep( " " , wsp ) )
817+ wsp <- wsp( nsp = wsp )
818818 prior_only <- identical(attr(prior , " sample_prior" ), " only" )
819819 keep <- prior $ class == class &
820820 prior $ coef %in% c(coef , " " ) & prior $ group %in% c(group , " " )
@@ -957,19 +957,20 @@ stan_target_prior <- function(prior, par, ncoef = 1, bound = "") {
957957 trunc_lb <- is.character(par_bound $ lb ) || par_bound $ lb > prior_bound $ lb
958958 trunc_ub <- is.character(par_bound $ ub ) || par_bound $ ub < prior_bound $ ub
959959 if (trunc_lb || trunc_ub ) {
960+ wsp <- wsp(nsp = 4 )
960961 if (trunc_lb && ! trunc_ub ) {
961962 str_add(out ) <- paste0(
962- " - " , ncoef , " * " , prior_name , " _lccdf(" ,
963+ " \n " , wsp , " - " , ncoef , " * " , prior_name , " _lccdf(" ,
963964 par_bound $ lb , " | " , prior_args
964965 )
965966 } else if (! trunc_lb && trunc_ub ) {
966967 str_add(out ) <- paste0(
967- " - " , ncoef , " * " , prior_name , " _lcdf(" ,
968+ " \n " , wsp , " - " , ncoef , " * " , prior_name , " _lcdf(" ,
968969 par_bound $ ub , " | " , prior_args
969970 )
970971 } else if (trunc_lb && trunc_ub ) {
971972 str_add(out ) <- paste0(
972- " - \n " , collapse(rep( " " , 8 )) , ncoef , " * log_diff_exp(" ,
973+ " \n " , wsp , " - " , ncoef , " * log_diff_exp(" ,
973974 prior_name , " _lcdf(" , par_bound $ ub , " | " , prior_args , " , " ,
974975 prior_name , " _lcdf(" , par_bound $ lb , " | " , prior_args , " )"
975976 )
@@ -995,11 +996,14 @@ stan_special_prior <- function(class, prior, ncoef, nlpar = "") {
995996 global_args <- sargs(global_args , global_args )
996997 c2_args <- paste0(" 0.5 * hs_df_slab" , p )
997998 c2_args <- sargs(c2_args , c2_args )
999+ wsp <- wsp(nsp = 4 )
9981000 str_add(out ) <- paste0(
9991001 tp , " normal_lpdf(zb" , p , " | 0, 1); \n " ,
1000- tp , " normal_lpdf(hs_local" , p , " [1] | 0, 1) - " , ncoef , " * log_half; \n " ,
1002+ tp , " normal_lpdf(hs_local" , p , " [1] | 0, 1)\n " ,
1003+ wsp , " - " , ncoef , " * log(0.5); \n " ,
10011004 tp , " inv_gamma_lpdf(hs_local" , p , " [2] | " , local_args , " ); \n " ,
1002- tp , " normal_lpdf(hs_global" , p , " [1] | 0, 1) - log_half; \n " ,
1005+ tp , " normal_lpdf(hs_global" , p , " [1] | 0, 1)\n " ,
1006+ wsp , " - 1 * log(0.5); \n " ,
10031007 tp , " inv_gamma_lpdf(hs_global" , p , " [2] | " , global_args , " ); \n " ,
10041008 tp , " inv_gamma_lpdf(hs_c2" , p , " | " , c2_args , " ); \n "
10051009 )
0 commit comments