From 58aa69ef13ebcdfa4f576cd9aad829c53b686211 Mon Sep 17 00:00:00 2001 From: Qinyun Lin Date: Tue, 7 May 2024 00:20:11 +0200 Subject: [PATCH] update output --- R/helper_output_print.R | 10 +++++----- R/test_cop.R | 1 + R/test_pse.R | 4 ++-- R/tkonfound.R | 12 ++++++------ tests/testthat/test-test_cop.R | 3 ++- tests/testthat/test-test_pse.R | 7 ++++--- 6 files changed, 20 insertions(+), 17 deletions(-) diff --git a/R/helper_output_print.R b/R/helper_output_print.R index 9aca77e..efb8fa1 100644 --- a/R/helper_output_print.R +++ b/R/helper_output_print.R @@ -48,7 +48,7 @@ output_print <- function(n_covariates, cat("\n") cat(paste0("The estimated effect is ", round(est_eff, 3), ". To invalidate the inference of an effect using")) cat("\n") - cat(paste0("the threshold of ", round(beta_threshhold, 3), " for statistical significance with alpha = ", alpha, ", ", round(bias, 3), "% of")) + cat(paste0("the threshold of ", round(beta_threshhold, 3), " for statistical significance (with alpha = ", alpha, "), ", round(bias, 3), "% of")) cat("\n") cat(paste0("the (", round(est_eff, 3), ") estimate would have to be due to bias. This implies that to invalidate")) cat("\n") @@ -134,7 +134,7 @@ output_print <- function(n_covariates, cat("\n") cat("on all observed covariates in the model; signs are interchangeable). This is") cat("\n") - cat(paste0("based on a threshold of ", round(critical_r, 3), " for statistical significance (alpha = ", alpha, ").\n")) + cat(paste0("based on a threshold effect of ", round(critical_r, 3), " for statistical significance (alpha = ", alpha, ").\n")) cat("\n") cat("Correspondingly the impact of an omitted variable (as defined in Frank 2000) must be ") cat("\n") @@ -148,7 +148,7 @@ output_print <- function(n_covariates, cat("\n") cat("of interest (conditioning on all observed covariates in the model;") cat("\n") - cat(paste0("signs are interchangeable). This is based on a threshold of ", round(critical_r, 3), " for")) + cat(paste0("signs are interchangeable). This is based on a threshold effect of ", round(critical_r, 3), " for")) cat("\n") cat("statistical significance (alpha = ", alpha, ").\n", sep = "") cat("\n") @@ -164,7 +164,7 @@ output_print <- function(n_covariates, cat("\n") cat("of interest (conditioning on all observed covariates in the model;") cat("\n") - cat(paste0("signs are interchangeable). This is based on a threshold of ", round(beta_threshhold, 3))) + cat(paste0("signs are interchangeable). This is based on a threshold effect of ", round(beta_threshhold, 3))) cat("\n") cat("for statistical significance (alpha = ", alpha, ").\n", sep = "") cat("\n") @@ -180,7 +180,7 @@ output_print <- function(n_covariates, cat("\n") cat("on all observed covariates in the model; signs are interchageable).") cat("\n") - cat(paste0("This is based on a threshold of ", round(beta_threshhold, 3), " for statistical significance (alpha = ", alpha, ").\n")) + cat(paste0("This is based on a threshold effect of ", round(beta_threshhold, 3), " for statistical significance (alpha = ", alpha, ").\n")) cat("\n") cat("Correspondingly the impact of an omitted variable (as defined in Frank 2000) must be ") cat("\n") diff --git a/R/test_cop.R b/R/test_cop.R index 2a2430d..39a33bd 100644 --- a/R/test_cop.R +++ b/R/test_cop.R @@ -342,6 +342,7 @@ fig <- ggplot2::ggplot(figTable, ggplot2::aes(x = figTable$ModelLabel)) + cat("\n") cat(sprintf("Delta* is %.3f (assuming no covariates in the baseline model M1),\nthe correlation-based delta is %.3f, with a bias of %.3f%%.\n", delta_star, delta_exact, delta_pctbias)) + cat("Note that %bias = (delta* - delta) / delta.\n") cat("\n") cat(sprintf("With delta*, the coefficient in the final model will be %.3f.\nWith the correlation-based delta, the coefficient will be %.3f.\n", eff_x_M3_oster, eff_x_M3)) diff --git a/R/test_pse.R b/R/test_pse.R index fc495d2..24cf451 100644 --- a/R/test_pse.R +++ b/R/test_pse.R @@ -143,10 +143,10 @@ test_pse <- function(est_eff, } if (to_return == "print") { - cat("This function calculates the conditions that set the estimated effect\napproximately equal to the threshold while preserving the standard error.\n\n") + cat("This function calculates the correlations associated with the confound that \ngenerate an estimated effect that is approximately equal to the threshold \nwhile preserving the standard error.\n\n") cat(sprintf("The correlation between X and CV is %.3f, and the correlation between\nY and CV is %.3f.\n\n", rxcv, rycv)) cat(sprintf("Conditional on the covariates, the correlation between X and CV is %.3f,\nand the correlation between Y and CV is %.3f.\n\n", rxcvGz, rycvGz)) - cat(sprintf("Including such CV, the coefficient changes to %.3f, and standard error\nis %.3f.\n\n", eff_x_M3, se_x_M3)) + cat(sprintf("Including such a CV, the coefficient changes to %.3f, and standard error\nis %.3f.\n\n", eff_x_M3, se_x_M3)) cat("Use to_return = \"raw_output\" to see more specific results.") } diff --git a/R/tkonfound.R b/R/tkonfound.R index 03c5531..02a0b90 100644 --- a/R/tkonfound.R +++ b/R/tkonfound.R @@ -202,7 +202,7 @@ total_rate_final <- total_success_final / (total_fail_final + total_success_fina if (!allnotenough & final > 1) { conclusion1 <- paste0( - change, sprintf("one would need to replace %d ", RIR), RIRway, "data points") + change, sprintf("one would need to replace %d ", RIR), RIRway, " data points with data points") if (replace == "control") { conclusion1b <- paste0( @@ -214,13 +214,13 @@ total_rate_final <- total_success_final / (total_fail_final + total_success_fina conclusion1c <- paste0( sprintf("This is equivalent to transferring %d", final), - " data points from ", transferway, "." - ) + " data points from ", transferway, " (Fragility = ", final, ")." + ) } if (!allnotenough & final == 1) { conclusion1 <- paste0( - change, sprintf("one would need to replace %d ", RIR), RIRway, "data points") + change, sprintf("one would need to replace %d ", RIR), RIRway, " data points with data points") if (replace == "control") { conclusion1b <- paste0( @@ -232,7 +232,7 @@ total_rate_final <- total_success_final / (total_fail_final + total_success_fina conclusion1c <- paste0( sprintf("This is equivalent to transferring %d", final), - " data points from ", transferway, ".") + " data points from ", transferway, " (Fragility = ", final, ").") } if (allnotenough){ @@ -265,7 +265,7 @@ total_rate_final <- total_success_final / (total_fail_final + total_success_fina info1 <- "This function calculates the number of data points that would have to be replaced with" info2 <- "zero effect data points (RIR) to invalidate an inference made about the association" info3 <- "between the rows and columns in a 2x2 table." - info4 <- "One can also interpret this as switches from one cell to another, such as from the" + info4 <- "One can also interpret this as switches (Fragility) from one cell to another, such as from the" info5 <- "treatment success cell to the treatment failure cell." if (to_return == "raw_output") { diff --git a/tests/testthat/test-test_cop.R b/tests/testthat/test-test_cop.R index 44fd564..185da10 100644 --- a/tests/testthat/test-test_cop.R +++ b/tests/testthat/test-test_cop.R @@ -88,7 +88,8 @@ test_that("test_cop outputs the correct language and values when to_return is 'p "proportionality (delta) as well as Oster's delta*.", "", "Delta* is 0.387 (assuming no covariates in the baseline model M1),", - "the correlation-based delta is 1.172, with a bias of -66.980%.", + "the correlation-based delta is 1.172, with a bias of -66.980%.", + "Note that %bias = (delta* - delta) / delta.", "", "With delta*, the coefficient in the final model will be 0.447.", "With the correlation-based delta, the coefficient will be 0.300.", diff --git a/tests/testthat/test-test_pse.R b/tests/testthat/test-test_pse.R index 80aa35d..38db70b 100644 --- a/tests/testthat/test-test_pse.R +++ b/tests/testthat/test-test_pse.R @@ -78,8 +78,9 @@ test_that("test_pse print output is correct", { # Expected string expected_output <- c( - "This function calculates the conditions that set the estimated effect", - "approximately equal to the threshold while preserving the standard error.", + "This function calculates the correlations associated with the confound that ", + "generate an estimated effect that is approximately equal to the threshold ", + "while preserving the standard error.", "", "The correlation between X and CV is 0.214, and the correlation between", "Y and CV is 0.313.", @@ -87,7 +88,7 @@ test_that("test_pse print output is correct", { "Conditional on the covariates, the correlation between X and CV is 0.248,", "and the correlation between Y and CV is 0.372.", "", - "Including such CV, the coefficient changes to 0.097, and standard error", + "Including such a CV, the coefficient changes to 0.097, and standard error", "is 0.054.", "", "Use to_return = \"raw_output\" to see more specific results."