Skip to content

Commit 46cdcc5

Browse files
committed
allow for multiple values passed
1 parent d55307d commit 46cdcc5

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

R/tip-helpers.R

+8-8
Original file line numberDiff line numberDiff line change
@@ -135,21 +135,21 @@ tip_gamma <- function(p0 = NULL,
135135
}
136136

137137
check_r2 <- function(r2, exposure = FALSE, effect, se, df) {
138-
if (r2 < 0 | r2 > 1) {
138+
if (any(r2 < 0) | any(r2 > 1)) {
139139
stop_glue("You input:\n {r2}\n",
140140
"The partial R2 values entered must be between 0 and 1.")
141141
}
142142
if (exposure) {
143-
if (r2 == 1) {
143+
if (any(r2 == 1)) {
144144
stop_glue("You input:\n * `exposure_r2`: {r2}\n",
145145
"This means 100% of the residual variation in the exposure ",
146146
"is explained by the unmeasured confounder, meaning regardless ",
147147
"of the unmeasured confounder - outcome relationship, this ",
148148
"will be \"tipped\".")
149149
}
150150
limit <- sensemakr::partial_r2(effect / se, df)
151-
if (r2 < limit) {
152-
stop_glue("You input:\n * `exposure_r2`: {r2}\n",
151+
if (any(r2 < limit)) {
152+
stop_glue("You input:\n * `exposure_r2`: {r2[r2 < limit]}\n",
153153
"It is not possible to tip this result with any unmeasured ",
154154
"confounder - outcome relationship. In fact, if your ",
155155
"unmeasured confounder explained 100% of the residual ",
@@ -171,9 +171,9 @@ check_r2 <- function(r2, exposure = FALSE, effect, se, df) {
171171

172172
exposure_r2 <-
173173
effect ^ 2 / (effect ^ 2 + se ^ 2 * df * outcome_r2)
174-
if (exposure_r2 > 1) {
174+
if (any(exposure_r2 > 1)) {
175175
stop_glue(
176-
"Given the input:\n * `effect`: {effect}\n * `outcome_r2`: {outcome_r2}\n",
176+
"Given the input:\n * `effect`: {effect}\n * `outcome_r2`: {outcome_r2[exposure_r2 > 1]}\n",
177177
"There does not exist an unmeasured confounder that could tip this.\n",
178178
)
179179
}
@@ -266,9 +266,9 @@ check_r2 <- function(r2, exposure = FALSE, effect, se, df) {
266266

267267
outcome_r2 <-
268268
(effect ^ 2 - effect ^ 2 * exposure_r2) / (se ^ 2 * df * exposure_r2)
269-
if (outcome_r2 > 1) {
269+
if (any(outcome_r2 > 1)) {
270270
stop_glue(
271-
"Given the input:\n * `effect`: {effect}\n * `exposure_r2`: {exposure_r2}\n",
271+
"Given the input:\n * `effect`: {effect}\n * `exposure_r2`: {exposure_r2[outcome_r2 > 1]}\n",
272272
"There does not exist an unmeasured confounder that could tip this.\n",
273273
)
274274
}

R/tip_coef_with_r2.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ tip_coef_with_r2 <- function(effect,
5050
if (tip_bound) {
5151
outcome_r2 <- tip_outcome_r2_bound(effect, se, df, exposure_r2, alpha)
5252
} else{
53-
outcome_r2 <- tip_outcome_r2(effect, se, df, exposure_r2)
53+
outcome_r2 <- tip_outcome_r2(effect, se, df, exposure_r2)
5454
}
5555
}
5656
o <- adjust_coef_with_r2(

0 commit comments

Comments
 (0)