Skip to content

Commit 65eaa75

Browse files
committed
fix the test for updated output
1 parent 7badac4 commit 65eaa75

File tree

5 files changed

+46
-34
lines changed

5 files changed

+46
-34
lines changed

R/test_cop.R

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -334,24 +334,25 @@ fig <- ggplot2::ggplot(figTable, ggplot2::aes(x = figTable$ModelLabel)) +
334334

335335
if (to_return == "print") {
336336
cat(crayon::bold("Coefficient of Proportionality (COP):\n\n"))
337-
cat("This function calculates (Oster's) delta* and the exact value of delta.")
337+
cat("This function calculates a correlation-based coefficient of\nproportionality (delta) as well as Oster's delta*.")
338338
cat("\n")
339339
if (negest == 1) {
340340
cat("Using the absolute value of the estimated effect, result can be interpreted\nby symmetry.\n")
341341
}
342-
cat(sprintf("Delta* is %.3f (assuming no covariates in the baseline model M1),\nthe exact delta is %.3f, with a bias of %.3f%%.\n",
342+
cat("\n")
343+
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",
343344
delta_star, delta_exact, delta_pctbias))
344345
cat("\n")
345-
cat(sprintf("With delta*, the coefficient in the final model will be %.3f.\nWith the exact delta, the coefficient will be %.3f.\n",
346+
cat(sprintf("With delta*, the coefficient in the final model will be %.3f.\nWith the correlation-based delta, the coefficient will be %.3f.\n",
346347
eff_x_M3_oster, eff_x_M3))
347348
cat("\n")
348349
cat("Use to_return = \"raw_output\" to see more specific results and graphic\npresentation of the result.\n")
349350
cat("\n")
350-
cat("This function calculates a correlation-based based coefficient of\nproportionality (delta) as well as Oster's delta*.\n")
351+
cat("This function also calculates conditional RIR that invalidates the statistical inference.\n")
351352
cat("\n")
352-
cat(sprintf("If the replacement cases have a fixed value, then RIR = %.3f.\n", cond_RIR_fixedY))
353-
cat(sprintf("If the replacement cases follow a null distribution, then RIR = %.3f.\n", cond_RIR_null))
354-
cat(sprintf("If the replacement cases satisfy rxy|Z = 0, then RIR = %.3f.\n", cond_RIR_rxyz))
353+
cat(sprintf("If the replacement data points have a fixed value, then RIR = %.3f.\n", cond_RIR_fixedY))
354+
cat(sprintf("If the replacement data points follow a null distribution, then RIR = %.3f.\n", cond_RIR_null))
355+
cat(sprintf("If the replacement data points satisfy rxy|Z = 0, then RIR = %.3f.\n", cond_RIR_rxyz))
355356
}
356357

357358
}

R/test_pse.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ test_pse <- function(est_eff,
147147
cat(sprintf("The correlation between X and CV is %.3f, and the correlation between\nY and CV is %.3f.\n\n", rxcv, rycv))
148148
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))
149149
cat(sprintf("Including such CV, the coefficient changes to %.3f, and standard error\nis %.3f.\n\n", eff_x_M3, se_x_M3))
150-
cat("Use to_return = \"raw_ouput\" to see more specific results.")
150+
cat("Use to_return = \"raw_output\" to see more specific results.")
151151
}
152152

153153

tests/testthat/test-helper_output_print.R

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@ test_that("output_print produces the correct language when index is 'RIR' with e
2020
# Define expected lines
2121
expected_lines <- c(
2222
"Robustness of Inference to Replacement (RIR):",
23-
"TO INVALIDATE:",
24-
"",
2523
"RIR = 5",
2624
"",
2725
"The estimated effect is 0.6, and specified threshold for inference is 0.5.",
2826
"To invalidate the inference based on your estimate, 30% of the (0.6)",
2927
"estimate would have to be due to bias. This implies that to invalidate",
3028
"the inference one would expect to have to replace 5 (30%) observation",
31-
"with cases for which the effect is 0.1 (RIR = 5).",
29+
"with data points for which the effect is 0.1 (RIR = 5).",
3230
"",
3331
"See Frank et al. (2013) for a description of the method.",
3432
"",
@@ -64,15 +62,13 @@ test_that("output_print produces the correct language for 'TO SUSTAIN' when inde
6462
# Define expected lines
6563
expected_lines <- c(
6664
"Robustness of Inference to Replacement (RIR):",
67-
"TO SUSTAIN:",
68-
"",
6965
"RIR = 10",
7066
"",
7167
"The estimated effect is 0.3, and specified threshold for inference is 0.4.",
7268
"To reach that threshold, 20% of the (0.3) estimate would have to be due",
7369
"to bias. This implies that to sustain an inference one would expect to have",
74-
"to replace 10 (20%) observations with effect of 0.2 with cases with effect",
75-
"of 0.5 (RIR = 10).",
70+
"to replace 10 (20%) observations with effect of 0.2 with data points with",
71+
"effect of 0.5 (RIR = 10).",
7672
"",
7773
"See Frank et al. (2013) for a description of the method.",
7874
"",

tests/testthat/test-test_cop.R

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,25 @@ test_that("test_cop outputs the correct language and values when to_return is 'p
8282

8383
# Define expected lines
8484
expected_lines <- c(
85-
"This function calculates delta* and the exact value of delta.",
86-
"delta* is 0.387 (assuming no covariates in the baseline model M1), ",
87-
" the exact delta is 1.172, with a bias of -66.980%.",
88-
"With delta*, the coefficient in the final model will be 0.447. ",
89-
" With the exact delta, the coefficient will be 0.300.",
90-
"Use to_return = raw_ouput to see more specific results ",
91-
" and graphic presentation of the result.",
85+
"Coefficient of Proportionality (COP):",
86+
"",
87+
"This function calculates a correlation-based coefficient of",
88+
"proportionality (delta) as well as Oster's delta*.",
89+
"",
90+
"Delta* is 0.387 (assuming no covariates in the baseline model M1),",
91+
"the correlation-based delta is 1.172, with a bias of -66.980%.",
92+
"",
93+
"With delta*, the coefficient in the final model will be 0.447.",
94+
"With the correlation-based delta, the coefficient will be 0.300.",
95+
"",
96+
"Use to_return = \"raw_output\" to see more specific results and graphic",
97+
"presentation of the result.",
9298
"",
93-
"This function also calculates conditional RIR that ",
94-
" invalidates the statistical inference.",
95-
"If the replacement cases have a fixed value, then RIR = 80.03469 .",
96-
"If the replacement cases follow a null distribution, ",
97-
" then RIR = 55.31744 .",
98-
"If the replacement cases satisfy rxy|Z = 0, then RIR = 56.31727 .",
99-
""
99+
"This function also calculates conditional RIR that invalidates the statistical inference.",
100+
"",
101+
"If the replacement data points have a fixed value, then RIR = 80.035.",
102+
"If the replacement data points follow a null distribution, then RIR = 55.317.",
103+
"If the replacement data points satisfy rxy|Z = 0, then RIR = 56.317."
100104
)
101105

102106
# Check each line against expected

tests/testthat/test-test_pse.R

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,20 @@ test_that("test_pse print output is correct", {
7777
to_return <- "print"
7878

7979
# Expected string
80-
expected_output <- paste(
81-
"This function calculates the conditions that set the\n estimated effect approximately equal to the threshold\n while preserving the standard error.\nThe correlation between X and CV is 0.214,\n and the correlation between Y and CV is 0.313.\nConditional on the covariates, the correlation between X\n and CV is 0.248, and the correlation between Y and CV\n is 0.372.\nIncluding such CV, the coefficient changes to 0.097,\n and standard error is 0.054.\nUse to_return = raw_ouput to see more specific results.",
82-
sep = ""
80+
expected_output <- c(
81+
"This function calculates the conditions that set the estimated effect",
82+
"approximately equal to the threshold while preserving the standard error.",
83+
"",
84+
"The correlation between X and CV is 0.214, and the correlation between",
85+
"Y and CV is 0.313.",
86+
"",
87+
"Conditional on the covariates, the correlation between X and CV is 0.248,",
88+
"and the correlation between Y and CV is 0.372.",
89+
"",
90+
"Including such CV, the coefficient changes to 0.097, and standard error",
91+
"is 0.054.",
92+
"",
93+
"Use to_return = \"raw_output\" to see more specific results."
8394
)
8495

8596
# Capture the output of the print statement
@@ -88,9 +99,9 @@ test_that("test_pse print output is correct", {
8899
)
89100

90101
# Convert output array into a single string for easier grepl checking
91-
output_string <- paste(output, collapse = "\n")
102+
# output_string <- paste(output, collapse = "\n")
92103

93104
# Check if the output is as expected
94-
expect_equal(output_string, expected_output)
105+
expect_equal(output, expected_output)
95106
})
96107

0 commit comments

Comments
 (0)