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

Multivariate Modelling with Multiple DVs #18

Open zentavious opened 10 months ago

zentavious commented 10 months ago

I'm looking for some clarity about ordbetareg's support for multivariate modeling. I've done a fair amount of digging around the source code and have narrowed down what appears to be the issue.

Keeping things simple, I'm trying to fit the following function:

bform1 <- bf(mvbind(Y1, Y2, Y3) ~ X + (1|p|participant.id)) + set_rescor(FALSE)

ord_fit <- ordbetareg(formula=bform1, 
                      data=model_data,
                      cores=4,chains=4,iter=2000,
                      control = list(adapt_delta = 0.95))

The observed behavior is that the model is completed successfully, but an error is thrown after calling fit_func(...) in modeling.R on line 573.

Error in data[[dv_pos]] : recursive indexing failed at level 2

This error stems from the call out_obj$upper_bound <- attr(data[[dv_pos]],'upper_bound') when dv_pos is named list of integers

  Y1  Y2  Y3 
   1   2   3 

My question, is ordbetareg intended to support such a function? And if so, what are the intended interpretations of out_obj$upper_bound and out_obj$lower_bound when there could be multiple upper and lower bounds? I will say in my case, I've already normalized all the response variables. In that case, I suspect it'd be ok if line 273 said out_obj$upper_bound <- attr(data[[dv_pos[[1]]]],'upper_bound')

zentavious commented 10 months ago

I was able to fork the repo and fix this issue for my personal use. Please let me know if it'd be helpful for me to make a pull request to support this. I'd guess it'd be reasonable to return a list containing all upper and lower bounds for each variable, but I'm unsure if other brms functions depend on those variables. If that's the case, returning the normalized bounds [0,1] might be the right thing to do. Let me know!

saudiwin commented 10 months ago

Hi @zentavious - thanks for alerting me to this. You are using the simplified brms syntax while I focused on implementing the more customized syntax in which you specify each model separately with bf (see ordbetareg vignette for an example). It should be easier to implement this version than the customized version, but it will require a bit of extra code as there are multiple models.

Why don't you send in your code fix as a pull request so I can look at it? I do think ordbetareg should support this use case. I'll leave this issue open until it's fully implemented.