GidonFrischkorn / bmm-implement-m3

Bayesian Measurement Models
https://venpopov.github.io/bmm/
GNU General Public License v2.0
0 stars 0 forks source link

Create `aggregate_data` function based on `bmmodel` and `bmmformula` #35

Closed GidonFrischkorn closed 1 month ago

GidonFrischkorn commented 6 months ago

This function should take the bmmodel and the bmmformula and then aggregate the data to optimize model estimation. This will speed up model estimation for all bmmodel that do not need to fit trial wise data

chenyu-psy commented 6 months ago

An idea of the function:

tidy_M3 <- function(
    .data,
    responses,
    group = NULL,
) {

  # Add response column to group
  new_group = c(group, "response")

  # Aggregate responses
  data_output <- .data %>% 
    select(all_of(responses), all_of(group)) %>% 
    pivot_longer(cols = all_of(responses), names_to = "response", values_to = "value") %>% 
    summarise(
      Resp = sum(value, na.rm = TRUE),
      .by = all_of(new_group)) %>% 
    mutate(
      {{nDV_name}} := sum(Resp, na.rm = TRUE),
      .by = all_of(group)) %>% 
    pivot_wider(names_from = response, values_from = Resp)

  return(data_output)

}
chenyu-psy commented 1 month ago

This function should be applicable to all multinomial distribution data: https://github.com/chenyu-psy/smartr/blob/main/R/agg_multinomial.R

GidonFrischkorn commented 1 month ago

For now, I have decided not to implement this only for the m3, but I have created a discussion in the bmm repository: #236