Skip to content

Commit 919ac62

Browse files
Merge pull request #51 from r-causal/args
Update argument consistency to match propensity
2 parents 8162863 + de48376 commit 919ac62

File tree

101 files changed

+6871
-6789
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+6871
-6789
lines changed

R/bal_ess.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#' * If ESS is much lower than the total sample size, consider investigating
2222
#' why some weights are extremely large or small
2323
#'
24-
#' @param .wts A numeric vector of weights or a single weight column from a data frame.
24+
#' @param .weights A numeric vector of weights or a single weight column from a data frame.
2525
#' @inheritParams balance_params
2626
#'
2727
#' @return A single numeric value representing the effective sample size.
@@ -43,7 +43,7 @@
4343
#' bal_ess(weights_with_na, na.rm = TRUE)
4444
#'
4545
#' @export
46-
bal_ess <- function(.wts, na.rm = FALSE) {
46+
bal_ess <- function(.weights, na.rm = FALSE) {
4747
# Simply call the existing ess() function
48-
ess(.wts, na.rm = na.rm)
48+
ess(.weights, na.rm = na.rm)
4949
}

R/bal_model_auc.R

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
#' balance.
1616
#'
1717
#' @param .data A data frame containing the variables.
18-
#' @param .truth The treatment/outcome variable (unquoted).
18+
#' @param .exposure The treatment/outcome variable (unquoted).
1919
#' @param .estimate The propensity score or fitted values (unquoted).
20-
#' @param .wts Optional single weight variable (unquoted). If NULL, computes
20+
#' @param .weights Optional single weight variable (unquoted). If NULL, computes
2121
#' unweighted AUC.
2222
#' @inheritParams balance_params
2323
#' @inheritParams treatment_param
@@ -39,25 +39,25 @@
3939
#' @export
4040
bal_model_auc <- function(
4141
.data,
42-
.truth,
42+
.exposure,
4343
.estimate,
44-
.wts = NULL,
44+
.weights = NULL,
4545
na.rm = TRUE,
46-
treatment_level = NULL
46+
.focal_level = NULL
4747
) {
4848
validate_data_frame(.data, call = rlang::caller_env())
4949

50-
truth_quo <- rlang::enquo(.truth)
50+
exposure_quo <- rlang::enquo(.exposure)
5151
estimate_quo <- rlang::enquo(.estimate)
52-
wts_quo <- rlang::enquo(.wts)
52+
wts_quo <- rlang::enquo(.weights)
5353

5454
# Extract column names
55-
truth_name <- names(tidyselect::eval_select(truth_quo, .data))
55+
exposure_name <- names(tidyselect::eval_select(exposure_quo, .data))
5656
estimate_name <- names(tidyselect::eval_select(estimate_quo, .data))
5757

58-
if (length(truth_name) != 1) {
58+
if (length(exposure_name) != 1) {
5959
abort(
60-
"{.arg .truth} must select exactly one variable",
60+
"{.arg .exposure} must select exactly one variable",
6161
error_class = "halfmoon_arg_error",
6262
call = rlang::current_env()
6363
)
@@ -71,7 +71,7 @@ bal_model_auc <- function(
7171
}
7272

7373
# Extract data
74-
truth <- .data[[truth_name]]
74+
exposure <- .data[[exposure_name]]
7575
estimate <- .data[[estimate_name]]
7676

7777
# Handle weights if provided
@@ -80,7 +80,7 @@ bal_model_auc <- function(
8080
weight_vars <- names(tidyselect::eval_select(wts_quo, .data))
8181
if (length(weight_vars) != 1) {
8282
abort(
83-
"{.arg .wts} must select exactly one variable or be NULL",
83+
"{.arg .weights} must select exactly one variable or be NULL",
8484
error_class = "halfmoon_arg_error",
8585
call = rlang::current_env()
8686
)
@@ -91,20 +91,20 @@ bal_model_auc <- function(
9191
# Handle missing values
9292
if (na.rm) {
9393
if (is.null(weights)) {
94-
complete_cases <- stats::complete.cases(truth, estimate)
94+
complete_cases <- stats::complete.cases(exposure, estimate)
9595
} else {
96-
complete_cases <- stats::complete.cases(truth, estimate, weights)
96+
complete_cases <- stats::complete.cases(exposure, estimate, weights)
9797
}
98-
truth <- truth[complete_cases]
98+
exposure <- exposure[complete_cases]
9999
estimate <- estimate[complete_cases]
100100
if (!is.null(weights)) {
101101
weights <- weights[complete_cases]
102102
}
103103
} else {
104104
if (is.null(weights)) {
105-
na_present <- any(is.na(truth)) || any(is.na(estimate))
105+
na_present <- any(is.na(exposure)) || any(is.na(estimate))
106106
} else {
107-
na_present <- any(is.na(truth)) ||
107+
na_present <- any(is.na(exposure)) ||
108108
any(is.na(estimate)) ||
109109
any(is.na(weights))
110110
}
@@ -115,10 +115,10 @@ bal_model_auc <- function(
115115

116116
# Compute ROC curve
117117
roc_data <- compute_roc_curve_imp(
118-
truth,
118+
exposure,
119119
estimate,
120120
weights = weights,
121-
treatment_level = treatment_level,
121+
.focal_level = .focal_level,
122122
call = rlang::current_env()
123123
)
124124

R/bal_model_roc_curve.R

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
#' inadequate balance.
1717
#'
1818
#' @param .data A data frame containing the variables.
19-
#' @param .truth The treatment/outcome variable (unquoted).
19+
#' @param .exposure The treatment/outcome variable (unquoted).
2020
#' @param .estimate The propensity score or fitted values (unquoted).
21-
#' @param .wts Optional single weight variable (unquoted). If NULL, computes
21+
#' @param .weights Optional single weight variable (unquoted). If NULL, computes
2222
#' unweighted ROC curve.
2323
#' @inheritParams balance_params
2424
#' @inheritParams treatment_param
@@ -42,25 +42,25 @@
4242
#' @export
4343
bal_model_roc_curve <- function(
4444
.data,
45-
.truth,
45+
.exposure,
4646
.estimate,
47-
.wts = NULL,
47+
.weights = NULL,
4848
na.rm = TRUE,
49-
treatment_level = NULL
49+
.focal_level = NULL
5050
) {
5151
validate_data_frame(.data, call = rlang::caller_env())
5252

53-
truth_quo <- rlang::enquo(.truth)
53+
exposure_quo <- rlang::enquo(.exposure)
5454
estimate_quo <- rlang::enquo(.estimate)
55-
wts_quo <- rlang::enquo(.wts)
55+
wts_quo <- rlang::enquo(.weights)
5656

5757
# Extract column names
58-
truth_name <- names(tidyselect::eval_select(truth_quo, .data))
58+
exposure_name <- names(tidyselect::eval_select(exposure_quo, .data))
5959
estimate_name <- names(tidyselect::eval_select(estimate_quo, .data))
6060

61-
if (length(truth_name) != 1) {
61+
if (length(exposure_name) != 1) {
6262
abort(
63-
"{.arg .truth} must select exactly one variable",
63+
"{.arg .exposure} must select exactly one variable",
6464
error_class = "halfmoon_arg_error",
6565
call = rlang::current_env()
6666
)
@@ -74,7 +74,7 @@ bal_model_roc_curve <- function(
7474
}
7575

7676
# Extract data
77-
truth <- .data[[truth_name]]
77+
exposure <- .data[[exposure_name]]
7878
estimate <- .data[[estimate_name]]
7979

8080
# Handle weights if provided
@@ -83,7 +83,7 @@ bal_model_roc_curve <- function(
8383
weight_vars <- names(tidyselect::eval_select(wts_quo, .data))
8484
if (length(weight_vars) != 1) {
8585
abort(
86-
"{.arg .wts} must select exactly one variable or be NULL",
86+
"{.arg .weights} must select exactly one variable or be NULL",
8787
error_class = "halfmoon_arg_error",
8888
call = rlang::current_env()
8989
)
@@ -94,20 +94,20 @@ bal_model_roc_curve <- function(
9494
# Handle missing values
9595
if (na.rm) {
9696
if (is.null(weights)) {
97-
complete_cases <- stats::complete.cases(truth, estimate)
97+
complete_cases <- stats::complete.cases(exposure, estimate)
9898
} else {
99-
complete_cases <- stats::complete.cases(truth, estimate, weights)
99+
complete_cases <- stats::complete.cases(exposure, estimate, weights)
100100
}
101-
truth <- truth[complete_cases]
101+
exposure <- exposure[complete_cases]
102102
estimate <- estimate[complete_cases]
103103
if (!is.null(weights)) {
104104
weights <- weights[complete_cases]
105105
}
106106
} else {
107107
if (is.null(weights)) {
108-
na_present <- any(is.na(truth)) || any(is.na(estimate))
108+
na_present <- any(is.na(exposure)) || any(is.na(estimate))
109109
} else {
110-
na_present <- any(is.na(truth)) ||
110+
na_present <- any(is.na(exposure)) ||
111111
any(is.na(estimate)) ||
112112
any(is.na(weights))
113113
}
@@ -122,10 +122,10 @@ bal_model_roc_curve <- function(
122122

123123
# Compute and return ROC curve
124124
compute_roc_curve_imp(
125-
truth,
125+
exposure,
126126
estimate,
127127
weights = weights,
128-
treatment_level = treatment_level,
128+
.focal_level = .focal_level,
129129
call = rlang::current_env()
130130
)
131131
}

0 commit comments

Comments
 (0)