venpopov / bmm

An R package for easy and flexible Bayesian Measurement Modeling
https://venpopov.github.io/bmm/
GNU General Public License v2.0
12 stars 3 forks source link

Create custom summary.bmmfit method #37

Closed venpopov closed 7 months ago

venpopov commented 8 months ago

Currently the brms model returns a summary that include the internal terms such as constant mu, kappa2, etc

image

We can remove that with a bit of preprocessing - brms does the same internally for its own models.

GidonFrischkorn commented 7 months ago

Just to remind ourselves of the discussion we had today: We will implement this by writing a summary.bmmfit method to avoid changing any information in the fit object and keep it compatible with most of the brms post-processing.

venpopov commented 7 months ago

Yes, just as an example of why we really want to do this. I had never run the mixture3p model when there is setsize 1 (or I don't remember looking at the summary, maybe we did for the tutorial). I just did for testing. We did anticipate it and fixed the thetant to be a constant for setsize1, but if I didn't know why, I would be quite confused by this output:

image

venpopov commented 7 months ago

Before we dive into doing this, mayb discuss what we would like the summary to actually show.

For example, here's the summary from an example sdm model

image

For this particular model it actually mostly fine. I'd prefer to have it show

So my proposal for all models is:

Also, we can give an option summary_backend = 'bmm' or 'brms', with 'bmm' default, but people can use the brms option if they want to.

venpopov commented 7 months ago

Just a few notes about how brms produces the summary. Assume fit is the variable containing the model fit

what do we need?

summary.bmmfit <- function(object, priors = FALSE, prob = 0.95, robust = FALSE,  mc_se = FALSE, ..., backend = 'bmm') {
   # add some check about possible backends (bmm and brms only)

   # get summary object from brms, since it contains a lot of necessary information:
   out <- NextMethod('summary')

   # stop and give brms summary if user wants brms summary
   if (backend == 'brms') {
    return(out)
   }

   # out is just a list - at this point we can modify it any way we want. In a upcoming PR I have also saved the bmm model and bmm_formula objects in the output, so we can access them for info
   # here add, remove or change any parts of the summary list

   # assign bmmsummary class to handle the printing
   class(out) <- 'bmmsummary'
   out
}

and then a custom print.bmmsummary method (modifying the base code from brms:::print.brmssummary)


I think this will be the simplest approach

GidonFrischkorn commented 7 months ago

Agreed! If you want you can have a look at it. I took the more complicated road and actually looked into writing a whole summary.bmmfit function.

But I think given that we import brms your suggestion will work easiest.

I did not make much progress so far. So, if you want to feel free to have a look into this. I will get to this earliest by Tuesday or Wednesday next week.

venpopov commented 7 months ago

Ok, then if you don't mind I will give it ago :)

venpopov commented 7 months ago

Just fyi, I'm starting to work on this, so I will use the same branch