Skip to content

Commit f023b75

Browse files
committed
added sd from ipd for agd
1 parent 027923a commit f023b75

File tree

2 files changed

+34
-19
lines changed

2 files changed

+34
-19
lines changed

vignettes/bibliography.bib

Whitespace-only changes.

vignettes/comparison-with-other-packages.Rmd

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: "Comparison with other packages"
33
output: rmarkdown::html_vignette
44
vignette: >
5-
%\VignetteEncoding{UTF-8}
5+
%\VignetteEncoding{UTF-8}
66
%\VignetteEngine{knitr::rmarkdown}
77
editor_options:
88
chunk_output_type: console
@@ -11,28 +11,34 @@ vignette: >
1111

1212
```{r, include = FALSE}
1313
knitr::opts_chunk$set(
14-
collapse = TRUE,
15-
comment = "#>"
14+
collapse = TRUE,
15+
comment = "#>"
1616
)
1717
```
1818

1919
```{r setup, warning=FALSE, message=FALSE}
2020
library(outstandR)
2121
```
2222

23-
There are already a few widely-used R packages in CRAN to perform model-based standardization, such as [`{marginaleffects}`](https://marginaleffects.com/) and [`{stdReg}/{StdReg2}`](https://sachsmc.github.io/stdReg2/).
23+
The aim of this document is to compare the results from various other R packages with those produced using `{outstandR}`.
24+
There are already a few widely-used R packages on CRAN to perform model-based standardization, such as [`{marginaleffects}`](https://marginaleffects.com/) and [`{stdReg}/{stdReg2}`](https://sachsmc.github.io/stdReg2/).
2425

2526
## marginaleffects
2627

28+
The `{marginaleffects}` package has functions to calculate G-computation estimates.
29+
2730
```{r , warning=FALSE, message=FALSE}
2831
##TODO: see unit tests
2932
library(marginaleffects)
33+
34+
# marginaleffects::avg_predictions()
35+
# marginaleffects::avg_comparisons()
3036
```
3137

3238

3339
## stdReg[2]
3440

35-
`{StdReg}` has been rewritten to produce `{StdReg2}` which has "nicer output, more available methods, the possibility to include new methods, and mainly to make maintenance and updating easier." So, for this reason, we will use `{StdReg2}`.
41+
The package `{stdReg}` has been rewritten to produce `{stdReg2}` which has "nicer output, more available methods, the possibility to include new methods, and mainly to make maintenance and updating easier." So, for this reason, we will use `{stdReg2}`.
3642

3743
We shall follow the article [_Estimation of causal effects using stdReg2_](https://sachsmc.github.io/stdReg2/articles/overview.html).
3844
This is for continuous outcomes (change in weight) and includes transformed covariates.
@@ -82,13 +88,15 @@ nhefs.X <- nhefs_ipd %>%
8288
list(mean = mean, sd = sd),
8389
.names = "{fn}.{col}"))
8490
85-
nhefs.B <- dplyr::filter(nhefs_ipd, trt == 1) |>
91+
nhefs.B <- nhefs_ipd |>
92+
dplyr::filter(trt == 1) |>
8693
summarise(y.B.sum = sum(y),
8794
y.B.bar = mean(y),
8895
y.B.sd = sd(y),
8996
N.B = n())
9097
91-
nhefs.C <- dplyr::filter(nhefs_ipd, trt == 0) |>
98+
nhefs.C <- nhefs_ipd |>
99+
dplyr::filter(trt == 0) |>
92100
summarise(y.C.sum = sum(y),
93101
y.C.bar = mean(y),
94102
y.C.sd = sd(y),
@@ -117,15 +125,15 @@ Alternatively, rather than dropping factors, we can create dummy variables to re
117125
```{r stdReg2-alternative2, warning=FALSE, message=FALSE}
118126
119127
nhefs_ipd <- nhefs_dat |>
120-
select(qsmk, sex, race, age, smokeintensity, smokeyrs, wt71,
121-
wt82_71, education, exercise, active) |>
122-
rename(trt = qsmk,
123-
y = wt82_71) |>
124-
mutate(sex = as.numeric(sex) - 1, # binary
125-
race = as.numeric(race) - 1) |>
128+
dplyr::select(qsmk, sex, race, age, smokeintensity, smokeyrs, wt71,
129+
wt82_71, education, exercise, active) |>
130+
dplyr::rename(trt = qsmk,
131+
y = wt82_71) |>
132+
dplyr::mutate(sex = as.numeric(sex) - 1, # binary
133+
race = as.numeric(race) - 1) |>
126134
maicplus::dummize_ipd(dummize_cols = c("education", "exercise", "active"),
127135
dummize_ref_level = c("1","0","0")) |>
128-
select(-education, -exercise, -active) # remove originals
136+
dplyr::select(-education, -exercise, -active) # remove originals
129137
130138
# # replace with this?
131139
# model.matrix()
@@ -176,15 +184,15 @@ The 2024 [ISPOR poster by Hatswell](https://www.ispor.org/heor-resources/present
176184
## maicplus
177185

178186
Roche developed the `maic` package which is now deprecated and replaced by `maicplus`.
179-
We will follow the article titled [Anchored Binary Analysis](https://hta-pharma.github.io/maicplus/main/articles/anchored_binary.html) to make our comparison.
187+
We will follow the article titled [Anchored Binary Analysis](https://hta-pharma.github.io/maicplus/main/articles/anchored_binary.html) which is part of their package to make our comparison.
180188

181189
```{r maicplus-original, warning=FALSE, message=FALSE}
182190
library(maicplus)
183191
184192
# Load required data
185193
data(centered_ipd_twt)
186-
data(adrs_twt)
187-
data("adsl_sat") # Original IPD
194+
data(adrs_twt) # response IPD
195+
data(adsl_sat) # covariates IPD
188196
189197
# Load required package
190198
library(dplyr)
@@ -262,6 +270,11 @@ AC.IPD <- adsl_twt |>
262270
y = RESPONSE) |>
263271
mutate(AGE_SQUARED = AGE^2)
264272
273+
# sd from IPD
274+
agd_sd <- AC.IPD |>
275+
summarise(across(c(AGE, AGE_SQUARED, SMOKE, ECOG0, N_PR_THER, SEX_MALE),
276+
.fns = sd, .names = "sd.{.col}"))
277+
265278
# transform names to format needed in outstandR
266279
# mean.* and y.*
267280
# note that we're nto going to use sd in matching
@@ -274,7 +287,7 @@ BC.ALD <- agd |>
274287
mean.N_PR_THER = N_PR_THER_MEDIAN) |>
275288
mutate(
276289
# mean.AGE_SQUARED = sd.AGE^2 + mean.AGE^2,
277-
mean.AGE_SQUARED = mean.AGE^2, ##TODO: this is a fudge. Use from IPD?
290+
# mean.AGE_SQUARED = mean.AGE^2, ##TODO: this is a fudge
278291
# sd.SEX_MALE = sqrt(mean.SEX_MALE * (1 - mean.SEX_MALE)),
279292
# sd.ECOG0 = sqrt(mean.ECOG0 * (1 - mean.ECOG0)),
280293
# sd.SMOKE = sqrt(mean.SMOKE * (1 - mean.SMOKE)),
@@ -284,7 +297,9 @@ BC.ALD <- agd |>
284297
y.B.bar = y.B.sum/N.B,
285298
N.C = 320,
286299
y.C.sum = binary_agd[binary_agd$ARM == "C" & binary_agd$RESPONSE == "YES", "COUNT"],
287-
y.C.bar = y.C.sum/N.C)
300+
y.C.bar = y.C.sum/N.C) |>
301+
cbind(agd_sd) |>
302+
relocate(N.B, y.B.sum, y.B.bar, N.C, y.C.sum, y.C.bar, .after = sd.SEX_MALE)
288303
289304
BC.ALD
290305
```

0 commit comments

Comments
 (0)