pkonfound() command,
available in the GitHub repository.needtworows = TRUE, particularly when
switch_trm is either TRUE or
FALSE.See heretkonfound() and implied table by estimates is generated by
test_sensitivity_ln()test_sensitivity_ln()konfound from github repositorylibrary(tidyverse)
library(htmltools)
library(evaluate)
library(githubinstall)
suppressMessages(gh_install_packages("konfound", ref = "newitcv_output", force = TRUE))
## Warning in fread(download_url, sep = "\t", header = FALSE, stringsAsFactors =
## FALSE, : Found and resolved improper quoting out-of-sample. First healed line
## 4848: <<Puriney honfleuR "Evening, honfleuR" by Seurat>>. If the fields are not
## quoted (e.g. field separator does not appear within any field), try quote="" to
## avoid this warning.
## Do you want to install the package (Y/n)?
## future (1.33.0 -> 1.33.1) [CRAN]
##
## The downloaded binary packages are in
## /var/folders/52/my2sfsnn1qs78nfvl14zyynh0000gn/T//Rtmpzv4Ct5/downloaded_packages
## ── R CMD build ─────────────────────────────────────────────────────────────────
##
checking for file ‘/private/var/folders/52/my2sfsnn1qs78nfvl14zyynh0000gn/T/Rtmpzv4Ct5/remotesac323f008e28/konfound-project-konfound-d93cbc3/DESCRIPTION’ ...
✔ checking for file ‘/private/var/folders/52/my2sfsnn1qs78nfvl14zyynh0000gn/T/Rtmpzv4Ct5/remotesac323f008e28/konfound-project-konfound-d93cbc3/DESCRIPTION’
##
─ preparing ‘konfound’:
##
checking DESCRIPTION meta-information ...
✔ checking DESCRIPTION meta-information
##
─ checking for LF line-endings in source and make files and shell scripts
##
─ checking for empty or unneeded directories
##
─ building ‘konfound_0.4.0.tar.gz’
##
##
library(konfound)
eff_thr = NA# Case 1: Linear
### invalidate
## eff_thr = NA
pkonfound(est_eff = -0.3, std_err = 0.01, n_obs = 5000, n_covariates = 10, alpha = .05, tails = 2, index = "RIR", nu = 0, model_type = "ols", eff_thr = NA, to_return = "print")
## Robustness of Inference to Replacement (RIR):
## TO INVALIDATE:
##
## RIR = 4673
##
## You entered an estimated effect of -0.3. To invalidate
## the inference of an effect using the threshold of -0.02 for
## statistical significance with alpha = 0.05, 93.465% of the
## (-0.3) estimate would have to be due to bias. This implies
## that to invalidate the inference one would expect to have to
## replace 4673 (93.465%) observations with cases for which the
## treatment effect is 0 (RIR = 4673).
##
## See Frank et al. (2013) for a description of the method.
##
## Citation: Frank, K.A., Maroulis, S., Duong, M., and Kelcey, B. (2013).
## What would it take to change an inference?
## Using Rubin's causal model to interpret the robustness of causal inferences.
## Education, Evaluation and Policy Analysis, 35 437-460.
## For other forms of output, run ?pkonfound and inspect the to_return argument
## For models fit in R, consider use of konfound().
eff_thr != NA (user-entered
threshold)## eff_thr != NA (user entered)
pkonfound(est_eff = -0.3, std_err = 0.01, n_obs = 5000, n_covariates = 10, alpha = .05, tails = 2, index = "RIR", nu = 0, model_type = "ols", eff_thr = 0.2, to_return = "print")
## Robustness of Inference to Replacement (RIR):
## TO INVALIDATE:
##
## RIR = 4673
##
## You entered an effect of -0.3, and specified a threshold
## for inference of 0.2. To invalidate the inference based on your
## estimate, 93.465% of the (-0.3) estimate would have to be due to
## bias. This implies that to invalidate the inference one would
## expect to have to replace 4673 (93.465%) observations with
## cases for which the treatment effect is 0 (RIR = 4673).
##
## See Frank et al. (2013) for a description of the method.
##
## Citation: Frank, K.A., Maroulis, S., Duong, M., and Kelcey, B. (2013).
## What would it take to change an inference?
## Using Rubin's causal model to interpret the robustness of causal inferences.
## Education, Evaluation and Policy Analysis, 35 437-460.
## For other forms of output, run ?pkonfound and inspect the to_return argument
## For models fit in R, consider use of konfound().
eff_thr = NA### sustain
## eff_thr = NA
pkonfound(est_eff = 0.003, std_err = 0.1, n_obs = 5000, n_covariates = 10, alpha = .05, tails = 2, index = "RIR", nu = 0, model_type = "ols", eff_thr = NA, to_return = "print")
## Robustness of Inference to Replacement (RIR):
## TO SUSTAIN:
##
## RIR = 4923
##
## You entered an estimated effect of 0.003. The threshold value for
## statistical significance is 0.196 (alpha = 0.05). To reach that
## threshold, 98.47% of the (0.003) estimate would have to be due to
## bias. This implies that to sustain an inference one would expect to
## have to replace 4923 (98.47%) observations with effect of 0 with
## cases with effect of 0.196 (RIR = 4923).
##
## See Frank et al. (2013) for a description of the method.
##
## Citation: Frank, K.A., Maroulis, S., Duong, M., and Kelcey, B. (2013).
## What would it take to change an inference?
## Using Rubin's causal model to interpret the robustness of causal inferences.
## Education, Evaluation and Policy Analysis, 35 437-460.
## For other forms of output, run ?pkonfound and inspect the to_return argument
## For models fit in R, consider use of konfound().
eff_thr != NA (user-entered
threshold)## eff_thr != NA (user entered)
pkonfound(est_eff = 0.09, std_err = 0.1, n_obs = 5000, n_covariates = 10, alpha = .05, tails = 2, index = "RIR", nu = 0, model_type = "ols", eff_thr = 0.2, to_return = "print")
## Robustness of Inference to Replacement (RIR):
## TO SUSTAIN:
##
## RIR = 2705
##
## You entered an effect size of 0.09, and specified a threshold
## for inference of 0.2. To reach that threshold, 54.092% of the
## (0.09) estimate would have to be due to bias. This implies
## that to sustain an inference one would expect to have to replace
## 2705 (54.092%) observations with effect of 0 with cases
## with effect of 0.196 (RIR = 2705).
##
## See Frank et al. (2013) for a description of the method.
##
## Citation: Frank, K.A., Maroulis, S., Duong, M., and Kelcey, B. (2013).
## What would it take to change an inference?
## Using Rubin's causal model to interpret the robustness of causal inferences.
## Education, Evaluation and Policy Analysis, 35 437-460.
## For other forms of output, run ?pkonfound and inspect the to_return argument
## For models fit in R, consider use of konfound().
changeSE = TRUE# Case 2: Non-linear
## Case 2-1: changeSE = TRUE, Invalidate
pkonfound(-0.3, 0.01, 5000, n_covariates = 0, alpha = .05, tails = 2, nu = 0, n_treat = 2500, switch_trm = TRUE, model_type = "logistic", to_return = "print")
## RIR = 220
##
## The table implied by the parameter estimates and sample sizes you entered:
##
## Fail Success
## Control 1157 1343
## Treatment 1344 1156
##
## The reported effect size = -0.300, SE = 0.010, p-value = 0.000.
## The SE has been adjusted to 0.057 to generate a real number in the
## implied table. Numbers in the table cells have been rounded
## to integers, which may slightly alter the estimated effect from
## the value originally entered.
##
## To invalidate the inference that the effect is different from 0
## (alpha = 0.050) one would need to replace 220 (16.37%) treatment failure
## cases with cases for which the probability of failure in the control
## group (46.28%) applies (RIR = 220). This is equivalent to transferring
## 118 cases from treatment failure to treatment success (Fragility = 118).
##
## Note that RIR = Fragility/[1-P(failure in the treatment group)]
##
## The transfer of 118 cases yields the following table:
##
## Fail Success
## Control 1157 1343
## Treatment 1226 1274
## Effect size = -0.111, SE = 0.057, p-value = 0.051.
## Indicate that this is based on t = estimated effect/standard error
## For other forms of output, run ?pkonfound and inspect the to_return argument
## For models fit in R, consider use of konfound().
changeSE = FALSE## Case 2-2: changeSE = FALSE, Invalidate
pkonfound(-0.3, 0.1, 5000, n_covariates = 10, alpha = .05, tails = 2, n_treat = 2500, switch_trm = TRUE, model_type = "logistic", to_return = "print")
## RIR = 207
##
## The table implied by the parameter estimates and sample sizes you entered:
##
## Fail Success
## Control 2246 254
## Treatment 2307 193
##
## The reported effect size = -0.300, and SE = 0.100, p-value = 0.003.
## Values have been rounded to the nearest integer. This may cause
## a little change to the estimated effect for the table.
##
## To invalidate the inference that the effect is different from 0
## (alpha = 0.050) one would need to replace 207 (8.97%) treatment failure
## cases with cases for which the probability of failure in the control
## group (89.84%) applies (RIR = 207). This is equivalent to transferring
## 21 cases from treatment failure to treatment success (Fragility = 21).
##
## Note that RIR = Fragility/[1-P(failure in the treatment group)]
##
## The transfer of 21 cases yields the following table:
##
## Fail Success
## Control 2246 254
## Treatment 2286 214
## Effect size = -0.189, SE = 0.097, p-value = 0.052.
## Indicate that this is based on t = estimated effect/standard error
## For other forms of output, run ?pkonfound and inspect the to_return argument
## For models fit in R, consider use of konfound().
changeSE = TRUE (where RIR_perc
exceeds 100%)## Case 2-3: changeSE = TRUE, Sustain
pkonfound(-0.03, 0.2, 50, n_covariates = 5, alpha = .005, tails = 2, nu = 0, n_treat = 25, switch_trm = TRUE, model_type = "logistic", to_return = "print")
## RIR = 21
##
## The table implied by the parameter estimates and sample sizes you entered:
##
## Fail Success
## Control 12 13
## Treatment 13 12
##
## The reported effect size = -0.030, SE = 0.200, p-value = 0.779.
## The SE has been adjusted to 0.566 to generate a real number in the
## implied table. Numbers in the table cells have been rounded
## to integers, which may slightly alter the estimated effect from
## the value originally entered.
##
## To reach the threshold that would sustain an inference that the
## effect is different from 0 (alpha = 0.005) one would need to replace 21
## (175.00%) treatment success cases with cases for which the probability of
## failure in the control group (48.00%) applies (RIR = 21). This is equivalent
## to transferring 10 cases from treatment success to treatment failure
## (Fragility = 10).
##
## Note that RIR = Fragility/[1-P(success in the treatment group)]
##
## Note the RIR exceeds 100%. Generating the transfer of 10 cases would
## require replacing more cases that are in the treatment success condition.
##
## The transfer of 10 cases yields the following table:
##
## Fail Success
## Control 12 13
## Treatment 23 2
## Effect size = -2.522, SE = 0.839, p-value = 0.004.
## Indicate that this is based on t = estimated effect/standard error
## For other forms of output, run ?pkonfound and inspect the to_return argument
## For models fit in R, consider use of konfound().
changeSE = FALSE## Case 2-4: changeSE = FALSE, Sustain
pkonfound(-0.03, 0.2, 500, n_covariates = 10, alpha = .05, tails = 2, nu = 0, n_treat = 250, switch_trm = TRUE, model_type = "logistic", to_return = "print")
## RIR = 24
##
## The table implied by the parameter estimates and sample sizes you entered:
##
## Fail Success
## Control 180 70
## Treatment 182 68
##
## The reported effect size = -0.030, and SE = 0.200, p-value = 0.841.
## Values have been rounded to the nearest integer. This may cause
## a little change to the estimated effect for the table.
##
## To reach the threshold that would sustain an inference that the
## effect is different from 0 (alpha = 0.050) one would need to replace 24
## (35.29%) treatment success cases with cases for which the probability of
## failure in the control group (72.00%) applies (RIR = 24). This is equivalent
## to transferring 17 cases from treatment success to treatment failure
## (Fragility = 17).
##
## Note that RIR = Fragility/[1-P(success in the treatment group)]
##
## The transfer of 17 cases yields the following table:
##
## Fail Success
## Control 180 70
## Treatment 199 51
## Effect size = -0.417, SE = 0.211, p-value = 0.049.
## Indicate that this is based on t = estimated effect/standard error
## For other forms of output, run ?pkonfound and inspect the to_return argument
## For models fit in R, consider use of konfound().
needtworows = T)needtworows = TRUE is a
relatively rare case. Additionally, there are constraints that prevent
invalidate_ob = TRUE when
needtworows = TRUE.alpha value (e.g.,
0.0001) combined with a small number of observations
(n_obs, e.g., fewer than 50) is a major factor leading to
needtworows = TRUE.thr_t,
which tends to make invalidate_ob = TRUE in almost all
cases.needtworows = TRUE scenario, finding a real case
that satisfies this condition might be challenging.n_obs is closely associated with
minse being greater than user_std_err.
Consequently, it is also difficult to find a real case where
changeSE = FALSE under the needtworows = TRUE
condition.needtworows = T, sustain,
changeSE = TRUE## Case 3: needtworows = T, Sustain, changeSE = T,
pkonfound(0.25, 0.5, 70, n_covariates = 20, alpha = .001, tails = 2, nu = 0, n_treat = 20, switch_trm = TRUE, model_type = "logistic", to_return = "print")
## RIR = 37
##
## The table implied by the parameter estimates and sample sizes you entered:
##
## Fail Success
## Control 27 23
## Treatment 10 10
##
## The reported effect size = 0.250, SE = 0.500, p-value = 0.763.
## The SE has been adjusted to 0.530 to generate a real number in the
## implied table. Numbers in the table cells have been rounded
## to integers, which may slightly alter the estimated effect from
## the value originally entered.
##
## The inference cannot be sustained merely by switching cases in
## only one treatment condition. Therefore, cases have been switched from
## treatment failure to treatment success and from control success to control failure.
## The final Fragility(= 17) and RIR(= 37) reflect both sets of changes.
## Please compare the after transfer table with the implied table.
##
## Fail Success
## Control 35 15
## Treatment 1 19
## Effect size = 3.792, SE = 1.071, p-value = 0.001.
## Indicate that this is based on t = estimated effect/standard error
## For other forms of output, run ?pkonfound and inspect the to_return argument
## For models fit in R, consider use of konfound().
needtworows = T,
sustain, changeSE = TRUE## Case 3: needtworows = T, Sustain, changeSE = T,
pkonfound(0.8, 0.2, 50, n_covariates = 20, alpha = .001, tails = 2, nu = 0, n_treat = 20, switch_trm = FALSE, model_type = "logistic", to_return = "print")
## RIR = 19
##
## The table implied by the parameter estimates and sample sizes you entered:
##
## Fail Success
## Control 19 11
## Treatment 8 12
##
## The reported effect size = 0.800, SE = 0.200, p-value = 0.120.
## The SE has been adjusted to 0.593 to generate a real number in the
## implied table. Numbers in the table cells have been rounded
## to integers, which may slightly alter the estimated effect from
## the value originally entered.
##
## The inference cannot be sustained merely by switching cases in
## only one treatment condition. Therefore, cases have been switched from
## control success to control failure and from treatment failure to treatment success.
## The final Fragility(= 12) and RIR(= 19) reflect both sets of changes.
## Please compare the after transfer table with the implied table.
##
## Fail Success
## Control 29 1
## Treatment 6 14
## Effect size = 4.215, SE = 1.128, p-value = 0.001.
## Indicate that this is based on t = estimated effect/standard error
## For other forms of output, run ?pkonfound and inspect the to_return argument
## For models fit in R, consider use of konfound().
needtworows = T & invalidate &
changeSE = TRUE else {
### when needtworows = T
### changeSE = T
cat(paste0(
sprintf("The inference cannot be invalidated merely by switching cases in"),
sprintf("\nonly one treatment condition. Therefore, cases have been switched from"),
c("\n"), transferway, c(" and from "),
transferway_extra, c("."), c("\n"),
sprintf("The final Fragility(= %d) and RIR(= %d)", final_solution$final_switch, RIR),
c(" reflect both sets of changes. \nPlease compare the after transfer table with the implied table.")
)
)
}
print option
(test="fisher")# 2 by 2 table: printed output
pkonfound(a = 35, b = 17, c = 17, d = 38, alpha = 0.05, switch_trm = T, test = "fisher", replace = "control", "to_return" = "print")
## Background Information:
## This function calculates the number of cases that would have to be replaced
## with zero effect cases (RIR) to invalidate an inference made about the association
## between the rows and columns in a 2x2 table.
## One can also interpret this as switches from one cell to another, such as from
## the treatment success cell to the treatment failure cell.
##
## Conclusion:
## To invalidate the inference, one would need to replace 14 treatment success
## cases for which the probability of failure in the control group applies (RIR = 14).
## This is equivalent to transferring 9 cases from treatment success to treatment failure.
## For the User-entered Table, the estimated odds ratio is 4.530, with p-value of 0.000:
##
## User-entered Table:
## Fail Success
## Control 35 17
## Treatment 17 38
##
##
## For the Transfer Table, the estimated odds ratio is 2.278, with p-value of 0.051:
## Transfer Table:
## Fail Success
## Control 35 17
## Treatment 26 29
##
## RIR:
## RIR = 14
## For other forms of output, run ?pkonfound and inspect the to_return argument
## For models fit in R, consider use of konfound().
raw_output option
(test="fisher")# 2 by 2 table: raw output
pkonfound(a = 35, b = 17, c = 17, d = 38, alpha = 0.05, switch_trm = T, test = "fisher", replace = "control", "to_return" = "raw_output")
## For interpretation, check out to_return = 'print'.
## $RIR_primary
## [1] 14
##
## $RIR_supplemental
## [1] 0
##
## $RIR_perc
## [1] 36.84211
##
## $fragility_primary
## [1] 9
##
## $starting_table
## Fail Success
## Control 35 17
## Treatment 17 38
##
## $final_table
## Fail Success
## Control 35 17
## Treatment 26 29
print option
(test="chisq")# 2 by 2 table: printed output
pkonfound(a = 35, b = 17, c = 17, d = 38, alpha = 0.05, switch_trm = T, test = "chisq", replace = "control", "to_return" = "print")
## Background Information:
## This function calculates the number of cases that would have to be replaced
## with zero effect cases (RIR) to invalidate an inference made about the association
## between the rows and columns in a 2x2 table.
## One can also interpret this as switches from one cell to another, such as from
## the treatment success cell to the treatment failure cell.
##
## Conclusion:
## To invalidate the inference, one would need to replace 15 treatment success
## cases for which the probability of failure in the control group applies (RIR = 15).
## This is equivalent to transferring 10 cases from treatment success to treatment failure.
## For the User-entered Table, the Pearson's chi square is 14.176, with p-value of 0.000:
##
## User-entered Table:
## Fail Success
## Control 35 17
## Treatment 17 38
##
##
## For the Transfer Table, the Pearson's chi square is 3.640, with p-value of 0.056:
## Transfer Table:
## Fail Success
## Control 35 17
## Treatment 27 28
##
## RIR:
## RIR = 15
## For other forms of output, run ?pkonfound and inspect the to_return argument
## For models fit in R, consider use of konfound().
raw_output option
(test="chisq")# 2 by 2 table: raw output
pkonfound(a = 35, b = 17, c = 17, d = 38, alpha = 0.05, switch_trm = T, test = "chisq", replace = "control", "to_return" = "raw_output")
## For interpretation, check out to_return = 'print'.
## $RIR_primary
## [1] 15
##
## $RIR_supplemental
## [1] 0
##
## $RIR_perc
## [1] 39.47368
##
## $fragility_primary
## [1] 10
##
## $starting_table
## Fail Success
## Control 35 17
## Treatment 17 38
##
## $final_table
## Fail Success
## Control 35 17
## Treatment 27 28
pkonfound should ideally
depend on the research context.t_obs might be
used to choose between upper or lower p-value tests. if (tails == 2) {
p_start <- (2 * (1 - pt(abs(final_solution$t_start), n_obs - n_covariates - 2)))
p_final <- (2 * (1 - pt(abs(final_solution$t_final), n_obs - n_covariates - 2)))
}
# For a one-tailed test (assuming upper tail)
else if (tails == 1 & t_obs > 0) {
p_start <- (1 - pt(final_solution$t_start, n_obs - n_covariates - 2))
p_final <- (1 - pt(final_solution$t_final, n_obs - n_covariates - 2))
}
# For a one-tailed test (assuming lower tail)
else if (tails == 1 & t_obs < 0) {
p_start <- (pt(final_solution$t_start, n_obs - n_covariates - 2))
p_final <- (pt(final_solution$t_final, n_obs - n_covariates - 2))
}
## 1-tail, lower tail
pkonfound(-0.03, 0.2, 50, n_covariates = 5, alpha = .005, tails = 1, nu = 0, n_treat = 25, switch_trm = TRUE, model_type = "logistic", to_return = "print")
## RIR = 19
##
## The table implied by the parameter estimates and sample sizes you entered:
##
## Fail Success
## Control 12 13
## Treatment 13 12
##
## The reported effect size = -0.030, SE = 0.200, p-value = 0.389.
## The SE has been adjusted to 0.566 to generate a real number in the
## implied table. Numbers in the table cells have been rounded
## to integers, which may slightly alter the estimated effect from
## the value originally entered.
##
## To reach the threshold that would sustain an inference that the
## effect is different from 0 (alpha = 0.005) one would need to replace 19
## (158.33%) treatment success cases with cases for which the probability of
## failure in the control group (48.00%) applies (RIR = 19). This is equivalent
## to transferring 9 cases from treatment success to treatment failure
## (Fragility = 9).
##
## Note that RIR = Fragility/[1-P(success in the treatment group)]
##
## Note the RIR exceeds 100%. Generating the transfer of 9 cases would
## require replacing more cases that are in the treatment success condition.
##
## The transfer of 9 cases yields the following table:
##
## Fail Success
## Control 12 13
## Treatment 22 3
## Effect size = -2.072, SE = 0.734, p-value = 0.004.
## Indicate that this is based on t = estimated effect/standard error
## For other forms of output, run ?pkonfound and inspect the to_return argument
## For models fit in R, consider use of konfound().
## 1-tail, upper tail
pkonfound(0.8, 0.25, 5000, n_covariates = 50, alpha = .05, tails = 1, nu = 0, n_treat = 2500, switch_trm = TRUE, model_type = "logistic", to_return = "print")
## RIR = 625
##
## The table implied by the parameter estimates and sample sizes you entered:
##
## Fail Success
## Control 52 2448
## Treatment 24 2476
##
## The reported effect size = 0.800, and SE = 0.250, p-value = 0.001.
## Values have been rounded to the nearest integer. This may cause
## a little change to the estimated effect for the table.
##
## To invalidate the inference that the effect is different from 0
## (alpha = 0.050) one would need to replace 625 (25.24%) treatment success
## cases with cases for which the probability of failure in the control
## group (2.08%) applies (RIR = 625). This is equivalent to transferring
## 13 cases from treatment success to treatment failure (Fragility = 13).
##
## Note that RIR = Fragility/[1-P(success in the treatment group)]
##
## The transfer of 13 cases yields the following table:
##
## Fail Success
## Control 52 2448
## Treatment 37 2463
## Effect size = 0.346, SE = 0.217, p-value = 0.055.
## Indicate that this is based on t = estimated effect/standard error
## For other forms of output, run ?pkonfound and inspect the to_return argument
## For models fit in R, consider use of konfound().