Skip to content

Commit

Permalink
update output
Browse files Browse the repository at this point in the history
  • Loading branch information
qinyun-lin committed May 6, 2024
1 parent 3c96944 commit 58aa69e
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
10 changes: 5 additions & 5 deletions R/helper_output_print.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down
1 change: 1 addition & 0 deletions R/test_cop.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions R/test_pse.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}

Expand Down
12 changes: 6 additions & 6 deletions R/tkonfound.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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){
Expand Down Expand Up @@ -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") {
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test-test_cop.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
7 changes: 4 additions & 3 deletions tests/testthat/test-test_pse.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,17 @@ 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.",
"",
"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."
Expand Down

0 comments on commit 58aa69e

Please sign in to comment.