Skip to content

[Improvement] The rm3 function can be improved to be more convenient #279

@chenyu-psy

Description

@chenyu-psy

I use this issue to collect all my suggestions for the rm3 function. New suggestions might be added in the future.

  1. It is great that the rm3 checks whether all the parameters used in the activation functions are provided. However, I don't think it's necessary to provide the b parameter, as it is fixed to be 0 by default.
  2. It would be more convenient if the rm3 allowed me to provide the entire formula rather than just the activation formula. If I remember correctly, there should be some inner functions in bmm that can extract the activation formulas from the entire formula.
  3. I attempted to use the rm3 function in the mutate function. It was not very convenient. I have provided my code below. I wonder if there is any way we can simplify the code.
data <- data_pars %>%
    mutate(b=0) %>% 
    mutate(
      pars = pmap(select(., all_of(param_names)), 
                  function(...) setNames(c(...), param_names))
    ) %>%
    # Generate the response variables
    mutate(
      results = map(
        pars,
        ~ rm3(
          n = 1,
          size = nResp,
          pars = .x,     
          m3_model = model_m3,
          act_funs = act_form
        )
      )
    ) %>% 
    select(-pars) %>% 
    # Convert each results matrix to a named vector
    mutate(
      results_vec = map(results, ~ setNames(as.numeric(.x[1, ]), colnames(.x)))
    ) %>%
    select(-results) %>%
    # Unnest, using the names from the matrix columns
    unnest_wider(results_vec)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions