diff --git a/R/back_transformations.R b/R/back_transformations.R index 9b2254f..a7b90f4 100644 --- a/R/back_transformations.R +++ b/R/back_transformations.R @@ -25,12 +25,10 @@ log_back <- function(beta, se, sim) { original <- exp(simulated) %>% # exponential = inverse of log na.omit() m_est <- mean(original) - sd_est <- sd(original) - se_est <- sd_est / sqrt(length(original)) + se_est <- sd(original) quantiles <- quantile(original, c(0.025, 0.975), na.rm = TRUE) set <- data.frame(mean_origin = m_est, se_origin = se_est, - sd_origin = sd_est, lower = quantiles[[1]], upper = quantiles[[2]]) @@ -52,12 +50,10 @@ logit_back <- function(beta, se, sim) { original <- plogis(simulated) %>% # invlogit na.omit() m_est <- mean(original) - sd_est <- sd(original) - se_est <- sd_est / sqrt(length(original)) + se_est <- sd(original) quantiles <- quantile(original, c(0.025, 0.975), na.rm = TRUE) set <- data.frame(mean_origin = m_est, se_origin = se_est, - sd_origin = sd_est, lower = quantiles[[1]], upper = quantiles[[2]]) if (flatten_dbl(set) %>% @@ -77,12 +73,10 @@ probit_back <- function(beta, se, sim) { original <- pnorm(simulated) %>% # inv-probit na.omit() m_est <- mean(original) - sd_est <- sd(original) - se_est <- sd_est / sqrt(length(original)) + se_est <- sd(original) quantiles <- quantile(original, c(0.025, 0.975), na.rm = TRUE) set <- data.frame(mean_origin = m_est, se_origin = se_est, - sd_origin = sd_est, lower = quantiles[[1]], upper = quantiles[[2]]) @@ -103,12 +97,10 @@ inverse_back <- function(beta, se, sim) { original <- 1 / simulated %>% # inverse na.omit() m_est <- mean(original) - sd_est <- sd(original) - se_est <- sd_est / sqrt(length(original)) + se_est <- sd(original) quantiles <- quantile(original, c(0.025, 0.975), na.rm = TRUE) set <- data.frame(mean_origin = m_est, se_origin = se_est, - sd_origin = sd_est, lower = quantiles[[1]], upper = quantiles[[2]]) if (flatten_dbl(set) %>% @@ -128,12 +120,10 @@ square_back <- function(beta, se, sim) { original <- sqrt(simulated) %>% # inverse of x^2 na.omit() m_est <- mean(original) - sd_est <- sd(original) - se_est <- sd_est / sqrt(length(original)) + se_est <- sd(original) quantiles <- quantile(original, c(0.025, 0.975), na.rm = TRUE) set <- data.frame(mean_origin = m_est, se_origin = se_est, - sd_origin = sd_est, lower = quantiles[[1]], upper = quantiles[[2]]) @@ -154,12 +144,10 @@ cube_back <- function(beta, se, sim) { original <- pracma::nthroot(simulated, n = 3) %>% # inverse of x^3, use non-base to allow for -ve numbers na.omit() m_est <- mean(original) - sd_est <- sd(original) - se_est <- sd_est / sqrt(length(original)) + se_est <- sd(original) quantiles <- quantile(original, c(0.025, 0.975), na.rm = TRUE) set <- data.frame(mean_origin = m_est, se_origin = se_est, - sd_origin = sd_est, lower = quantiles[[1]], upper = quantiles[[2]]) if (flatten_dbl(set) %>% @@ -179,12 +167,10 @@ identity_back <- function(beta, se, sim) { # identity (typo) TODO original <- simulated %>% # no transformation na.omit() m_est <- mean(original) - sd_est <- sd(original) - se_est <- sd_est / sqrt(length(original)) + se_est <- sd(original) quantiles <- quantile(original, c(0.025, 0.975), na.rm = TRUE) set <- data.frame(mean_origin = m_est, se_origin = se_est, - sd_origin = sd_est, lower = quantiles[[1]], upper = quantiles[[2]]) if (flatten_dbl(set) %>% @@ -205,12 +191,10 @@ power_back <- function(beta, se, sim, n) { original <- pracma::nthroot(simulated, n = n) %>% # inverse of x^n, use non-base to allow for -ve numbers na.omit() m_est <- mean(original) - sd_est <- sd(original) - se_est <- sd_est/ sqrt(length(original)) + se_est <- sd(original) quantiles <- quantile(original, c(0.025, 0.975), na.rm = TRUE) set <- data.frame(mean_origin = m_est, se_origin = se_est, - sd_origin = sd_est, lower = quantiles[[1]], upper = quantiles[[2]]) if (flatten_dbl(set) %>% @@ -231,8 +215,7 @@ divide_back <- function(beta, se, sim, n) { original <- simulated * n %>% na.omit() m_est <- mean(original, na.rm = TRUE) - sd_est <- sd(original, na.rm = TRUE) - se_est <- sd_est / sqrt(length(original)) + se_est <- sd(original, na.rm = TRUE) quantiles <- quantile(original, c(0.025, 0.975), na.rm = TRUE @@ -240,7 +223,6 @@ divide_back <- function(beta, se, sim, n) { set <- data.frame( mean_origin = m_est, se_origin = se_est, - sd_origin = sd_est, lower = quantiles[[1]], upper = quantiles[[2]] ) @@ -264,12 +246,10 @@ square_root_back <- function(beta, se, sim) { original <- simulated^2 %>% na.omit() m_est <- mean(original) - sd_est <- sd(original) - se_est <- sd_est / sqrt(length(original)) + se_est <- sd(original) quantiles <- quantile(original, c(0.025, 0.975), na.rm = TRUE) set <- data.frame(mean_origin = m_est, se_origin = se_est, - sd_origin = sd_est, lower = quantiles[[1]], upper = quantiles[[2]]) if (flatten_dbl(set) %>% diff --git a/R/conversion.R b/R/conversion.R index bc84f58..2a05764 100644 --- a/R/conversion.R +++ b/R/conversion.R @@ -67,13 +67,16 @@ conversion <- function(beta, se, transformation, sim = 10000) { square_root_back(beta, se, sim) } else if (transformation == "(power3)/100") { x100 <- divide_back(beta, se, sim, 100) - cube_back(x100$mean_origin, x100$se_origin, sim = 1000) + cube_back(x100$mean_origin, x100$se_origin, sim) } else if (stringr::str_detect(transformation, "power")) { n <- str_split(transformation, "power") %>% pluck(1, 2) %>% as.numeric() if (rlang::is_na(n)) { - return(data.frame(mean_origin = NA, m_est = NA, se_origin = NA, sd_origin = NA, lower = NA, upper = NA)) + return(data.frame(mean_origin = NA, + se_origin = NA, + lower = NA, + upper = NA)) } else { power_back(beta, se, sim, n) } @@ -82,12 +85,18 @@ conversion <- function(beta, se, transformation, sim = 10000) { pluck(1, 3) %>% as.numeric() if (rlang::is_na(n)) { - return(data.frame(mean_origin = NA, m_est = NA, se_origin = NA, sd_origin = NA, lower = NA, upper = NA)) + return(data.frame(mean_origin = NA, + se_origin = NA, + lower = NA, + upper = NA)) } else { divide_back(beta, se, sim, n) } } else if (transformation == "double_transformation") { - return(data.frame(mean_origin = NA, m_est = NA, se_origin = NA, sd_origin = NA, lower = NA, upper = NA)) + return(data.frame(mean_origin = NA, + se_origin = NA, + lower = NA, + upper = NA)) } else { identity_back(beta, se, sim) # TODO change conditional logic to ensure strange transformations not put through here } diff --git a/R/log_transform.R b/R/log_transform.R index c4adb21..12b61f0 100644 --- a/R/log_transform.R +++ b/R/log_transform.R @@ -19,13 +19,11 @@ log_transform <- function(estimate = numeric(1L), na.omit() m_est <- mean(log_simulated) - sd_est <- sd(log_simulated) - std.error_est <- sd_est / sqrt(length(log_simulated)) + se_est <- sd(log_simulated) quantiles <- quantile(log_simulated, c(0.025, 0.975), na.rm = TRUE) out <- data.frame(mean_log = m_est, - se_log = std.error_est, - sd_log = sd_est, + se_log = se_est, lower = quantiles[[1]], upper = quantiles[[2]])