1
- # ' Tip a linear model result with a continuous confounder.
1
+ # ' Tip a linear model coefficient with a continuous confounder.
2
2
# '
3
3
# ' choose one of the following, and the other will be estimated:
4
4
# ' * `smd`
14
14
# ' between the unmeasured confounder and the outcome
15
15
# ' @param verbose Logical. Indicates whether to print informative message.
16
16
# ' Default: `TRUE`
17
- # ' @param correction_factor Character string. Options are "none", "hr", "or".
18
- # ' For common outcomes (>15%), the odds ratio or hazard ratio is not a good
19
- # ' estimate for the relative risk. In these cases, we can apply a correction
20
- # ' factor. If you are supplying a hazard ratio for a common outcome, set
21
- # ' this to "hr"; if you are supplying an odds ratio for a common outcome, set
22
- # ' this to "or"; if you are supplying a risk ratio or your outcome is rare,
23
- # ' set this to "none" (default).
24
17
# '
25
18
# ' @return Data frame.
26
19
# '
27
20
# ' @examples
28
21
# ' ## to estimate the association between an unmeasured confounder and outcome
29
22
# ' ## needed to tip analysis
30
- # ' tip_lm (1.2, smd = -2)
23
+ # ' tip_coef (1.2, smd = -2)
31
24
# '
32
25
# ' ## to estimate the number of unmeasured confounders specified needed to tip
33
26
# ' ## the analysis
34
- # ' tip_lm (1.2, smd = -2, outcome_association = -0.05)
27
+ # ' tip_coef (1.2, smd = -2, outcome_association = -0.05)
35
28
# '
36
29
# ' ## Example with broom
37
30
# ' if (requireNamespace("broom", quietly = TRUE) &&
40
33
# ' broom::tidy(conf.int = TRUE) %>%
41
34
# ' dplyr::filter(term == "mpg") %>%
42
35
# ' dplyr::pull(conf.low) %>%
43
- # ' tip_lm (outcome_association = 2.5)
36
+ # ' tip_coef (outcome_association = 2.5)
44
37
# '}
45
38
# ' @export
46
- tip_lm <- function (effect , smd = NULL , outcome_association = NULL , verbose = TRUE , correction_factor = " none " ) {
39
+ tip_coef <- function (effect , smd = NULL , outcome_association = NULL , verbose = TRUE ) {
47
40
48
41
o <- purrr :: map(
49
42
effect ,
50
- ~ tip_lm_one (.x ,
43
+ ~ tip_coef_one (.x ,
51
44
smd = smd ,
52
45
outcome_association = outcome_association ,
53
- verbose = verbose ,
54
- correction_factor = correction_factor
46
+ verbose = verbose
55
47
)
56
48
)
57
49
do.call(rbind , o )
58
50
}
59
51
60
- tip_lm_one <- function (b , smd , outcome_association , verbose , correction_factor ) {
52
+ tip_coef_one <- function (b , smd , outcome_association , verbose ) {
61
53
62
54
n_unmeasured_confounders <- 1
63
- correction <- " "
64
- if (correction_factor == " hr" ) {
65
- b <- hr_transform(b )
66
- outcome_association <- hr_transform(outcome_association )
67
- correction <- ' You opted to use the hazard ratio correction to convert your hazard ratios to approximate risk ratios.\n This is a good idea if the outcome is common (>15%).'
68
- }
69
-
70
- if (correction_factor == " or" ) {
71
- b <- or_transform(b )
72
- outcome_association <- or_transform(outcome_association )
73
- correction <- ' You opted to use the odds ratio correction to convert your odds ratios to approximate risk ratios.\n This is a good idea if the outcome is common (>15%).'
74
- }
75
55
76
56
if (is.null(outcome_association )) {
77
57
outcome_association <- b / smd
@@ -130,7 +110,7 @@ tip_lm_one <- function(b, smd, outcome_association, verbose, correction_factor)
130
110
" unmeasured confounder\n in the exposed population and " ,
131
111
" unexposed population: {round(o_notip$smd, 2)}" ,
132
112
" \n * estimated association between the unmeasured confounder and the " ,
133
- " outcome: {round(o_notip$outcome_association, 2)}\n\n {correction} "
113
+ " outcome: {round(o_notip$outcome_association, 2)}\n\n "
134
114
)
135
115
} else if (any(o $ n_unmeasured_confounders == 0 )) {
136
116
o_notip <- o [o $ n_unmeasured_confounders == 0 ,]
@@ -142,7 +122,7 @@ tip_lm_one <- function(b, smd, outcome_association, verbose, correction_factor)
142
122
" unmeasured confounder\n in the exposed population and " ,
143
123
" unexposed population: {round(o_notip$smd, 2)}" ,
144
124
" \n * estimated association between the unmeasured confounder and the " ,
145
- " outcome: {round(o_notip$outcome_association, 2)}\n\n {correction} "
125
+ " outcome: {round(o_notip$outcome_association, 2)}\n\n "
146
126
)
147
127
148
128
o_tip <- o [o $ n_unmeasured_confounders != 0 ,]
@@ -155,7 +135,7 @@ tip_lm_one <- function(b, smd, outcome_association, verbose, correction_factor)
155
135
" unmeasured confounder\n in the exposed population and " ,
156
136
" unexposed population: {round(o_tip$smd, 2)}" ,
157
137
" \n * estimated association between the unmeasured confounder and the " ,
158
- " outcome: {round(o_tip$outcome_association, 2)}\n\n {correction} "
138
+ " outcome: {round(o_tip$outcome_association, 2)}\n\n "
159
139
)
160
140
} else {
161
141
message_glue(
@@ -167,16 +147,20 @@ tip_lm_one <- function(b, smd, outcome_association, verbose, correction_factor)
167
147
" unmeasured confounder\n in the exposed population and " ,
168
148
" unexposed population: {round(o$smd, 2)}" ,
169
149
" \n * estimated association between the unmeasured confounder and the " ,
170
- " outcome: {round(o$outcome_association, 2)}\n\n {correction} "
150
+ " outcome: {round(o$outcome_association, 2)}\n\n "
171
151
)
172
152
}
173
153
}
174
154
o
175
155
}
176
156
177
- # ' @rdname tip_lm
157
+ # ' @rdname tip_coef
178
158
# ' @export
179
159
lm_tip <- function (effect , smd , outcome_association , verbose = TRUE ) {
180
160
.Deprecated(" tip_lm" )
181
- tip_lm (effect , smd , outcome_association , verbose )
161
+ tip_coef (effect , smd , outcome_association , verbose )
182
162
}
163
+
164
+ # ' @rdname tip_coef
165
+ # ' @export
166
+ tip_coef_with_continuous <- tip_coef
0 commit comments