winratio: Win Ratio for Prioritized Outcomes and 95% Confidence...

Description Usage Arguments Details Value Examples

View source: R/winratio.R

Description

Calculate the win ratio for prioritized outcomes and the 95% confidence interval based on Bebu and Lachin (2016). Three type of outcomes can be analyzed: survival "failure-time" events, repeated survival "failure-time" events and continuous or ordinal "non-failure time" events that are captured at specific time-points in the study.

Usage

1
winratio(id, trt, active = NULL, outcomes, fu, data, keep.matrix = FALSE)

Arguments

id

a string indicating the patient ID variable. The patient ID variable must not contain missing values or duplicates.

trt

a string indicating the treatment variable. The variable can be of any type (binary, numeric, character, factor) and must imperatively have 2 unique values/levels.

active

a numeric or string value used to define the active treatment group for the calculation of the win ratio. If active = NULL (default value), active group is automatically determined according to the type of treatment variable:

  • binary variable: active group = 1.

  • numeric variable: active group = maximum value.

  • character variable: active group = last string after sorting the character variable in ascending order.

  • factor variable: active group = last level.

outcomes

a list used to define all outcomes in order of priority. The first element to be defined must be the outcome considered as being of greater clinical importance, usually this outcome is a fatal event. Each element must be a character vector of length 3 or a character list of length 3 depending on the type of outcome (survival event, repeated survival event, continuous or ordinal event):

  • for survival events, the element is a character vector c(x, "s", y), where x is a string indicating the name of the event variable, "s" indicating that this outcome is a "failure-time" event, and y is a string indicating the name of the time-to-event variable.

  • for repeated survival events, note k the maximum number of events observed during follow-up, the element is a character list list(x, "r", y), where x = c(x1, ..., xk) is a character vector of length k indicating the name of event variables, "r" indicating that this outcome is a "failure-time" repeated event, and y = c(y1, ..., yk) is a character vector of length k indicating the name of time-to-event variables corresponding to the event variables.

  • for continuous or ordinal events, the element is a character vector c(x, "c", d), where x is a string indicating the name of the continuous or ordinal variable, "c" indicating that this outcome is a continuous or ordinal event, and d is a string with two options "<" or ">" indicating the direction of deterioration or worsening.

fu

a string indicating the name of the follow-up time variable.

data

a data frame containing all the variables listed in the id, trt, outcomes and fu arguments.

keep.matrix

a logical value indicating if the 'win-loss' matrix is kept. Default value is FALSE.

Details

'win-loss' matrix

Let n1 the number of patients in the active group and n0 the number of patients in the other group. The 'win-loss' matrix is a matrix M of dimension n1 x n0 with its element M[i,j] is defined as:

M[i,j] = 1 if i wins against j on 1st outcome,

M[i,j] = -1 if i loses against j on 1st outcome,

M[i,j] = k if i wins on outcome k after ties with j on outcomes 1 to (k-1),

M[i,j] = -k if i loses on outcome k after ties with j on outcomes 1 to (k-1),

M[i,j] = 0 if i and j ties on all outcomes.

Value

call

a list with all arguments entered list(id, trt, active, outcomes, fu, data, keep.matrix).

group1

the value/level of the active group (group 1).

group0

the value/level of the other group (group 0).

n1

the number of subjects in group 1.

n0

the number of subjects in group 0.

n

the total number of subjects.

wins

a vector of numbers of 'winners' for each outcome.

loss

a vector of numbers of 'losers' for each outcome.

total.wins

the total number of 'winners'.

total.loss

the total number of 'losers'.

total.ties

the total number of ties.

wr

the win ratio.

v

the estimated variance of win ratio.

z

the value of the test statistic.

p.value

the p-value of the test.

wr.lower

the lower end of the 95% confidence interval.

wr.upper

the upper end of the 95% confidence interval.

wr.matrix

the 'win-loss' matrix (only if keep.matrix = T). See details above.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Load survival package to use the dataset 'bladder1'
library(survival)

# Creation of dataset 'df' with 3 outcomes:
#   Outcome 1: death (survival event)
#   Outcome 2: cancer recurrence (repeated survival event)
#   Outcome 3: size of largest initial tumour (continuous event) 
data1 <- bladder1  %>%  
  mutate(trt = if_else(treatment == "placebo", "Placebo", "Treatment")) %>%
  group_by(id) %>% 
  mutate(death = if_else(max(status) %in% c(2, 3), 1, 0),
         t2death = max(stop)) %>% 
  ungroup() %>%
  select(id, trt, death, t2death, number, size) %>% 
 unique()

data2 <- bladder1 %>% 
  filter(status == 1) %>% 
  select(id, t2recurr = stop) %>%
  mutate(recurr = 1) %>% 
  arrange(id, t2recurr) %>% 
  group_by(id) %>% 
  mutate(nrecurr = row_number()) %>% 
  ungroup() %>% 
  full_join((data1 %>% select(id)), by = "id") %>% 
  complete(id, nrecurr) %>%
  filter(!is.na(nrecurr)) %>% 
  full_join((data1 %>% select(id, t2death)), by = "id") %>% 
  mutate(
    recurr = replace(recurr, is.na(recurr), 0),
    t2recurr = if_else(is.na(t2recurr), t2death, t2recurr)
  ) %>% 
  select(id, nrecurr, recurr, t2recurr)

data3 <- data2 %>% 
  pivot_wider(id_cols = "id", names_from =  nrecurr, 
              values_from = recurr, names_prefix  = "recurr") 

data4 <- data2 %>% 
  pivot_wider(id_cols = "id", names_from =  nrecurr, 
              values_from = t2recurr, names_prefix  = "t2recurr") 

data5 <- full_join(data3, data4, by = "id")

df <- full_join(data1, data5, by = "id")

# Calculate the win ratio
wr <- winratio(id = "id", trt = "trt", active = "Treatment", 
               outcomes = list(outc1 = c("death", "s", "t2death"),
                               outc2 = list(paste0("recurr", 1:9), "r", paste0("t2recurr", 1:9)),
                               outc3 = c("size", "c", ">")), 
               fu = "t2death", data = df)
summary(wr)

WinRatio documentation built on Nov. 23, 2020, 9:06 a.m.