Skip to content

Commit 1600106

Browse files
Merge pull request #33 from r-causal/weights_improvements
Weights improvements
2 parents 95273b7 + a8323b7 commit 1600106

File tree

7 files changed

+2204
-75
lines changed

7 files changed

+2204
-75
lines changed

DESCRIPTION

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@ Imports:
1515
cli,
1616
rlang,
1717
stats,
18+
tidyselect,
1819
vctrs (>= 0.6.5)
1920
Suggests:
2021
dplyr,
2122
ggplot2,
2223
mgcv,
24+
parsnip,
2325
probably,
2426
PSweight,
2527
spelling,
2628
testthat (>= 3.0.0),
27-
tidyselect,
29+
tibble,
2830
WeightIt
2931
Config/testthat/edition: 3
3032
Encoding: UTF-8

NAMESPACE

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,39 @@ S3method(vec_ptype_abbr,psw)
8181
S3method(vec_ptype_full,ps_trim)
8282
S3method(vec_ptype_full,ps_trunc)
8383
S3method(vec_ptype_full,psw)
84+
S3method(wt_ate,data.frame)
85+
S3method(wt_ate,default)
86+
S3method(wt_ate,glm)
8487
S3method(wt_ate,numeric)
8588
S3method(wt_ate,ps_trim)
8689
S3method(wt_ate,ps_trunc)
90+
S3method(wt_atm,data.frame)
91+
S3method(wt_atm,default)
92+
S3method(wt_atm,glm)
8793
S3method(wt_atm,numeric)
8894
S3method(wt_atm,ps_trim)
8995
S3method(wt_atm,ps_trunc)
96+
S3method(wt_ato,data.frame)
97+
S3method(wt_ato,default)
98+
S3method(wt_ato,glm)
9099
S3method(wt_ato,numeric)
91100
S3method(wt_ato,ps_trim)
92101
S3method(wt_ato,ps_trunc)
102+
S3method(wt_att,data.frame)
103+
S3method(wt_att,default)
104+
S3method(wt_att,glm)
93105
S3method(wt_att,numeric)
94106
S3method(wt_att,ps_trim)
95107
S3method(wt_att,ps_trunc)
108+
S3method(wt_atu,data.frame)
109+
S3method(wt_atu,default)
110+
S3method(wt_atu,glm)
96111
S3method(wt_atu,numeric)
97112
S3method(wt_atu,ps_trim)
98113
S3method(wt_atu,ps_trunc)
114+
S3method(wt_entropy,data.frame)
115+
S3method(wt_entropy,default)
116+
S3method(wt_entropy,glm)
99117
S3method(wt_entropy,numeric)
100118
S3method(wt_entropy,ps_trim)
101119
S3method(wt_entropy,ps_trunc)

R/weights-utils.R

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ abort_unsupported <- function(exposure_type, what, call = rlang::caller_env()) {
88

99
match_exposure_type <- function(
1010
exposure_type = c("auto", "binary", "categorical", "continuous"),
11-
.exposure
11+
.exposure,
12+
valid_types = c("auto", "binary", "categorical", "continuous")
1213
) {
13-
.exposure_type <- rlang::arg_match(exposure_type)
14+
.exposure_type <- rlang::arg_match(exposure_type, valid_types)
1415
if (.exposure_type == "auto") {
1516
detect_exposure_type(.exposure)
1617
} else {
@@ -128,3 +129,26 @@ check_lower_upper <- function(lower, upper, call = rlang::caller_env()) {
128129

129130
invisible(TRUE)
130131
}
132+
133+
check_lengths_match <- function(
134+
.propensity,
135+
.exposure,
136+
call = rlang::caller_env()
137+
) {
138+
len_prop <- length(.propensity)
139+
len_exp <- length(.exposure)
140+
141+
if (len_prop != len_exp) {
142+
abort(
143+
c(
144+
"{.arg .propensity} and {.arg .exposure} must have the same length.",
145+
i = "{.arg .propensity} has length {len_prop}",
146+
i = "{.arg .exposure} has length {len_exp}"
147+
),
148+
call = call,
149+
error_class = "propensity_length_error"
150+
)
151+
}
152+
153+
invisible(TRUE)
154+
}

0 commit comments

Comments
 (0)