Skip to content

Commit 6095091

Browse files
committed
chnaged input formula so that uses : rather than * so that it doesnt implicitly include the effect modifiers also as prognostic variables
1 parent 0bf82e0 commit 6095091

File tree

3 files changed

+85
-17
lines changed

3 files changed

+85
-17
lines changed

R/prep_data.R

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,21 @@ prep_ipd <- function(form, data) {
1010
prep_ald <- function(form, data) {
1111

1212
all_term_labels <- attr(terms(form), "term.labels")
13+
trt_name <- get_treatment_name(form)
1314

14-
# Remove duplicates (since age and I(age^2) will both appear)
15+
# pull out original of transformed variable
16+
# remove duplicates (since X and I(X^2) will both appear)
1517
term.labels <- unique(gsub("I\\(([^)]+)\\^2\\)", "\\1", all_term_labels))
1618

19+
# remove treatment
20+
# interaction separate by :
21+
term.labels <- unlist(strsplit(term.labels, ":", fixed = TRUE))
22+
term.labels <- setdiff(term.labels, trt_name)
23+
1724
mean_names <- paste0("mean.", term.labels)
1825
sd_names <- paste0("sd.", term.labels) ##TODO: for maic do we need these?
1926
term_names <- c(mean_names, sd_names)
2027

21-
# remove treatment labels
22-
term_names <- sort(term_names[!grepl(pattern = "trt", term_names)])
23-
2428
# replace outcome variable name
2529
response_var <- all.vars(form)[1]
2630
response_names <- gsub(pattern = "y", replacement = response_var,

tests/testthat/test-parse_formula.R

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
# unit test functions in parse_formula.R
2+
# unit test functions in parse_formula.R and prep_data.R
33

44

55
test_that("test get_eff_mod_names", {
@@ -39,3 +39,53 @@ test_that("get_covariate_names", {
3939
expect_equal(get_covariate_names(y ~ x*z + z), c("x","z"))
4040
})
4141

42+
43+
test_that("prep_ald differenf formula formats", {
44+
45+
# mock data
46+
data <- data.frame(
47+
mean.X1 = 0.6065438,
48+
sd.X1 = 0.3917644,
49+
mean.X2 = 0.6273452,
50+
sd.X2 = 0.4031580,
51+
mean.X3 = 0.5579042,
52+
sd.X3 = 0.4077155,
53+
mean.X4 = 0.6122686,
54+
sd.X4 = 0.4466750,
55+
y.C.sum = 36,
56+
y.C.bar = 0.5373134,
57+
y.C.sd = 0.5023689,
58+
N.C = 67,
59+
y.B.sum = 35,
60+
y.B.bar = 0.2631579,
61+
y.B.sd = 0.4420122,
62+
N.B = 133,
63+
stringsAsFactors = FALSE
64+
)
65+
66+
form <- as.formula("y ~ X3 + X4 + trt*X1 + trt*X2")
67+
68+
prep_ald(form, data)
69+
70+
form <- as.formula("y ~ X3 + X4 + trt + X1 + X2 + trt*X1 + trt*X2")
71+
72+
prep_ald(form, data)
73+
74+
form <- as.formula("y ~ X3 + X4 + trt*(X1 + X2)")
75+
76+
prep_ald(form, data)
77+
78+
form <- as.formula("y ~ X3 + X4 + trt:(X1 + X2)")
79+
80+
prep_ald(form, data)
81+
82+
form <- as.formula("y ~ X3 + X4 + trt:X1 + trt:X2")
83+
84+
prep_ald(form, data)
85+
86+
form <- as.formula("y ~ X3 + X4 + trt + trt:X1 + trt:X2")
87+
88+
prep_ald(form, data)
89+
90+
})
91+

vignettes/Binary_data_example.Rmd

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -235,28 +235,42 @@ A `strategy` argument of `outstandR` takes functions called
235235
particular method required, e.g. `strategy_maic()` for MAIC. Each
236236
specific example is provided below.
237237

238-
### MAIC
239-
240-
Using the individual level data for *AC* firstly we perform
241-
non-parametric bootstrap of the `maic.boot` function with `R = 1000`
242-
replicates. This function fits treatment coefficient for the marginal
243-
effect for *A* vs *C*. The returned value is an object of class `boot`
244-
from the `{boot}` package. We then calculate the bootstrap mean and
245-
variance in the wrapper function `maic_boot_stats`.
238+
### Model formula
246239

247-
Defining $X_1,X2$ as effect modifiers and $X_3,X_4$ as prognostic variables then the formula used in this model is
240+
Defining $X_1, X_2$ as effect modifiers, $X_3, X_4$ as prognostic variables and $Z$ the treatment indicator then the formula used in this model is
248241

249242
$$
250-
y = X_3 + X_4 + \beta_t X_1 + \beta_t X_2
243+
y = X_3 + X_4 + Z + Z X_1 + Z X_2
251244
$$
252245

253246
which corresponds to the following `R` `formula` object passed as an
254247
argument to the strategy function.
255248

256249
```{r}
257-
lin_form <- as.formula("y ~ X3 + X4 + trt*X1 + trt*X2")
250+
lin_form <- as.formula("y ~ X3 + X4 + trt + trt:X1 + trt:X2")
251+
```
252+
253+
Note that the more succinct formula
254+
255+
```{r, eval=FALSE}
256+
y ~ X3 + X4 + trt*(X1 + X2)
258257
```
259258

259+
Would also include $X_1, X_2$ as prognostic factors so in not equivalent, but could be modified as follows.
260+
261+
```{r, eval=FALSE}
262+
y ~ X3 + X4 + trt*(X1 + X2) - X1 - X2
263+
```
264+
265+
### MAIC
266+
267+
Using the individual level data for *AC* firstly we perform
268+
non-parametric bootstrap of the `maic.boot` function with `R = 1000`
269+
replicates. This function fits treatment coefficient for the marginal
270+
effect for *A* vs *C*. The returned value is an object of class `boot`
271+
from the `{boot}` package. We then calculate the bootstrap mean and
272+
variance in the wrapper function `maic_boot_stats`.
273+
260274
```{r outstandR_maic}
261275
outstandR_maic <-
262276
outstandR(AC.IPD, BC.ALD,
@@ -359,7 +373,7 @@ the previous analysis but we now use the `strategy_stc()` strategy
359373
function instead and a formula with centered covariates.
360374

361375
$$
362-
y = X_3 + X_4 + \beta_t(X_1 - \bar{X_1}) + \beta_t(X_2 - \bar{X_2})
376+
y = X_3 + X_4 + Z + Z (X_1 - \bar{X_1}) + Z (X_2 - \bar{X_2})
363377
$$
364378

365379
However, `outstandR()` knows how to handle this so we can simply pass

0 commit comments

Comments
 (0)