diff --git a/R/prepare_response_variables.R b/R/prepare_response_variables.R index 84165c9..d8f63eb 100644 --- a/R/prepare_response_variables.R +++ b/R/prepare_response_variables.R @@ -23,7 +23,7 @@ prepare_response_variables <- function(ManyEcoEvo, if (!is.null(dataset_standardise)) { stopifnot(is.character(dataset_standardise)) stopifnot(length(dataset_standardise) >= 1) - stopifnot(length(dataset_standardise) == length(unique(ManyEcoEvo$dataset))) + stopifnot(length(dataset_standardise) <= length(unique(ManyEcoEvo$dataset))) match.arg(dataset_standardise, choices = ManyEcoEvo$dataset, several.ok = TRUE) } @@ -84,10 +84,6 @@ prepare_response_variables <- function(ManyEcoEvo, )) } else { - process_response <- function(dat){ - dat #TODO replace dummy function with actual function - } - datasets_to_standardise <- tibble( dataset = dataset_standardise, fns = list(standardise_response) @@ -100,12 +96,12 @@ prepare_response_variables <- function(ManyEcoEvo, out <- out %>% ungroup() %>% left_join(datasets_to_standardise, by = "dataset") %>% - mutate(fns = coalesce(fns, list(process_response)), - data = pmap(.l = ., + mutate(fns = coalesce(fns, list(process_response))) %>% + mutate(data = pmap(.l = ., .f = pmap_prepare_response, estimate_type = estimate_type, param_table = param_table)) %>% - select(-fns) + select(-fns) #TODO drop ci cols or not?? } return(out) } diff --git a/R/standardise_response.R b/R/standardise_response.R index e34e815..be8edf7 100644 --- a/R/standardise_response.R +++ b/R/standardise_response.R @@ -16,6 +16,8 @@ NULL #' Standardise Response Variable #' @return A tibble of analyst data with standardised values contained in a list-column called 'back_transformed_data' #' @details +#' # `standardise_response()` +#' #' When the `estimate_type` is `"Zr"`, [standardise_response()] standardises #' effect-sizes with [est_to_zr()], assuming that the `beta_estimate` and #' `beta_SE` values have already been back-transformed to the appropriate scale. #TODO check this. @@ -120,10 +122,18 @@ standardise_response <- function(dat, #' @description #' This function generates the response data for meta-analysis without standardising the effect sizes / out-of-sample predictions. #' @describeIn process_analyst_data Process response data for meta-analysis but do not standardise effect-sizes -process_response <- function(dat, - estimate_type = NULL, - param_table = NULL, - dataset = NULL){ #TODO what to do about args in pmap_prepare_response? allow ... args in fns(x,y,z, ...)? +#' @details +#' # `process_response()` +#' +#' Formats tibbles in the list-column `back_transformed_data` to ensure that the +#' correct columns are present for meta-analysis, matching the outputs of +#' [standardise_response()]. For blue tit data `dat$back_transformed_data$fit` +#' and for eucalyptus data, `dat$back_transformed_data$estimate` is renamed `Z`. +#' `se.fit` is renamed `VZ`. +#' @import dplyr +#' @import purrr +#' @import tidyr +process_response <- function(dat, ...){ Z_names_lookup <- c(Z = "estimate", #blue tit Z = "fit", #eucalyptus @@ -135,5 +145,4 @@ process_response <- function(dat, rename, any_of(Z_names_lookup)), params = NA) - #TODO replace dummy function with actual function }