@@ -135,21 +135,21 @@ tip_gamma <- function(p0 = NULL,
135
135
}
136
136
137
137
check_r2 <- function (r2 , exposure = FALSE , effect , se , df ) {
138
- if (r2 < 0 | r2 > 1 ) {
138
+ if (any( r2 < 0 ) | any( r2 > 1 ) ) {
139
139
stop_glue(" You input:\n {r2}\n " ,
140
140
" The partial R2 values entered must be between 0 and 1." )
141
141
}
142
142
if (exposure ) {
143
- if (r2 == 1 ) {
143
+ if (any( r2 == 1 ) ) {
144
144
stop_glue(" You input:\n * `exposure_r2`: {r2}\n " ,
145
145
" This means 100% of the residual variation in the exposure " ,
146
146
" is explained by the unmeasured confounder, meaning regardless " ,
147
147
" of the unmeasured confounder - outcome relationship, this " ,
148
148
" will be \" tipped\" ." )
149
149
}
150
150
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 " ,
153
153
" It is not possible to tip this result with any unmeasured " ,
154
154
" confounder - outcome relationship. In fact, if your " ,
155
155
" unmeasured confounder explained 100% of the residual " ,
@@ -171,9 +171,9 @@ check_r2 <- function(r2, exposure = FALSE, effect, se, df) {
171
171
172
172
exposure_r2 <-
173
173
effect ^ 2 / (effect ^ 2 + se ^ 2 * df * outcome_r2 )
174
- if (exposure_r2 > 1 ) {
174
+ if (any( exposure_r2 > 1 ) ) {
175
175
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 " ,
177
177
" There does not exist an unmeasured confounder that could tip this.\n " ,
178
178
)
179
179
}
@@ -266,9 +266,9 @@ check_r2 <- function(r2, exposure = FALSE, effect, se, df) {
266
266
267
267
outcome_r2 <-
268
268
(effect ^ 2 - effect ^ 2 * exposure_r2 ) / (se ^ 2 * df * exposure_r2 )
269
- if (outcome_r2 > 1 ) {
269
+ if (any( outcome_r2 > 1 ) ) {
270
270
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 " ,
272
272
" There does not exist an unmeasured confounder that could tip this.\n " ,
273
273
)
274
274
}
0 commit comments