# In hoffmakl/tmleplus: What the Package Does (One Line, Title Case)

```knitr::opts_chunk\$set(
collapse = TRUE,
comment = "#>"
)
```
```library(knitr)
library(tmleplus)
```

# `surv_eff_mod()`

This function uses influence curves to calculate the difference and standard error in marginal cumulative incidence for an effect modification variable.

We demonstrate this by modifying the example from David Bankeser and Nima Hejazi's `survtmle` vignette.

We have 1000 observations with randomized treatment and randomized effect modification variables. The survival time (`ftime`) is affected by an interaction between the treatment and effect modification variable.

```set.seed(1234)
n <- 1000
t_0 <- 6
trt <- rbinom(n, 1, 0.5)
eff <- rbinom(n, 1, 0.5)
adjustVars <- data.frame(W1 = round(runif(n)), W2 = round(runif(n, 0, 2)))
ftime <- round(1 + runif(n, 1, 4) - trt*eff + adjustVars\$W1 + adjustVars\$W2)
ftype <- round(runif(n, 0, 1))
dat <- data.frame(trt, eff, adjustVars, ftime, ftype)
```

We can then stratify our data into patients with and without the effect modification variable and obtain `survtmle` estimates for the effect of treatment.

For observations without the effect modifier:

```dat_noeff <- dat[dat\$eff == 0,]
trt <- dat_noeff\$trt
ftime <- dat_noeff\$ftime
ftype <- dat_noeff\$ftype
fit_noeff <- survtmle::survtmle(ftime = ftime, ftype = ftype,
SL.trt = c("SL.glm", "SL.mean", "SL.step"),
SL.ftime = c("SL.glm", "SL.mean", "SL.step"),
SL.ctime = c("SL.glm", "SL.mean", "SL.step"),
method = "hazard", t0 = t_0)
```

For observations with the effect modifier:

```dat_eff <- dat[dat\$eff == 1,]
trt <- dat_eff\$trt
ftime <- dat_eff\$ftime
ftype <- dat_eff\$ftype
fit_eff <- survtmle::survtmle(ftime = ftime, ftype = ftype,
SL.trt = c("SL.glm", "SL.mean", "SL.step"),
SL.ftime = c("SL.glm", "SL.mean", "SL.step"),
SL.ctime = c("SL.glm", "SL.mean", "SL.step"),
method = "hazard", t0 = t_0)
```

Once we have obtained our two `survtmle` fits, we need only to specify the full data set, our effect modification variable, and the names of our `survtmle` objects.

```result <- surv_eff_mod(tmle_fit_0 = fit_a, tmle_fit_1 = fit_b)
```

The resulting data frame contains the estimate, standard error, 95% confidence intervals and p-values for...

1. The difference in the marginal cumulative incidence between treated and untreated patients amongst those with the effect modification variable.

2. The estimate and standard error for the difference in the marginal cumulative incidence between treated and untreated patients amongst those without the effect modification variable.

3. The overall difference and standard error between the effect modification groups.

```kable(result)
```

This result would indicate:

1. A significant effect on the marginal cumulative incidence at `t0` between the treated and untreated observations for those with the effect modification variable.

2. A non-significant effect on the marginal cumulative incidence at `t0` between the treated and untreated observations for those without the effect modification variable.

3. An overall significant modification effect on the marginal cumulative incidence at `t0` between the treated and untreated observations.

hoffmakl/tmleplus documentation built on Aug. 31, 2020, 4:33 p.m.