Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Imports:
dplyr,
ggplot2,
gtsummary (>= 2.1.0),
propensity (>= 0.0.0.9000),
purrr,
rlang,
smd,
Expand All @@ -43,4 +44,5 @@ LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
Remotes:
r-causal/tidysmd
r-causal/tidysmd,
r-causal/propensity
7 changes: 1 addition & 6 deletions R/geom_qq2.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,8 @@
#' geom_abline(intercept = 0, slope = 1, linetype = "dashed")
#'
#' # Compare multiple weights using long format
#' # TODO: Remove vec_data() workaround once propensity implements vctrs methods
#' # Extract numeric data from psw objects first
#' nhefs_for_pivot <- nhefs_weights
#' nhefs_for_pivot$w_ate <- vctrs::vec_data(nhefs_weights$w_ate)
#' nhefs_for_pivot$w_att <- vctrs::vec_data(nhefs_weights$w_att)
#' long_data <- tidyr::pivot_longer(
#' nhefs_for_pivot,
#' nhefs_weights,
#' cols = c(w_ate, w_att),
#' names_to = "weight_type",
#' values_to = "weight"
Expand Down
7 changes: 1 addition & 6 deletions R/geom_roc.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,8 @@
#' geom_abline(intercept = 0, slope = 1, linetype = "dashed")
#'
#' # With grouping by weight
#' # TODO: Remove vec_data() workaround once propensity implements vctrs methods
#' # Extract numeric data from psw objects first
#' nhefs_for_pivot <- nhefs_weights
#' nhefs_for_pivot$w_ate <- vctrs::vec_data(nhefs_weights$w_ate)
#' nhefs_for_pivot$w_att <- vctrs::vec_data(nhefs_weights$w_att)
#' long_data <- tidyr::pivot_longer(
#' nhefs_for_pivot,
#' nhefs_weights,
#' cols = c(w_ate, w_att),
#' names_to = "weight_type",
#' values_to = "weight"
Expand Down
2 changes: 1 addition & 1 deletion R/utils-validation.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ validate_weights <- function(weights, n, arg_name = "weights", call = rlang::cal
if (is.null(weights)) return(invisible(weights))

# Accept both numeric vectors and psw objects from propensity package
is_valid_weights <- is.numeric(weights) || inherits(weights, "psw")
is_valid_weights <- is.numeric(weights) || propensity::is_psw(weights)

if (!is_valid_weights) {
abort(
Expand Down
8 changes: 8 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.onLoad <- function(libname, pkgname) {
# Ensure propensity's namespace is loaded so its S3 methods are registered
# This is needed for psw objects in nhefs_weights to work properly without
# users having to explicitly load propensity
loadNamespace("propensity")
Comment thread
malcolmbarrett marked this conversation as resolved.

invisible()
}
7 changes: 1 addition & 6 deletions man/geom_qq2.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions man/geom_roc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified tests/testthat/Rplots.pdf
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/testthat/test-compute_balance.R
Original file line number Diff line number Diff line change
Expand Up @@ -1506,8 +1506,8 @@ test_that("balance functions work seamlessly with psw objects from propensity pa
data(nhefs_weights)

# Verify we have psw objects in the dataset
expect_true(inherits(nhefs_weights$w_cat_ate, "psw"))
expect_true(inherits(nhefs_weights$w_cat_att_none, "psw"))
expect_true(propensity::is_psw(nhefs_weights$w_cat_ate))
expect_true(propensity::is_psw(nhefs_weights$w_cat_att_none))

# Test that balance functions work directly with psw weights
result_smd <- bal_smd(
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-extract_weight_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ test_that("extract_weight_data extracts data from psw objects", {
expect_type(result, "double")

# Should not have psw class anymore
expect_false(inherits(result, "psw"))
expect_false(propensity::is_psw(result))
})

test_that("extract_weight_data preserves values from different psw estimands", {
Expand Down
9 changes: 2 additions & 7 deletions tests/testthat/test-geom_qq2.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,9 @@ test_that("geom_qq2 works with weights", {
})

test_that("geom_qq2 works with color aesthetic for multiple weights", {
# Create long format data - need to extract numeric data from psw columns first
# TODO: Remove vec_data() workaround once propensity implements vctrs methods
nhefs_for_pivot <- nhefs_weights
nhefs_for_pivot$w_ate <- vctrs::vec_data(nhefs_weights$w_ate)
nhefs_for_pivot$w_att <- vctrs::vec_data(nhefs_weights$w_att)

# Create long format data
long_data <- tidyr::pivot_longer(
nhefs_for_pivot,
nhefs_weights,
cols = c(w_ate, w_att),
names_to = "weight_type",
values_to = "weight"
Expand Down
9 changes: 2 additions & 7 deletions tests/testthat/test-geom_roc.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,9 @@ test_that("geom_roc visual regression", {
)

# Multiple groups with different weights
# First create long format data - need to extract numeric data from psw columns
# TODO: Remove vec_data() workaround once propensity implements vctrs methods
nhefs_for_pivot <- nhefs_weights
nhefs_for_pivot$w_ate <- vctrs::vec_data(nhefs_weights$w_ate)
nhefs_for_pivot$w_att <- vctrs::vec_data(nhefs_weights$w_att)

# Create long format data
long_data <- tidyr::pivot_longer(
nhefs_for_pivot,
nhefs_weights,
cols = c(w_ate, w_att),
names_to = "weight_type",
values_to = "weight"
Expand Down
Loading