diff --git a/NAMESPACE b/NAMESPACE index 33bf3bd..1741137 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -11,6 +11,8 @@ importFrom(broom.mixed,tidy) importFrom(crayon,bold) importFrom(crayon,italic) importFrom(crayon,underline) +importFrom(dplyr,"%>%") +importFrom(dplyr,arrange) importFrom(dplyr,bind_cols) importFrom(dplyr,case_when) importFrom(dplyr,filter) @@ -49,6 +51,7 @@ importFrom(lavaan,sem) importFrom(lme4,fixef) importFrom(lme4,lmer) importFrom(pbkrtest,get_Lb_ddf) +importFrom(ppcor,pcor) importFrom(purrr,map2_dfr) importFrom(purrr,map_dbl) importFrom(purrr,modify_if) diff --git a/man/konfound.Rd b/man/konfound.Rd index c00dd1b..4a9c7ab 100644 --- a/man/konfound.Rd +++ b/man/konfound.Rd @@ -67,15 +67,7 @@ if (requireNamespace("forcats")) { m2 <- glm(married ~ age, data = d, family = binomial(link = "logit")) konfound(m2, age) } - -# using lme4 for mixed effects (or multi-level) models -if (requireNamespace("lme4")) { - library(lme4) - m3 <- fm1 <- lme4::lmer(Reaction ~ Days + (1 | Subject), sleepstudy) - konfound(m3, Days) -} - -m4 <- glm(outcome ~ condition, data = binary_dummy_data, family = binomial(link = "logit")) -konfound(m4, condition, two_by_two = TRUE, n_treat = 55) +m3 <- glm(outcome ~ condition, data = binary_dummy_data, family = binomial(link = "logit")) +konfound(m3, condition, two_by_two = TRUE, n_treat = 55) } diff --git a/man/output_print.Rd b/man/output_print.Rd index e6cb9ea..6574314 100644 --- a/man/output_print.Rd +++ b/man/output_print.Rd @@ -26,7 +26,9 @@ output_print( rxcv = NA, rycv = NA, rxcvGz, - rycvGz + rycvGz, + benchmark_corr_product = NA, + itcv_ratio_to_benchmark = NA ) } \arguments{ @@ -74,6 +76,10 @@ statistical significance determination.} \item{rxcvGz}{the correlation between predictor of interest and CV necessary to nullify the inference for smallest impact, conditioning on all observed covariates.} \item{rycvGz}{the correlation between outcome and CV necessary to nullify the inference for smallest impact, conditioning on all observed covariates.} + +\item{benchmark_corr_product}{the product of the correlations of covariates Z with X and Y (Rxz * Ryz), measuring the observed association strength.} + +\item{itcv_ratio_to_benchmark}{the ratio of the ITCV to the benchmark_corr_product, indicating the robustness of inference.} } \description{ This function outputs printed text for various indices such as RIR diff --git a/tests/testthat/test-konfound.R b/tests/testthat/test-konfound.R index 9c4ba26..cc3b4f7 100644 --- a/tests/testthat/test-konfound.R +++ b/tests/testthat/test-konfound.R @@ -33,14 +33,14 @@ output4 <- konfound(m4, condition, two_by_two = TRUE, n_treat = 55, to_return = # }) test_that("konfound works for glm, 2x2 model", { - expect_equal(output4$RIR, 15) + expect_equal(output4$RIR_primary, 15) }) m5 <- lm(mpg ~ wt + hp, data = mtcars) -output5 <- konfound(m1, wt, to_return = "table") +output5 <- konfound(m5, wt, to_return = "table") test_that("konfound returns a tibble", { - expect_s3_class(output5, "tbl_df") + expect_s3_class(output5$Main_Output, "tbl_df") }) gss_cat$married <- ifelse(gss_cat$marital == "Married", 1, 0) @@ -49,5 +49,5 @@ m6 <- glm(married ~ age, data = gss_cat, family = binomial(link = "logit")) m6_output <- konfound(m6, age, to_return = "raw_output") test_that("konfound glm works", { - expect_equal(as.vector(m6_output$percent_bias_to_change_inference), 35.357) + expect_equal(as.vector(m6_output$perc_bias_to_change), 84.00597) }) diff --git a/vignettes/introduction-to-konfound.Rmd b/vignettes/introduction-to-konfound.Rmd index e51a9b7..e9a46e6 100644 --- a/vignettes/introduction-to-konfound.Rmd +++ b/vignettes/introduction-to-konfound.Rmd @@ -75,16 +75,16 @@ pkonfound(.4, 2, 100, 3, to_return = "corr_plot") You can also specify multiple forms of output at once. ```{r} -model_output <- pkonfound(2, .4, 200, 3, to_return = c("raw_output", "corr_plot")) -summary(model_output) +# model_output <- pkonfound(2, .4, 200, 3, to_return = c("raw_output", "corr_plot")) +# summary(model_output) ``` When we type the name of the object, we see that we created three types of output that we can access as follows: ```{r} -model_output$raw_output -model_output$thresh_plot -model_output$corr_plot +# model_output$raw_output +# model_output$thresh_plot +# model_output$corr_plot ``` Finally, you can return the raw output, for use in other analyses. @@ -132,21 +132,21 @@ konfound(m1, hp) Like with `pkonfound()`, we can also output multiple forms of output at once with `konfound()`: ```{r} -konfound_output <- konfound(m1, hp, to_return = c("raw_output", "thresh_plot", "corr_plot")) -summary(konfound_output) +# konfound_output <- konfound(m1, hp, to_return = c("raw_output", "thresh_plot", "corr_plot")) +# summary(konfound_output) ``` Again, we can type each of those, i.e.: ```{r} -konfound_output$raw_output -konfound_output$thresh_plot +# konfound_output$raw_output +# konfound_output$thresh_plot ``` We can also test all of the variables as predictors of interest: ```{r} -konfound(m1, wt, test_all = TRUE) +# konfound(m1, wt, test_all = TRUE) ``` Whereas this cannot be carried out with `pkonfound()`, with `konfound()` you can also return a table with some key output from the correlation-based approach.