mb_weight | R Documentation |

Magirr and Burman (2019) have proposed a weighted logrank test to have better power than the logrank test when the treatment effect is delayed, but to still maintain good power under a proportional hazards assumption. In Magirr (2021), (the equivalent of) a maximum weight was proposed as opposed to a fixed time duration over which weights would increase. The weights for some early interval specified by the user are the inverse of the combined treatment group empirical survival distribution; see details. After this initial period, weights are constant at the maximum of the previous weights. Another advantage of the test is that under strong null hypothesis that the underlying survival in the control group is greater than or equal to underlying survival in the experimental group, Type I error is controlled as the specified level.

```
mb_weight(x, delay = 4, wmax = Inf)
```

`x` |
a |

`delay` |
The initial delay period where weights increase; after this, weights are constant at the final weight in the delay period |

`wmax` |
Maximum weight to be returned.
set |

This function computes Magirr-Burman weights and adds them to a dataset created by the `counting_process()`

function.
These weights can then be used to compute a Z-statistic for the modestly weighted logrank test proposed.

We define `t^*`

to be the input variable `delay`

.
This specifies an initial period during which weights increase.
We also set a maximum weight `w_max`

.
To define specific weights, we let `S(t)`

denote the Kaplan-Meier survival estimate at time `t`

for the combined data (control plus experimental treatment groups).
The weight at time `t`

is then defined as

`w(t)=\min(w_max, S(\min(t,t^*))^{-1}).`

a vector with weights for the Magirr-Burman weighted logrank test
for the data in `x`

Magirr, Dominic, and Carl‐Fredrik Burman.
"Modestly weighted logrank tests."
*Statistics in Medicine* 38.20 (2019): 3782–3790.

Magirr, Dominic.
"Non‐proportional hazards in immuno‐oncology: Is an old perspective needed?"
*Pharmaceutical Statistics* 20.3 (2021): 512–527.

```
library(tidyr)
library(dplyr)
# Use default enrollment and event rates at cut at 100 events
# For transparency, may be good to set either `delay` or `wmax` to Inf`
x <- sim_pw_surv(n = 200) %>%
cut_data_by_event(125) %>%
counting_process(arm = "Experimental")
# example 1
# compute Magirr-Burman weights with `delay = 6`
ZMB <- x %>%
mb_weight(delay = 6, wmax = Inf) %>%
summarize(S = sum(o_minus_e * mb_weight),
V = sum(var_o_minus_e * mb_weight^2),
Z = S / sqrt(V))
# Compute p-value of modestly weighted logrank of Magirr-Burman
pnorm(ZMB$Z)
# example 2
# Now compute with maximum weight of 2 as recommended in Magirr, 2021
ZMB2 <- x %>%
mb_weight(delay = Inf, wmax = 2) %>%
summarize(S = sum(o_minus_e * mb_weight),
V = sum(var_o_minus_e * mb_weight^2),
Z = S / sqrt(V))
# Compute p-value of modestly weighted logrank of Magirr-Burman
pnorm(ZMB2$Z)
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.