Skip to content

Commit

Permalink
Newitcv output (#83)
Browse files Browse the repository at this point in the history
* add missing dois

* Update README.md to include coding team meeting note link

* fix typo in title

* Update README.md

* change default to control group throughout

* fixed formatting issues with output

* Update helper_output_dataframe.R

The default assignment of function parameters retains the value "=", and when assigning values to the columns of the dplyr::tibble I chose to replace the assignment "=" with the value "<-", (this change can be retained or not).

* Update nonlinear_auxiliary.R

The main change comes from the assignment of variables with T changed to "TRUE", not all = changed to <-, the main principle is: function parameter assignment with "=", variable assignment for "<-". "

In addition, for the definition of the matrix "byrow = TRUE" this way usually use "=", instead of the assignment symbol <-. This is a way of passing a function parameter without using the assignment "<-" symbol.

* Update helper_plot_threshold.R

 change“ est_eff = est_eff,
  beta_threshold = beta_threshold”

to
  est_eff <- est_eff,
      beta_threshold <- beta_threshold

* Update test_cop.R

Maintain "=" for function parameter assignments and "<-" for variable assignments.

* Update test_pse.R

 Maintain "=" for function parameter assignments and "<-" for variable assignments.

* Update test_sensitivity_ln.R

T to TRUE;F to FALSE

* Update tkonfound.R

T to TRUE

* Update tkonfound_fig.R

T to TRUE; F to FALSE

* update nrow issue

* add CONTRIBUTING and update README; also change email for JR

* add CONTRIBUTING and update README; also change email for S narvaiz

* fix the bug pkonfound error #64

* fix bug error with thresh_plot output #63

* Update links in DESCRIPTION

* remove rounding in itcv calculation

* work on tests

* move

* minor edits to tests

* to close #65 and to close #70

* add tests

* update docs

* update docs

* update README

* add check badges

* setting covr up again

* undo lme4 edits

trying another approach

* Revert "undo lme4 edits"

This reverts commit 2810fd0.

* update Matrix depends

* update lme4 version

* update README

* edit description

* update tests and docs

* update testing with Qinyun

* get rid of test_all = TRUE

* remove test_all = TRUE

* remove test_all = TRUE

* patch to konfound to address test_all = TRUE error

* add pkgdown action

* address warnings in tests that were due to an unititialized column

* iterate version

* fix minor discrepancy with package name

* continue to update tests, remove unused code

* further enhancing tests

* add badges and update README

* address error in vignette

* remove mention of functionality to call multiple forms of output at once

* address error in mkonfound

* remove calling of multiple forms of output

* remove commented out code

* address NOTES in R CMD CHECK

* add a few more tests

* address note about class(flag_cov)

* work on documentation to address imports issue

* edits to JOSS paper in response to feedback from @fartist and @wjakethompson

* simplify the function test_sensitivity_ln

now almost all calculations are moved to subfunctions in nonlinear_auxiliary

* minor edits to DESCRIPTION, removing aes_string and data_frame to address warnings, and moving print output out of test_sensitivity_ln

* Update helper_output_print.R

round up 'r_con' for ITCV

* Update helper_output_print.R

* Update cop_pse_auxiliary.R(F - FALSE) (#78)

* Update cop_pse_auxiliary.R

* Update cop_pse_auxiliary.R

* Update concord1.R

* Update cop_pse_auxiliary.R

* Update helper_output_print.R

* Update helper_output_dataframe.R

* Update helper_plot_correlation.R

* Update helper_plot_threshold.R

* Update konfound-glm-dichotomous.R

* Update konfound-glm.R

* Update konfound-lm.R

* Update konfound-lmer.R

* Update konfound.R

* Update mkonfound-data.R

* Update mkonfound.R

* Update core-sensitivity-mkonfound.R

* Update pkonfound.R

* Update test_cop.R

* Update test_cop.R

* Update test_pse.R

* Update test_sensitivity.R

* Update test_sensitivity_ln.R

* Update tkonfound.R

* Update tkonfound_fig.R

* Update zzz.R

* Update helper_output_table.R

* Update nonlinear_auxiliary.R

* Update test_cop.R

* Update test_pse.R

* Update test_sensitivity_ln.R

* Update test_pse.R

* Update test_cop.R

* Update cop_pse_auxiliary.R

* Update concord1.R

* Update cop_pse_auxiliary.R

* Update core-sensitivity-mkonfound.R

* Update konfound-glm.R

* Update konfound-lmer.R

* Update mkonfound.R

* Update nonlinear_auxiliary.R

* Update zzz.R

* Update DESCRIPTION

* addressing namespace issue - trying to rewrite the NAMESPACE and docs

* delete dup doc file

* remove glue and lifecycle

* make edits to remove import lavaan and import ggplot2

* remove summary function

* remove summary function to simplify codebase and address remaining NAMESPACE issue

* Update paper.md

* Update paper.bib

* Update paper.bib

* Update paper.bib

* Update paper.bib

* Update paper.bib

* edits to paper.bib to address APA issues

* edits to the paper and .bib to related to issues 3 and 5 in #80

* minor edits to .bib

* Update CONTRIBUTING.md

* a few more edits to address formatting issues with the paper

* a few more minor edits to the paper after viewing the rendered PDF

* update README to link to CONTRIBUTING.md and minor edits to paper.md based on Ken's feedback

* Update helper_output_print.R

* Update CONTRIBUTING.md

* edits to paper.bib and paper.md in response to request from @fabian-s: openjournals/joss-reviews#5779 (comment)

* minor edit to .bib

* additional edits to .bib

* fix bug when single predictor and test_all == T

* minor copy edits to paper

* Update helper_output_print.R

* a few more edits in response to Ken's feedback

* Update test_sensitivity_ln.R

* Update helper_output_print.R

* Update helper_output_print.R

* Update helper_output_print.R

* Update helper_output_print.R

* Update helper_output_print.R

* remove mice and tibble as they are not used

* Revert "remove mice and tibble as they are not used"

This reverts commit 16cad9f.

* updates to links

* add Wei to DESCRIPTION, remove unused license

* edit license

* rename license

* Update helper_output_print.R

* Update helper_output_print.R

* Update helper_output_print.R

* Update helper_output_print.R

* Update helper_output_print.R

* Update helper_output_print.R

* Update helper_output_print.R

* Update helper_output_print.R

* Update helper_output_print.R

* Update helper_output_print.R

* Update helper_output_print.R

* Update helper_output_print.R

* Update helper_output_print.R

* Update helper_output_print.R

* Update helper_output_print.R

* Update helper_output_print.R

* Update helper_output_print.R

* Update helper_output_print.R

* Update helper_output_print.R

* Update helper_output_print.R

* Update helper_output_print.R

* Update helper_output_print.R

* Update konfound-lm.R

* Update konfound-lm.R

* Update konfound-lm.R

* Update konfound-lm.R

* Update konfound-lm.R

* Update helper_output_print.R

* edits in response to @fabian-s feedback on the paper

* Update helper_output_print.R

* Update helper_output_print.R

* Update helper_output_print.R

* Update test_sensitivity_ln.R

* Update test_sensitivity_ln.R

* Update test_sensitivity_ln.R

* Update test_sensitivity_ln.R

* super small edit to the paper - changing &beta so it appears correctly as β

* fix the bug when est_eff_start = 0 and needtworows

fix the bug when est_eff_start = 0 and needtworows

* update URL in README

* update urls

* CRAN submission

* Update CONTRIBUTING.md

* Update konfound.R

revised warning message for non-linear model in konfound

* update testing

no errors now in devtools::check()

* Revert "Merge branch 'master' into newitcv_output"

This reverts commit fc199f7, reversing
changes made to 04fbc43.

---------

Co-authored-by: jrosen48 <jmrosen48@gmail.com>
Co-authored-by: Bret Staudt Willet <bret.staudt.willet@gmail.com>
Co-authored-by: wwang93 <142034236+wwang93@users.noreply.github.com>
Co-authored-by: Joshua Rosenberg <jmrosenberg@utk.edu>
Co-authored-by: olivroy <52606734+olivroy@users.noreply.github.com>
Co-authored-by: Jihoon_Choi <50298939+JihoonChoi26@users.noreply.github.com>
  • Loading branch information
7 people authored Mar 19, 2024
1 parent 1b91a6b commit bcc0cf2
Show file tree
Hide file tree
Showing 10 changed files with 339 additions and 148 deletions.
85 changes: 41 additions & 44 deletions R/helper_output_print.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,68 +8,60 @@ output_print <- function(est_eff, beta_threshhold, bias = NULL, sustain = NULL,
cat("\n")
cat(paste0("RIR = ", round(recase, 3), "\n"))
cat("\n")
cat(paste0("You entered an estimated effect of ", round(est_eff, 3), ". To invalidate"))
cat(paste0("The estimated effect is ", round(est_eff, 3), ". To invalidate the inference of an effect using"))
cat("\n")
cat(paste0("the inference of an effect using the threshold of ", round(beta_threshhold, 3), " for"))
cat(paste0("the threshold of ", round(beta_threshhold, 3), " for statistical significance with alpha = ", alpha, ", ", round(bias, 3), "% of"))
cat("\n")
cat(paste0("statistical significance with alpha = ", alpha, ", ", round(bias, 3), "% of the"))
cat(paste0("the (", round(est_eff, 3), ") estimate would have to be due to bias. This implies that to invalidate"))
cat("\n")
cat(paste0("(", round(est_eff, 3), ") estimate would have to be due to bias. This implies"))
cat(paste0("the inference one would expect to have to replace ", round(recase, 3), " (", round(bias, 3), "%) observations"))
cat("\n")
cat("that to invalidate the inference one would expect to have to\n")
cat(paste0("replace ", round(recase, 3), " (", round(bias, 3), "%) observations with cases for which the"))
cat("\n")
cat(paste0("treatment effect is ", nu, " (RIR = ", round(recase, 3), ").\n"))
cat(paste0("with cases for which the treatment effect is ", nu, " (RIR = ", round(recase, 3), ").\n"))
cat("\n")
} else if ((abs(est_eff) > abs(beta_threshhold)) & is.na(eff_thr) == FALSE) {
cat("TO INVALIDATE:\n")
cat("\n")
cat(paste0("RIR = ", round(recase, 3), "\n"))
cat("\n")
cat(paste0("You entered an effect of ", round(est_eff, 3), ", and specified a threshold"))
cat("\n")
cat(paste0("for inference of ", round(eff_thr, 3), ". To invalidate the inference based on your"))
cat(paste0("The estimated effect is ", round(est_eff, 3), ", and specified threshold for inference is ", round(eff_thr, 3), "."))
cat("\n")
cat(paste0("estimate, ", round(bias, 3), "% of the (", round(est_eff, 3), ") estimate would have to be due to"))
cat(paste0("To invalidate the inference based on your estimate, ", round(bias, 3), "% of the (", round(est_eff, 3), ")"))
cat("\n")
cat(paste0("bias. This implies that to invalidate the inference one would"))
cat(paste0("estimate would have to be due to bias. This implies that to invalidate"))
cat("\n")
cat(paste0("expect to have to replace ", round(recase, 3), " (", round(bias, 3), "%) observations with"))
cat(paste0("the inference one would expect to have to replace ", round(recase, 3), " (", round(bias, 3), "%) observation"))
cat("\n")
cat(paste0("cases for which the treatment effect is ", nu, " (RIR = ", round(recase, 3), ").\n"))
cat(paste0("with cases for which the treatment effect is ", nu, " (RIR = ", round(recase, 3), ").\n"))
cat("\n")
} else if ((abs(est_eff) < abs(beta_threshhold)) & is.na(eff_thr) == TRUE) {
cat("TO SUSTAIN:\n", sep = "")
cat("\n")
cat(paste0("RIR = ", round(recase, 3), "\n"))
cat("\n")
cat(paste0("You entered an estimated effect of ", round(est_eff, 3), ". The threshold value for"))
cat(paste0("The estimated effect is ", round(est_eff, 3), ". The threshold value for statistical significance"))
cat("\n")
cat(paste0("statistical significance is ", round(beta_threshhold, 3), " (alpha = ", alpha, "). To reach that"))
cat(paste0("is ", round(beta_threshhold, 3), " (alpha = ", alpha, "). To reach that threshold, ", round(sustain, 3), "% of the (", round(est_eff, 3), ") estimate"))
cat("\n")
cat(paste0("threshold, ", round(sustain, 3), "% of the (", round(est_eff, 3), ") estimate would have to be due to"))
cat(paste0("would have to be due to bias. This implies to sustain an inference one would"))
cat("\n")
cat("bias. This implies that to sustain an inference one would expect to")
cat(paste0("expect to have to replace ", round(recase, 3), " (", round(sustain, 3), "%) observations with effect of ", nu, " with cases"))
cat("\n")
cat(paste0("have to replace ", round(recase, 3), " (", round(sustain, 3), "%) observations with effect of ", nu, " with\n"))
cat(paste0("cases with effect of ", round(beta_threshhold, 3), " (RIR = ", round(recase, 3), ").\n"))
cat(paste0("with effect of ", round(beta_threshhold, 3), " (RIR = ", round(recase, 3), ").\n"))
cat("\n")
} else if ((abs(est_eff) < abs(beta_threshhold)) & is.na(eff_thr) == FALSE) {
cat("TO SUSTAIN:\n", sep = "")
cat("\n")
cat(paste0("RIR = ", round(recase, 3), "\n"))
cat("\n")
cat(paste0("You entered an effect size of ", round(est_eff, 3), ", and specified a threshold"))
cat("\n")
cat(paste0("for inference of ", round(eff_thr, 3), ". To reach that threshold, ", round(sustain, 3), "% of the" ))
cat(paste0("The estimated effect is ", round(est_eff, 3), ", and specified threshold for inference is ", round(eff_thr, 3), "."))
cat("\n")
cat(paste0("(", round(est_eff, 3), ") estimate would have to be due to bias. This implies"))
cat(paste0("To reach that threshold, ", round(sustain, 3), "% of the (", round(est_eff, 3), ") estimate would have to be due"))
cat("\n")
cat("that to sustain an inference one would expect to have to replace ")
cat(paste0("to bias. This implies that to sustain an inference one would expect to have"))
cat("\n")
cat(paste0(round(recase, 3), " (", round(sustain, 3), "%) observations with effect of ", nu, " with cases"))
cat(paste0("to replace ", round(recase, 3), " (", round(sustain, 3), "%) observations with effect of ", nu, " with cases with effect"))
cat("\n")
cat(paste0("with effect of ", round(beta_threshhold, 3), " (RIR = ", round(recase, 3), ").\n"))
cat(paste0("of ", round(beta_threshhold, 3), " (RIR = ", round(recase, 3), ").\n"))
cat("\n")
} else if (est_eff == beta_threshhold) {
warning("The coefficient is exactly equal to the threshold.\n")
Expand Down Expand Up @@ -105,40 +97,39 @@ if (requireNamespace("htmltools", quietly = TRUE)) {
if (abs(obs_r) > abs(critical_r) & obs_r > 0) {
cat("The minimum impact of an omitted variable to invalidate an inference")
cat("\n")
cat(paste0("for a null hypothesis of 0 effect is based on a correlation of ", r_con))
cat(paste0("for a null hypothesis of 0 effect is based on a correlation of ", round(r_con, 3)))
cat("\n")
cat(paste0("with the outcome and at ", r_con, " with the predictor of interest (conditioning"))
cat(paste0("with the outcome and ", round(r_con, 3), " with the predictor of interest (conditioning"))
cat("\n")
cat(paste0("on all observed covariates in the model) based on a threshold of ", round(critical_r, 3)))
cat("on all observed covariates in the model; signs are interchangeable)")
cat("\n")
cat("for statistical significance (alpha = ", alpha, ").\n",
sep = "")
cat(paste0("based on a threshold 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")
cat(r_con, " X ", r_con, " = ", round(r_con^2, 3), " to invalidate an inference for a null hypothesis of 0 effect.\n", sep = "")
cat(round(r_con, 3), " X ", round(r_con, 3), " = ", round(r_con^2, 3), " to invalidate an inference for a null hypothesis of 0 effect.\n", sep = "")
} else if (abs(obs_r) > abs(critical_r) & obs_r < 0) {
cat("The minimum (in absolute value) impact of an omitted variable to")
cat("\n")
cat(paste0("invalidate an inference for a null hypothesis of 0 effect is based on"))
cat("\n")
cat(paste0("a correlation of ", -r_con, " with the outcome and at ", r_con, " with the predictor"))
cat(paste0("a correlation of ", -round(r_con, 3), " with the outcome and ", round(r_con, 3), " with the predictor"))
cat("\n")
cat("of interest (conditioning on all observed covariates in the model;")
cat("\n")
cat(paste0("signs are interchangeable) based on a threshold of ", round(beta_threshhold, 3), " for"))
cat(paste0("signs are interchangeable) based on a threshold of ", round(critical_r, 3), " for"))
cat("\n")
cat("statistical significance (alpha = ", alpha, ").\n", sep = "")
cat("\n")
cat("Correspondingly the impact of an omitted variable (as defined in Frank 2000) must be ")
cat("\n")
cat(-r_con, " X ", r_con, " = ", -round(r_con^2, 3), " to invalidate an inference for a null hypothesis of 0 effect.\n", sep = "")
cat(-round(r_con, 3), " X ", round(r_con, 3), " = ", -round(r_con^2, 3), " to invalidate an inference for a null hypothesis of 0 effect.\n", sep = "")
} else if (abs(obs_r) < abs(critical_r) & obs_r > 0) {
cat("The maximum impact (in absolute value) of an omitted variable to")
cat("\n")
cat("sustain an inference for a null hypothesis of 0 effect is based on")
cat("\n")
cat(paste0("a correlation of ", -r_con, " with the outcome an at ", r_con, " with the predictor"))
cat(paste0("a correlation of ", -round(r_con, 3), " with the outcome and ", round(r_con, 3), " with the predictor"))
cat("\n")
cat("of interest (conditioning on all observed covariates in the model;")
cat("\n")
Expand All @@ -148,24 +139,30 @@ if (requireNamespace("htmltools", quietly = TRUE)) {
cat("\n")
cat("Correspondingly the impact of an omitted variable (as defined in Frank 2000) must be ")
cat("\n")
cat(-r_con, " X ", r_con, " = ", -round(r_con^2, 3), " to sustain an inference for a null hypothesis of 0 effect.\n", sep = "")
cat(-round(r_con, 3), " X ", round(r_con, 3), " = ", -round(r_con^2, 3), " to sustain an inference for a null hypothesis of 0 effect.\n", sep = "")
} else if (abs(obs_r) < abs(critical_r) & obs_r < 0) {
cat("The maximum impact of an omitted variable to sustain an inference")
cat("\n")
cat(paste0("for a null hypothesis of 0 effect is based on a correlation of ", r_con))
cat(paste0("for a null hypothesis of 0 effect is based on a correlation of ", round(r_con, 3)))
cat("\n")
cat(paste0("with the outcome and at ", r_con, " with the predictor of interest (conditioning"))
cat(paste0("with the outcome and ", round(r_con, 3), " with the predictor of interest (conditioning"))
cat("\n")
cat(paste0("on all observed covariates in the model) based on a threshold of ", round(beta_threshhold, 3)))
cat("on all observed covariates in the model; signs are interchageable)")
cat("\n")
cat("for statistical significance (alpha = ", alpha, ").\n", sep = "")
cat(paste0("based on a threshold 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")
cat(r_con, " X ", r_con, " = ", round(r_con^2, 3), " to sustain an inference for a null hypothesis of 0 effect.\n", sep = "")
cat(round(r_con, 3), " X ", round(r_con, 3), " = ", round(r_con^2, 3), " to sustain an inference for a null hypothesis of 0 effect.\n", sep = "")
} else if (obs_r == critical_r) {
warning("The correlation is exactly equal to the threshold.\n")
}
cat("\n")
cat("For calculation of unconditional ITCV, request raw output. When using pkonfound(),")
cat("\n")
cat("additionally include the R2, sdx, and sdy as input.")
cat("\n")
cat("\n")
cat("See Frank (2000) for a description of the method.")
cat("\n")
cat("\n")
Expand Down
7 changes: 5 additions & 2 deletions R/konfound-lm.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ konfound_lm <- function(model_object, tested_variable_string, test_all, alpha, t
sdy <- unname(sqrt(diag(var(model_object$model)))[1])
R2 <- summary(model_object)$r.squared

if (test_all == FALSE) {
if (test_all == FALSE | n_covariates == 1) {
out <- test_sensitivity(
est_eff = est_eff,
std_err = std_err,
Expand All @@ -40,7 +40,10 @@ konfound_lm <- function(model_object, tested_variable_string, test_all, alpha, t
)
return(out)
} else {
message("Note that this output is calculated based on the correlation-based approach used in mkonfound()")
message("The mkonfound command is used which evaluates RIR in terms of a correlation-based approach
to support comparison among the robustness of the inferences across the covariates.
ITCV is for conditional correlations. To generate unconditional ITCV, use the pkonfound
command for each predictor separately.")
d <- data.frame(t = est_eff / std_err, df = (n_obs - n_covariates - 1))
o <- mkonfound(d, .data$t, .data$df)
term_names <- dplyr::select(tidy_output, var_name = .data$term) # remove the first row for intercept
Expand Down
2 changes: 1 addition & 1 deletion R/konfound.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ konfound <- function(model_object,
}

if (inherits(model_object, "glm") & two_by_two == FALSE) {
message("Note that for a non-linear model, impact threshold should not be interpreted.")
message("Note that if your model is a logistic regression, we recommend using the pkonfound command for logistic regression with manually entered parameter estimates and other quantities.")
message("Note that this is only an approximation. For exact results in terms of the number of cases that must be switched from treatment success to treatment failure to invalidate the inference see: https://msu.edu/~kenfrank/non%20linear%20replacement%20treatment.xlsm")
message("If a dichotomous independent variable is used, consider using the 2X2 table approach enabled with the argument two_by_two = TRUE")
output <- konfound_glm(
Expand Down
13 changes: 7 additions & 6 deletions R/nonlinear_auxiliary.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ getswitch <- function(table_bstart, thr_t, switch_trm, n_obs) {
b_tryall <- b - (b - 1) * (1 - as.numeric(switch_trm))
tryall_t <- get_t_kfnl(a_tryall, b_tryall, c_tryall, d_tryall)
tryall_est <- log(a_tryall*d_tryall/c_tryall/b_tryall)
allnotenough <- isTRUE(thr_t - tryall_t > 0 & tryall_est*est_eff_start > 0)
allnotenough <- isTRUE(thr_t - tryall_t > 0 &
tryall_est * est_eff_start >= 0)
}
if (t_start > thr_t) {
# transfer cases from A to B or D to C to decrease odds ratio
Expand All @@ -139,7 +140,7 @@ getswitch <- function(table_bstart, thr_t, switch_trm, n_obs) {
b_tryall <- b + (a - 1) * (1 - as.numeric(switch_trm))
tryall_t <- get_t_kfnl(a_tryall, b_tryall, c_tryall, d_tryall)
tryall_est <- log(a_tryall*d_tryall/c_tryall/b_tryall)
allnotenough <- isTRUE(tryall_t - thr_t > 0 & tryall_est*est_eff_start > 0)
allnotenough <- isTRUE(tryall_t - thr_t > 0 & tryall_est*est_eff_start >= 0)
}

### run following if transfering one row is enough
Expand Down Expand Up @@ -388,7 +389,7 @@ if (!dcroddsratio_start) {
b_tryall <- b - (b - 1) * (1 - as.numeric(switch_trm))
tryall_p <- chisq_p(a_tryall, b_tryall, c_tryall, d_tryall)
tryall_est <- log(a_tryall*d_tryall/c_tryall/b_tryall)
allnotenough <- isTRUE((thr_p-tryall_p)*tryall_est< 0 & tryall_est*est > 0)
allnotenough <- isTRUE((thr_p-tryall_p)*tryall_est< 0 & tryall_est*est >= 0)
}
if (dcroddsratio_start ) {
# transfer cases from A to B or D to C to decrease odds ratio
Expand All @@ -398,7 +399,7 @@ if (dcroddsratio_start ) {
b_tryall <- b + (a - 1) * (1 - as.numeric(switch_trm))
tryall_p <- chisq_p(a_tryall, b_tryall, c_tryall, d_tryall)
tryall_est <- log(a_tryall*d_tryall/c_tryall/b_tryall)
allnotenough <- isTRUE((thr_p-tryall_p)*tryall_est> 0 & tryall_est*est > 0)
allnotenough <- isTRUE((thr_p-tryall_p)*tryall_est> 0 & tryall_est*est >= 0)
}

### run following if transfering one row is enough
Expand Down Expand Up @@ -732,7 +733,7 @@ getswitch_fisher <- function(a, b, c, d, thr_p = 0.05, switch_trm = T){
if (d_tryall == 0) {d_tryall <- d_tryall + 0.5}
tryall_p <- fisher_p(a_tryall, b_tryall, c_tryall, d_tryall)
tryall_est <- log(a_tryall*d_tryall/c_tryall/b_tryall)
allnotenough <- isTRUE((thr_p-tryall_p)*tryall_est< 0 & tryall_est*est > 0)
allnotenough <- isTRUE((thr_p-tryall_p)*tryall_est< 0 & tryall_est*est >= 0)
}
if (dcroddsratio_start ) {
# transfer cases from A to B or D to C to decrease odds ratio
Expand All @@ -746,7 +747,7 @@ getswitch_fisher <- function(a, b, c, d, thr_p = 0.05, switch_trm = T){
if (d_tryall == 0) {d_tryall <- d_tryall + 0.5}
tryall_p <- fisher_p(a_tryall, b_tryall, c_tryall, d_tryall)
tryall_est <- log(a_tryall*d_tryall/c_tryall/b_tryall)
allnotenough <- isTRUE((thr_p-tryall_p)*tryall_est> 0 & tryall_est*est > 0)
allnotenough <- isTRUE((thr_p-tryall_p)*tryall_est> 0 & tryall_est*est >= 0)
}

### run following if transfering one row is enough
Expand Down
2 changes: 1 addition & 1 deletion R/test_sensitivity.R
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ if (signsuppression == 1) warning("signsuppression is defined by a threshold of
itcv <- signITCV * abs(act_r - critical_r) / (1 + mp * abs(critical_r))

# finding correlation of confound to invalidate / sustain inference
r_con <- round(sqrt(abs(itcv)), 3)
r_con <- sqrt(abs(itcv))

## calculate the unconditional ITCV if user inputs sdx, sdy and R2
if (!is.na(sdx) & !is.na(sdy) & !is.na(R2) & (n_covariates > 0)) {
Expand Down
Loading

0 comments on commit bcc0cf2

Please sign in to comment.