km_plot_weight: Weighted KM plot

Description Usage Arguments Value Examples

View source: R/km_plot_weight.R

Description

Weighted KM plot

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
km_plot_weight(
  data.in,
  indicator.var = "indicator",
  class.of.int = NULL,
  prob.names = NULL,
  filename = NULL,
  tte = "AVAL",
  event = "event",
  trt = "trt",
  time.unit = "month",
  prefix.title = "In strata:"
)

Arguments

data.in

input data, patients in rows and variables in columns. This could be an output from ipw_strata() or ps_match_strata().

indicator.var

(string) column name of the strata indicator variable which must be numeric. Assume arm1 has strata labeling and arm2 does not have strata labeling. pts without strata labeling should be indicated as -1 (e.g. pts in the arm1, or pts in arm2 but with missing label). within arm1 (the arm with strata labeling), subclasss should be indicated as 0,1,2...

class.of.int

(list) classes (stratum) of interest. Request to be in list format. It could be subset of classes in arm1; it could also define combined classes. For example: class.of.int = list("class1"=0, "class2"=1, "class3"=2, "class2or3"="c(1,2)"). for "class2or3", Prob(class 2 or 3) will be calculated as Prob(class2) + Prob(class3)

prob.names

column names for the probability scores to be used as weights. The order of probnames should match the order of class.of.int. if probnames is NULL, the function will assume that the probnames are pred0, pred1, prod2, prod1or2 in the example in class.of.int.

filename

if it is not NULL, a png file will be generated

tte

(string) column name of the time to event variable

event

(string) column name of the event variable (1: event, 0: censor)

trt

(string) column name of the treatment variable. The variable is expected to be in factor format and the first level will be considered as reference (control) arm when calculating summary statistics.

time.unit

time unit to be marked in x axis

prefix.title

prefix for title

Value

return a list of plots with class of ggsurvplot

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
 
library(dplyr)
clinical_1 <- clinical %>% mutate( 
  indicator = case_when(
    STRATUM == "strata_1" ~ 0, 
    STRATUM == "strata_2" ~ 1,
    is.na(STRATUM) & ARM == "experimental" ~ 1,
    TRUE ~ -1 
  ),
  ARM  = factor(ARM, levels = c("control","experimental")),
  BNLR = case_when(
    is.na(BNLR) ~ median(BNLR, na.rm = TRUE),
    TRUE ~ BNLR
  )
)
ipw_res1 <- ipw_strata(
  data.in = clinical_1, formula = indicator ~ BECOG + SEX + BNLR,
  indicator.var = "indicator", tte = "OS_MONTH", event = "OS_EVENT", trt = "ARM",
  class.of.int = list("strata_1" = 1, "strata_2" = 0)
 )
 km_plot_weight(ipw_res1$data,   
   indicator.var = "indicator", tte = "OS_MONTH", event = "OS_EVENT", 
   trt = "ARM", class.of.int = list("strata_2" = 0))
ps_res1 <- ps_match_strata(
  data.in = clinical_1, formula = indicator ~ BECOG + SEX + BNLR,
  indicator.var = "indicator", tte = "OS_MONTH", event = "OS_EVENT", trt = "ARM",
  class.of.int = list("strata_1" = 1, "strata_2" = 0)
 )
 km_plot_weight(ps_res1$data,   
   indicator.var = "indicator", tte = "OS_MONTH", event = "OS_EVENT", 
   trt = "ARM", class.of.int = list("strata_1" = 1, "strata_2" = 0)) 
   

PropensitySub documentation built on July 29, 2021, 9:07 a.m.