-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from egouldo/67-model-params
Extract model params from supported models
- Loading branch information
Showing
28 changed files
with
1,198 additions
and
1,133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
^.*\.Rproj$ | ||
^\.Rproj\.user$ | ||
_targets.R | ||
_targets/ | ||
|
||
^_pkgdown\.yml$ | ||
^docs$ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: ManyEcoEvo | ||
Title: Meta-analyse data from 'Many-Analysts' style studies | ||
Version: 2.0.0.9001 | ||
Version: 2.3.0 | ||
Authors@R: c(person(given = "Elliot", | ||
family = "Gould", | ||
email = "[email protected]", | ||
|
@@ -32,22 +32,23 @@ Imports: | |
tidyselect, | ||
pointblank, | ||
tibble, | ||
cli, | ||
data.table, | ||
forcats, | ||
fs, | ||
glue, | ||
here, | ||
lme4, | ||
metafor, | ||
cli, | ||
data.table, | ||
forcats, | ||
fs, | ||
glue, | ||
here, | ||
lme4, | ||
metafor, | ||
naniar, | ||
magrittr, | ||
tidyr, | ||
rlang, | ||
purrr, | ||
tidyselect, | ||
tidyselect | ||
Suggests: | ||
targets, | ||
qs, | ||
broom.mixed, | ||
metaviz, | ||
ggeffects, | ||
|
@@ -66,7 +67,7 @@ Remotes: | |
daniel1noble/orchaRd, | ||
NightingaleHealth/ggforestplot | ||
Encoding: UTF-8 | ||
LazyData: true | ||
LazyData: false | ||
Roxygen: list(markdown = TRUE) | ||
RoxygenNote: 7.3.2 | ||
URL: https://github.com/egouldo/ManyEcoEvo, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#' Fit a multivariate meta-regression model | ||
#' | ||
#' @description Fit a multivariate meta-regression model that models the effect of peer-review ratings on the deviation from the meta-analytic mean (both continuous and categorical ratings), mean Sorensen's index, and/or whether the analysis uses a mixed effects model, or not. | ||
#' | ||
#' @param data_tbl Data for model fitting | ||
#' @param ... Additional arguments passed to `lmer` | ||
#' @param env Environment in which to evaluate the formula, defaults to the calling environment | ||
#' @param N threshold for the number of analyses that must have been conducted using mixed effects models to include the binary predictor `mixed_model` in the meta-regression. Defaults to 5. | ||
#' | ||
#' @return An object of class lmer. | ||
#' | ||
#' @export | ||
#' @importFrom rlang new_formula | ||
#' @importFrom rlang caller_env | ||
#' @importFrom rlang expr | ||
#' @importFrom rlang expr | ||
#' @importFrom lme4 lmer | ||
#' @importFrom pointblank test_col_vals_gte | ||
#' @import dplyr | ||
#' @import cli | ||
#' @details | ||
#' Depending on whether enough analyses in `data_tbl` have been conducted with the `mixed_model` variable, the function will fit a model with or without the predictor `mixed_model`. | ||
#' | ||
#' Expects the following columns in `data_tbl`: | ||
#' | ||
#' - `RateAnalysis`: continuous peer-review ratings | ||
#' - `PublishableAsIs`: categorical peer-review ratings | ||
#' - `mean_diversity_index`: mean Sorensen's index | ||
#' - `box_cox_abs_deviation_score_estimate`: response variable, Box-Cox transformed deviation from the meta-analytic mean effect-size for each analysis | ||
#' - `mixed_model`: binary variable indicating whether the analysis used a mixed effects model or not | ||
#' - `ReviewerId`: reviewer identifier | ||
fit_multivar_MA <- function(data_tbl, N = 5, ..., env = rlang::caller_env()){ | ||
|
||
data_tbl %>% | ||
pointblank::expect_col_exists(columns = c(box_cox_abs_deviation_score_estimate, | ||
RateAnalysis, PublishableAsIs, | ||
mean_diversity_index, | ||
ReviewerId, | ||
mixed_model)) | ||
# Define Models | ||
f1 <- rlang::new_formula(rlang::expr(box_cox_abs_deviation_score_estimate), | ||
rlang::expr(RateAnalysis + | ||
PublishableAsIs + | ||
mean_diversity_index + | ||
(1 | ReviewerId)), env = env) | ||
|
||
f2 <- rlang::new_formula(rlang::expr(box_cox_abs_deviation_score_estimate), | ||
rlang::expr(RateAnalysis + | ||
PublishableAsIs + | ||
mean_diversity_index + | ||
mixed_model + | ||
(1 | ReviewerId)), env = env) | ||
|
||
cli::cli_h2("Fitting multivariate meta-regression model") | ||
|
||
pass_threshold <- | ||
data_tbl %>% | ||
count(mixed_model) %>% | ||
pointblank::test_col_vals_gte(n, N) | ||
|
||
cur_group_bullets <- dplyr::cur_group() %>% | ||
transpose() %>% | ||
list_flatten() %>% | ||
enframe() %>% | ||
mutate(value = list_c(value)) %>% | ||
unite(group, everything(), | ||
sep = ": ") %>% | ||
pull(group) | ||
|
||
if (pass_threshold == TRUE) { | ||
cli::cli_alert_info(glue::glue("Presence of random effects in analyses ", | ||
cli::style_italic("included"), | ||
" as predictor in model for data subset:")) | ||
cli::cli_bullets(c(setNames(cur_group_bullets, rep("*",length(cur_group_bullets))))) | ||
} else { | ||
cli::cli_alert_info(glue::glue("Presence of random effects in analyses ", | ||
cli::style_italic("excluded"), | ||
" as predictor in model for data subset:")) | ||
cli::cli_bullets(c(setNames(cur_group_bullets, rep("*",length(cur_group_bullets))))) | ||
} | ||
|
||
#TODO MAKE SURE GIVES CORRECT EX | ||
f <- if (pass_threshold) f2 else f1 # MAKE SURE RETURNS APPROPIRATELY | ||
|
||
mod <- rlang::inject(lme4::lmer(!!f, data = data_tbl, ...)) | ||
|
||
return(mod) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.