Skip to content

Commit 160c6bd

Browse files
committed
move to r-causal, change %>%
1 parent 1363bc3 commit 160c6bd

File tree

2 files changed

+47
-53
lines changed

2 files changed

+47
-53
lines changed

README.Rmd

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Or install the development version from GitHub:
2626

2727
```{r, eval = FALSE}
2828
# install.packages(devtools)
29-
devtools::install_github("lucymcgowan/tipr")
29+
devtools::install_github("r-causal/tipr")
3030
```
3131

3232
```{r}
@@ -45,7 +45,7 @@ Using the example data `exdata_rr`, we can estimate the exposure-outcome relatio
4545
mod <- glm(outcome ~ exposure + measured_confounder, data = exdata_rr,
4646
family = poisson)
4747
48-
mod %>%
48+
mod |>
4949
broom::tidy(exponentiate = TRUE, conf.int = TRUE)
5050
```
5151

@@ -72,12 +72,12 @@ A hypothetical unobserved continuous confounder a scaled mean difference between
7272
Because this is simulated data, we can see what the *true* unmeasured confounder looked like. First we will calculate the difference in scaled means.
7373

7474
```{r}
75-
exdata_rr %>%
76-
dplyr::group_by(exposure) %>%
77-
dplyr::summarise(m = mean(.unmeasured_confounder / sd(.unmeasured_confounder))) %>%
75+
exdata_rr |>
76+
dplyr::group_by(exposure) |>
77+
dplyr::summarise(m = mean(.unmeasured_confounder / sd(.unmeasured_confounder))) |>
7878
tidyr::pivot_wider(names_from = exposure,
7979
values_from = m,
80-
names_prefix = "u_") %>%
80+
names_prefix = "u_") |>
8181
dplyr::summarise(estimate = u_1 - u_0)
8282
```
8383

@@ -89,7 +89,7 @@ mod_true <- glm(
8989
data = exdata_rr,
9090
family = poisson)
9191
92-
mod_true %>%
92+
mod_true |>
9393
broom::tidy(exponentiate = TRUE, conf.int = TRUE)
9494
```
9595

@@ -128,10 +128,10 @@ These functions were created to easily integrate with models tidied using the **
128128
```{r}
129129
if (requireNamespace("broom", quietly = TRUE) && requireNamespace("dplyr", quietly = TRUE)) {
130130
glm(outcome ~ exposure + measured_confounder, data = exdata_rr,
131-
family = poisson) %>%
132-
broom::tidy(conf.int = TRUE, exponentiate = TRUE) %>%
133-
dplyr::filter(term == "exposure") %>%
134-
dplyr::pull(conf.low) %>%
131+
family = poisson) |>
132+
broom::tidy(conf.int = TRUE, exponentiate = TRUE) |>
133+
dplyr::filter(term == "exposure") |>
134+
dplyr::pull(conf.low) |>
135135
tip(confounder_outcome_effect = 2.5)
136136
}
137137
```

README.md

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Or install the development version from GitHub:
2525

2626
``` r
2727
# install.packages(devtools)
28-
devtools::install_github("lucymcgowan/tipr")
28+
devtools::install_github("r-causal/tipr")
2929
```
3030

3131
``` r
@@ -61,7 +61,7 @@ relationship using the measured confounder as follows:
6161
mod <- glm(outcome ~ exposure + measured_confounder, data = exdata_rr,
6262
family = poisson)
6363

64-
mod %>%
64+
mod |>
6565
broom::tidy(exponentiate = TRUE, conf.int = TRUE)
6666
```
6767

@@ -96,12 +96,11 @@ between the unmeasured confounder and outcome needed to tip the analysis
9696
tip(effect_observed = 1.5, exposure_confounder_effect = 0.5)
9797
```
9898

99-
## ℹ The observed effect (1.5) WOULD be tipped by 1 unmeasured confounder with the
100-
## following specifications:
101-
## • estimated difference in scaled means between the unmeasured confounder in the
102-
## exposed population and unexposed population: 0.5
103-
## • estimated relationship between the unmeasured confounder and the outcome:
104-
## 2.25
99+
## The observed effect (1.5) WOULD be tipped by 1 unmeasured confounder
100+
## with the following specifications:
101+
## * estimated difference in scaled means between the unmeasured confounder
102+
## in the exposed population and unexposed population: 0.5
103+
## * estimated relationship between the unmeasured confounder and the outcome: 2.25
105104

106105
## # A tibble: 1 × 5
107106
## effect_adjusted effect_observed exposure_confounder_effect confounde…¹ n_unm…²
@@ -118,12 +117,11 @@ between exposure groups of `0.5` would need a relationship of at least
118117
tip(effect_observed = 1.09, exposure_confounder_effect = 0.5)
119118
```
120119

121-
## ℹ The observed effect (1.09) WOULD be tipped by 1 unmeasured confounder with
122-
## the following specifications:
123-
## • estimated difference in scaled means between the unmeasured confounder in the
124-
## exposed population and unexposed population: 0.5
125-
## • estimated relationship between the unmeasured confounder and the outcome:
126-
## 1.19
120+
## The observed effect (1.09) WOULD be tipped by 1 unmeasured confounder
121+
## with the following specifications:
122+
## * estimated difference in scaled means between the unmeasured confounder
123+
## in the exposed population and unexposed population: 0.5
124+
## * estimated relationship between the unmeasured confounder and the outcome: 1.19
127125

128126
## # A tibble: 1 × 5
129127
## effect_adjusted effect_observed exposure_confounder_effect confounde…¹ n_unm…²
@@ -142,12 +140,12 @@ confounder looked like. First we will calculate the difference in scaled
142140
means.
143141

144142
``` r
145-
exdata_rr %>%
146-
dplyr::group_by(exposure) %>%
147-
dplyr::summarise(m = mean(.unmeasured_confounder / sd(.unmeasured_confounder))) %>%
143+
exdata_rr |>
144+
dplyr::group_by(exposure) |>
145+
dplyr::summarise(m = mean(.unmeasured_confounder / sd(.unmeasured_confounder))) |>
148146
tidyr::pivot_wider(names_from = exposure,
149147
values_from = m,
150-
names_prefix = "u_") %>%
148+
names_prefix = "u_") |>
151149
dplyr::summarise(estimate = u_1 - u_0)
152150
```
153151

@@ -168,7 +166,7 @@ mod_true <- glm(
168166
data = exdata_rr,
169167
family = poisson)
170168

171-
mod_true %>%
169+
mod_true |>
172170
broom::tidy(exponentiate = TRUE, conf.int = TRUE)
173171
```
174172

@@ -203,14 +201,11 @@ tip_with_binary(effect_observed = 1.09,
203201
unexposed_confounder_prev = 0.10)
204202
```
205203

206-
## ℹ The observed effect (1.09) WOULD be tipped by 1 unmeasured confounder with
207-
## the following specifications:
208-
## • estimated prevalence of the unmeasured confounder in the exposed population:
209-
## 0.25
210-
## • estimated prevalence of the unmeasured confounder in the unexposed
211-
## population: 0.1
212-
## • estimated relationship between the unmeasured confounder and the outcome:
213-
## 1.64
204+
## The observed effect (1.09) WOULD be tipped by 1 unmeasured confounder
205+
## with the following specifications:
206+
## * estimated prevalence of the unmeasured confounder in the exposed population: 0.25
207+
## * estimated prevalence of the unmeasured confounder in the unexposed population: 0.1
208+
## * estimated relationship between the unmeasured confounder and the outcome: 1.64
214209

215210
## # A tibble: 1 × 6
216211
## effect_adjusted effect_observed exposed_confounder_p…¹ unexp…² confo…³ n_unm…⁴
@@ -236,12 +231,11 @@ tip(effect_observed = 1.09,
236231
confounder_outcome_effect = 1.05)
237232
```
238233

239-
## ℹ The observed effect (1.09) WOULD be tipped by 7 unmeasured confounders with
240-
## the following specifications:
241-
## • estimated difference in scaled means between the unmeasured confounder in the
242-
## exposed population and unexposed population: 0.25
243-
## • estimated relationship between the unmeasured confounder and the outcome:
244-
## 1.05
234+
## The observed effect (1.09) WOULD be tipped by 7 unmeasured confounders
235+
## with the following specifications:
236+
## * estimated difference in scaled means between the unmeasured confounder
237+
## in the exposed population and unexposed population: 0.25
238+
## * estimated relationship between the unmeasured confounder and the outcome: 1.05
245239

246240
## # A tibble: 1 × 5
247241
## effect_adjusted effect_observed exposure_confounder_effect confounde…¹ n_unm…²
@@ -266,19 +260,19 @@ function **broom** that can be directly fed into the `tip()` function.
266260
``` r
267261
if (requireNamespace("broom", quietly = TRUE) && requireNamespace("dplyr", quietly = TRUE)) {
268262
glm(outcome ~ exposure + measured_confounder, data = exdata_rr,
269-
family = poisson) %>%
270-
broom::tidy(conf.int = TRUE, exponentiate = TRUE) %>%
271-
dplyr::filter(term == "exposure") %>%
272-
dplyr::pull(conf.low) %>%
263+
family = poisson) |>
264+
broom::tidy(conf.int = TRUE, exponentiate = TRUE) |>
265+
dplyr::filter(term == "exposure") |>
266+
dplyr::pull(conf.low) |>
273267
tip(confounder_outcome_effect = 2.5)
274268
}
275269
```
276270

277-
## The observed effect (1.09) WOULD be tipped by 1 unmeasured confounder with
278-
## the following specifications:
279-
## estimated difference in scaled means between the unmeasured confounder in the
280-
## exposed population and unexposed population: 0.09
281-
## estimated relationship between the unmeasured confounder and the outcome: 2.5
271+
## The observed effect (1.09) WOULD be tipped by 1 unmeasured confounder
272+
## with the following specifications:
273+
## * estimated difference in scaled means between the unmeasured confounder
274+
## in the exposed population and unexposed population: 0.09
275+
## * estimated relationship between the unmeasured confounder and the outcome: 2.5
282276

283277
## # A tibble: 1 × 5
284278
## effect_adjusted effect_observed exposure_confounder_effect confounde…¹ n_unm…²

0 commit comments

Comments
 (0)