Skip to content

Commit

Permalink
Merge pull request #100 from egouldo/76-transformation_tbl
Browse files Browse the repository at this point in the history
Move transformation_tbl into pkg dataset \document
  • Loading branch information
egouldo authored Aug 10, 2024
2 parents ccbcadb + 410be7b commit c28bb52
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 24 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
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.3.0
Version: 2.3.0.9000
Authors@R: c(
person("Elliot", "Gould", , "elliot.gould@unimelb.edu.au", role = c("aut", "cre"),
comment = c(ORCID = "https://orcid.org/0000-0002-6585-538X")),
Expand Down
34 changes: 11 additions & 23 deletions R/clean_response_transformation.R
Original file line number Diff line number Diff line change
@@ -1,34 +1,22 @@
#' Clean response transformation variable
#' @description Cleans the response transformation variable to the names of the back-transformation functions
#'
#' @param response_transformation A character vector with the
#' @param response_transformation A character vector with the response transformation values
#' @param transformation_tbl A tibble of the response transformation values `transformation_orig` and their cleaned names `cleaned_transformation`
#'
#'
#' @return A character vector of cleaned response transformation values equal to the required `transformation` values in `conversion()`
#' @export
#'
#' @details
#' The `transformation_tbl` is a tibble of the response transformation values `transformation_orig` and their cleaned
#' names `cleaned_transformation`. The `transformation_orig` values are the original response transformation values
#' used by the analyst. The `cleaned_transformation` values are the cleaned response transformation values that are equal to the required `transformation` values in [conversion()].
#' The user can supply an alternate table of transformations depending on what is required for the back-transformation functions.
#' @family back-transformation functions
clean_response_transformation <- function(response_transformation) {
clean_response_transformation <- function(response_transformation,
transformation_tbl = ManyEcoEvo:::transformation_tbl) {
original_data <- tibble(transformation_orig = response_transformation)

transformation_tbl <- tribble(
~transformation_orig, ~cleaned_transformation,
"^2", "square",
"power2", "square",
"^3", "cube",
"power3", "cube",
"squared", "square",
"cubed", "cube",
"scaled and centered", "identity",
"scaling and centering", "identity",
"mean centered and standardized", "identity",
"log", "log",
"orderNorm", NA, # TODO, ensure that this is the best behaviour - we need to exclude this first, rather than let it through here.. because else it gets passed through identity_back() inside conversion()
"divided.by.14", "divided.by.14",
"square.root", "square_root",
"back.transformed", "back.transformed",
"z.score", "identity",
"(power3)/100", "(power3)/100"
) # TODO double-check treatment of z.score

out <- original_data %>%
left_join(transformation_tbl) %>%
select(cleaned_transformation) %>% # TODO WHAT ABOUT MISSING NON-STANDARD TRANSFORMATIONS??
Expand Down
Binary file modified R/sysdata.rda
Binary file not shown.
23 changes: 23 additions & 0 deletions data-raw/create_internal_pkg_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,28 @@ prediction_ids <- tibble::tribble(
"Cessnock-1-1-1"
) # TODO ask HF where/how derived (used data pasta to copy from HF's files)

# ------ Create transformation_tbl -----

transformation_tbl <- tribble(
~transformation_orig, ~cleaned_transformation,
"^2", "square",
"power2", "square",
"^3", "cube",
"power3", "cube",
"squared", "square",
"cubed", "cube",
"scaled and centered", "identity",
"scaling and centering", "identity",
"mean centered and standardized", "identity",
"log", "log",
"orderNorm", NA, # TODO, ensure that this is the best behaviour - we need to exclude this first, rather than let it through here.. because else it gets passed through identity_back() inside conversion()
"divided.by.14", "divided.by.14",
"square.root", "square_root",
"back.transformed", "back.transformed",
"z.score", "identity",
"(power3)/100", "(power3)/100"
)


# ------- Write data internally -------

Expand All @@ -374,6 +396,7 @@ usethis::use_data(expert_subset,
collinearity_subset,
prediction_ids,
effect_ids,
transformation_tbl,
internal = TRUE,
overwrite = TRUE
)

0 comments on commit c28bb52

Please sign in to comment.