Skip to content

Commit

Permalink
bug!: switch to rowwise() execution in meta_analyse_datasets()
Browse files Browse the repository at this point in the history
---

Whenever mapped functions were called inside `ifelse()` statements in mutate calls without grouping, the same dataset (i.e. the first value) of the list-column was getting passed over and over again. I think that's because `ifelse()` isn't vectorised... switched to rowwise approach described at <https://cran.r-project.org/web/packages/dplyr/vignettes/rowwise.html> to avoid this problem, but also to explicitly enforce rowwise functionality without having to explicitly group to permit generalisability #97
  • Loading branch information
egouldo committed Aug 29, 2024
1 parent 711fc52 commit f3bba09
Showing 1 changed file with 36 additions and 74 deletions.
110 changes: 36 additions & 74 deletions R/meta_analyse_datasets.R
Original file line number Diff line number Diff line change
Expand Up @@ -170,87 +170,49 @@ meta_analyse_datasets <- function(data, outcome_variable = NULL, outcome_SE = NU

out <-
data %>%
rowwise() %>%
dplyr::mutate(
effects_analysis =
purrr::pmap(
.l = list(
effects_analysis,
outcome_colname,
outcome_SE_colname
),
.f = rm_inf_na
)
effects_analysis = list(rm_inf_na(effects_analysis,
outcome_colname,
outcome_SE_colname))
) %>%
dplyr::mutate(
MA_mod =
purrr::pmap(
.l = list(effects_analysis,
outcome_colname,
outcome_SE_colname,
estimate_type),
.f = fit_MA_mv
),
effects_analysis =
ifelse(is.na(MA_mod),
NA,
purrr::pmap(
.l = list(effects_analysis, MA_mod, outcome_colname),
.f = calculate_deviation_score
)
),
effects_analysis =
ifelse(rlang::is_na(effects_analysis),
NA,
purrr::pmap(
.l = list(effects_analysis,
dataset,
outcome_SE_colname),
.f = box_cox_transform
)
),
MA_mod = list(fit_MA_mv(effects_analysis,
outcome_colname,
outcome_SE_colname,
estimate_type)),
effects_analysis = ifelse(
rlang::is_na(MA_mod),
NA,
list(calculate_deviation_score(effects_analysis,
MA_mod,
outcome_colname))
),
effects_analysis = ifelse(
rlang::is_na(effects_analysis),
NA,
list(box_cox_transform(effects_analysis,
dataset,
outcome_SE_colname))
),
sorensen_glm =
purrr::map(
.x = effects_analysis,
.f = ~ poss_fit_sorensen_glm(
data = .x
)
),
list(poss_fit_sorensen_glm(effects_analysis)),
box_cox_rating_cont =
purrr::map(
.x = effects_analysis,
.f = ~ fit_boxcox_ratings_cont(
data = .x,
outcome = box_cox_abs_deviation_score_estimate,
outcome_var = box_cox_var
)
),
list(poss_fit_boxcox_ratings_cont(effects_analysis,
box_cox_abs_deviation_score_estimate,
box_cox_var)),
box_cox_rating_cat =
purrr::map(
.x = effects_analysis,
.f = ~ poss_fit_boxcox_ratings_cat(
data = .x,
outcome = box_cox_abs_deviation_score_estimate,
outcome_var = box_cox_var,
interceptless = FALSE
)
),
list(poss_fit_boxcox_ratings_cat(effects_analysis,
box_cox_abs_deviation_score_estimate,
box_cox_var,
interceptless = FALSE)),
box_cox_rating_cat_no_int =
purrr::map(
.x = effects_analysis,
.f = ~ poss_fit_boxcox_ratings_cat(
data = .x,
outcome = box_cox_abs_deviation_score_estimate,
outcome_var = box_cox_var,
interceptless = TRUE
)
),
uni_mixed_effects =
purrr::map(
.x = effects_analysis,
.f = ~ fit_uni_mixed_effects(
data = .x
)
)
list(poss_fit_boxcox_ratings_cat(effects_analysis,
box_cox_abs_deviation_score_estimate,
box_cox_var,
interceptless = TRUE)),
uni_mixed_effects =
list(fit_uni_mixed_effects(effects_analysis))
)

# --- Fit Multivariate Models ---
Expand Down

0 comments on commit f3bba09

Please sign in to comment.