From 1a0710569c9ea78a096e0d53fe2d49e02f725a5d Mon Sep 17 00:00:00 2001 From: George Perrett Date: Fri, 24 May 2024 15:18:43 -0400 Subject: [PATCH] bug fix: unit test --- DESCRIPTION | 2 +- NAMESPACE | 1 + R/plot_moderators.R | 2 +- man/table_moderator_c_bin.Rd | 38 ++++++++++++++++++++++++++++++++++++ renv.lock | 29 +++++++++++++++------------ 5 files changed, 58 insertions(+), 14 deletions(-) create mode 100644 man/table_moderator_c_bin.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 694fdce..68d62b1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -13,7 +13,7 @@ URL: https://priism-center.github.io/plotBart/, https://github.com/priism-center BugReports: https://github.com/priism-center/plotBart/issues Encoding: UTF-8 LazyData: true -RoxygenNote: 7.2.0 +RoxygenNote: 7.3.1 Depends: R (>= 2.10), bartCause (>= 1.0.4), diff --git a/NAMESPACE b/NAMESPACE index aec0fbf..1da8adb 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -22,6 +22,7 @@ export(plot_trank) export(plot_waterfall) export(print_balance) export(print_covariance) +export(table_moderator_c_bin) import(bartCause) import(dplyr) import(ggplot2) diff --git a/R/plot_moderators.R b/R/plot_moderators.R index d80260e..aa797e8 100644 --- a/R/plot_moderators.R +++ b/R/plot_moderators.R @@ -659,6 +659,7 @@ rpart_ggplot_ <- function(.model){ #' @import dplyr #' @importFrom bartCause extract #' @importFrom rpart rpart +#' @import stats #' #' @examples #' \donttest{ @@ -677,7 +678,6 @@ table_moderator_c_bin <- function(.model, moderator, .name = 'bin'){ validate_model_(.model) is_numeric_vector_(moderator) - type <- type[1] # adjust moderator to match estimand moderator <- adjust_for_estimand_(.model, moderator) diff --git a/man/table_moderator_c_bin.Rd b/man/table_moderator_c_bin.Rd new file mode 100644 index 0000000..7ebebab --- /dev/null +++ b/man/table_moderator_c_bin.Rd @@ -0,0 +1,38 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plot_moderators.R +\name{table_moderator_c_bin} +\alias{table_moderator_c_bin} +\title{Auto-Bin a table of a continuous moderating variable into a discrete moderating variable} +\usage{ +table_moderator_c_bin(.model, moderator, .name = "bin") +} +\arguments{ +\item{.model}{a model produced by `bartCause::bartc()`} + +\item{moderator}{the moderator as a vector} + +\item{.name}{sting representing the name of the moderating variable} +} +\value{ +a data.frame object +} +\description{ +Use a regression tree to optimally bin a continuous variable, this function will print out a table with estimates and 95% ci +} +\examples{ +\donttest{ +data(lalonde) +confounders <- c('age', 'educ', 'black', 'hisp', 'married', 'nodegr') +model_results <- bartCause::bartc( + response = lalonde[['re78']], + treatment = lalonde[['treat']], + confounders = as.matrix(lalonde[, confounders]), + estimand = 'ate', + commonSuprule = 'none' +) +table_moderator_c_bin(model_results, lalonde$age, .name = 'age') +} +} +\author{ +George Perrett +} diff --git a/renv.lock b/renv.lock index f304e5d..4b6bdcf 100644 --- a/renv.lock +++ b/renv.lock @@ -569,11 +569,12 @@ }, "lifecycle": { "Package": "lifecycle", - "Version": "1.0.1", + "Version": "1.0.4", "Source": "Repository", "Repository": "CRAN", - "Hash": "a6b6d352e3ed897373ab19d8395c98d0", + "Hash": "b8552d117e1b808b09a832f589b79035", "Requirements": [ + "cli", "glue", "rlang" ] @@ -825,13 +826,16 @@ }, "purrr": { "Package": "purrr", - "Version": "0.3.4", + "Version": "1.0.2", "Source": "Repository", - "Repository": "CRAN", - "Hash": "97def703420c8ab10d8f0e6c72101e02", + "Repository": "RSPM", + "Hash": "1cba04a4e9414bdefc9dcaa99649a8dc", "Requirements": [ + "cli", + "lifecycle", "magrittr", - "rlang" + "rlang", + "vctrs" ] }, "ragg": { @@ -893,10 +897,10 @@ }, "rlang": { "Package": "rlang", - "Version": "1.0.4", + "Version": "1.1.3", "Source": "Repository", - "Repository": "CRAN", - "Hash": "6539dd8c651e67e3b55b5ffea106362b", + "Repository": "RSPM", + "Hash": "42548638fae05fd9a9b5f3f437fbbbe2", "Requirements": [] }, "rmarkdown": { @@ -1112,13 +1116,14 @@ }, "vctrs": { "Package": "vctrs", - "Version": "0.4.1", + "Version": "0.6.5", "Source": "Repository", - "Repository": "CRAN", - "Hash": "8b54f22e2a58c4f275479c92ce041a57", + "Repository": "RSPM", + "Hash": "c03fa420630029418f7e6da3667aac4a", "Requirements": [ "cli", "glue", + "lifecycle", "rlang" ] },