saudiwin / ordbetareg_pack

Repository for R package ordbetareg, used to fit continuous data with lower and upper bounds.
Other
17 stars 3 forks source link

Compilation error when sample_prior=TRUE #1

Closed eipi10 closed 2 years ago

eipi10 commented 2 years ago

I've been working with ZOIB regression models in brms and decided to try the ordered beta model after seeing your posts on the Stan forum and browsing through your paper (which I hope to read in more detail). I included sample_prior=TRUE as an argument in the ordbetareg function, which caused a compilation error. I'm not sure if I should have expected sample_prior_TRUE to work, but I wanted to bring this to your attention in case it's a bug. When I removed the argument, the sampling completed as expected. Now I just have to spend some time getting a better understanding of the model. Thanks for making this model and package available!

Below is a reproducible example using the pew data from the Vignette.

ord_fit_mean <- ordbetareg(formula=therm ~ mo(education)*mo(income) + (1|region), 
                           data=model_data,
                           cores=2,chains=2,iter=1000,
                           sample_prior=TRUE,
                           refresh=0)
Compiling Stan program...
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
No matches for: 

  induced_dirichlet_rng(vector, int)

Function induced_dirichlet_rng not found.
 error in 'model165e36ef63963_4801811fdbe1356d482a6c93380fb357' at line 148, column 55
  -------------------------------------------------
   146:   real prior_phi = exponential_rng(0.1);
   147:   real prior_sd_1 = student_t_rng(3,0,2.5);
   148:   real prior_thresh = induced_dirichlet_rng([1,1,1]',0);
                                                              ^
   149:   // use rejection sampling for truncated priors
  -------------------------------------------------

Error in stanc(file = file, model_code = model_code, model_name = model_name,  : 
  failed to parse Stan model '4801811fdbe1356d482a6c93380fb357' due to the above error.
In addition: Warning message:
Rows containing NAs were excluded from the model. 
saudiwin commented 2 years ago

sorry about that! the model is using a custom prior and I didn't include an RNG function to allow it to sample from the prior. I'll try to update the package soon-ish. Would be a great feature to have for sure.

saudiwin commented 2 years ago

Unfortunately, this seems to be an underlying issue in brms, so it might take a while to resolve.

saudiwin commented 2 years ago

I made some changes to how the priors on the cutpoints are calculated, so it should work now. I also found a bug related to that calculation which could cause divergent transitions (!!), so on the whole this was a useful exercise. Try installing directly from github (remotes::install_github('saudiwin/ordbetareg_pack')) to use the sample_prior option.

eipi10 commented 2 years ago

Great. I will install the updated package. Thanks!