MUCollective / multiverse

R package for creating explorable multiverse analysis
https://mucollective.github.io/multiverse/
GNU General Public License v3.0
62 stars 5 forks source link

Incorrect output for `expand()` when dealing with asymmetric trees #100

Open abhsarma opened 2 years ago

abhsarma commented 2 years ago

When dealing with asymmetric trees (see example below), the output of expand(M) is not accurate. For instance consider the following multiverse:

# a random simulated dataset
N = 100

df = tibble(
  score = rlnorm(N),
  pretest1 = round(runif(N) * 100),
  pretest2 = round(runif(N) * 100),
  reaction_time = rnorm(N, 5, 1),
  HR = round(rnorm(N, 90, 10)),
  fatigue = sample(seq(1:7), size = N, replace = TRUE)
)
fit = branch(model, 
         "normal" ~ glm(log(score) ~ pretest1 + pretest2 + 
                        branch(interaction, 
                               "yes" ~ reaction_time:HR,
                               "no" ~ reaction_time:HR) + 
                        fatigue, data = df, family = "gaussian"),
         "binomial" ~ glm(score ~ pretest1 + pretest2 + 
                          fatigue, data = df, family = "binomial")
      )

This multiverse consists of three distinct paths, but the table produced by expand() contains four. This is probably due to naively taking all possible combinations of options for each parameter

abhsarma commented 2 months ago

Not sure if there's a good solution for this. This is not a problem if assymetric trees are created through %when% or branch_assert, only when they are created through nested branch calls. Currently, I am providing a warning message if there are asymmetric trees due to nested branch calls as in the example above.