Loading packages and data

if (!require(gClinBiomarker)) { 
  install_github("RPackages/gClinBiomarker",  host="https://github.roche.com/api/v3")
  library(gClinBiomarker)
}

library(knitr)
library(devtools)
library(ggplot2)
data(input)
sample.data <- input

Example data set

head(sample.data)

str(sample.data)

SummaryVars(): Summarize demographics variables (check demographics imbalance)

Default

kable(
SummaryVars(data=sample.data,trt='Arm', subgroup='BEP', var=c('Age','Sex'), 
       var.class=c("numeric","categorical"))
)

Compare to non-BEP instead of ITT

kable(
SummaryVars(data=sample.data,trt='Arm', subgroup='BEP', var=c('Age','Sex'), 
       var.class=c("numeric","categorical"), compare.subgroup=TRUE)
)

Allow testing

kable(
SummaryVars(data=sample.data,trt='Arm', subgroup='BEP', var=c('Age','Sex'), 
       var.class=c("numeric","categorical"), test.subgroup=TRUE)
)

Reorder TRT/CTRL arm in display

kable(
SummaryVars(data=sample.data,trt='Arm', subgroup='BEP', var=c('Age','Sex'), 
       var.class=c("numeric","categorical"), trt.order=c("TRT","CTRL"))
)

Combine trt arms

kable(
SummaryVars(data=sample.data, subgroup='BEP', var=c('Age','Sex'), 
       var.class=c("numeric","categorical"))
)

Alternative BEP indicator

sample.data$BEP2 <- ifelse(sample.data$BEP==1,"Yes","No")
kable(
SummaryVars(data=sample.data,trt='Arm', subgroup='BEP2', var=c('Age','Sex'), 
       var.class=c("numeric","categorical"), subgroup.indicator="Yes")
)

PlotProperty(): Plot biomarker, clinical covariate property and their association

Numeric biomarker variable. No clinical variables. Log transformation.

PlotProperty(data=input, biomarker.var="KRAS.exprs", biomarker.class="numeric", log2=TRUE)

No biomarker variable. Two numeric clinical variables. Log transformation for one varible.

PlotProperty(data=input, biomarker.var=NULL, biomarker.class=NULL,
             var=c("Weight","Age"), var.class=c("numeric", "numeric"),
             log2=c(TRUE, FALSE), par.param = list(mfrow=c(1,2), cex.axis=1.2))

Numeric biomarker variable. Two clinical categorical variables. Log transformation for numeric variable.

PlotProperty(data=input, biomarker.var="KRAS.exprs", biomarker.class="numeric",
             var=c("ECOG", "Country"), var.class=c("categorical", "categorical"),
             log2=TRUE, par.param = list(mfrow=c(3,2), cex.axis=1.2),
             show.clinical.uni=TRUE)

Numeric biomarker variable. Two clinical variables: one is categorocal, second is numeric. Log transformation for biomarker (numeric) variable.

PlotProperty(data=input, biomarker.var="KRAS.exprs", biomarker.class="numeric",
             var=c("Sex", "Age"), var.class=c("categorical", "numeric"),
             log2=c(TRUE, FALSE, FALSE), par.param = list(mfrow=c(3,2), cex.axis=1.4),
             show.clinical.uni=TRUE)

Categorical biomarker variable. Categorical clinical variable.

PlotProperty(data=input, biomarker.var="KRAS.mutant", biomarker.class="categorical",
             var="Country", var.class="categorical", 
             par.param = list(mfrow=c(2,2), cex.axis=1.2),
             show.clinical.uni=TRUE)

Categorial biomarker variable. Categorical and numeric clinical variables. No log transformation.

PlotProperty(data=input, biomarker.var="KRAS.mutant", biomarker.class="categorical",
             var=c("Country", "Age"), var.class=c("categorical", "numeric"),
             par.param = list(mfrow=c(3,2), cex.axis=1.2),
             show.clinical.uni=TRUE)

Categorial biomarker variable. Categorical and numeric clinical variables. No log transformation. Don't plot biomarker variable but plot clinical variables and association between biomarker and clinical variables.

PlotProperty(data=input, biomarker.var="KRAS.mutant", biomarker.class="categorical",
             var=c("Country", "Age"), var.class=c("categorical", "numeric"),
             par.param = list(mfrow=c(2,2), cex.axis=1.2), show.biomarker.uni = FALSE,
             show.clinical.uni=TRUE)

Categorial biomarker variable. Categorical and numeric clinical variables. No log transformation. Don't plot clinical variables but plot biomarker variable and association between biomarker and clinical variables.

PlotProperty(data=input, biomarker.var="KRAS.mutant", biomarker.class="categorical",
             var=c("Country", "Age"), var.class=c("categorical", "numeric"),
             par.param = list(mfrow=c(2,2), cex.axis=1.2))

Categorial biomarker variable. Categorical and numeric clinical variables. No log transformation. Don't plot association between variables but plot biomarker and clinical variables.

PlotProperty(data=input, biomarker.var="KRAS.mutant", biomarker.class="categorical",
             var=c("Country", "Age"), var.class=c("categorical", "numeric"),
             par.param = list(mfrow=c(2,2), cex.axis=1.2), show.association = FALSE,
             show.clinical.uni=TRUE)

Categorial biomarker variable. Categorical and numeric clinical variables. No log transformation. Plot only association between variables.

PlotProperty(data=input, biomarker.var="KRAS.mutant", biomarker.class="categorical",
             var=c("Country", "Age"), var.class=c("categorical", "numeric"),
             par.param = list(mfrow=c(1,2), cex.axis=1.2), 
             show.biomarker.uni = FALSE)

Categorial biomarker variable. Categorical and numeric clinical variables. No log transformation. Plot only clinical variables.

PlotProperty(data=input, biomarker.var="KRAS.mutant", biomarker.class="categorical",
             var=c("Country", "Age"), var.class=c("categorical", "numeric"),
             par.param = list(mfrow=c(1,2), cex.axis=1.1),
             show.biomarker.uni = FALSE, show.association = FALSE, 
             show.clinical.uni = TRUE)

Categorial biomarker variable. Categorical and numeric clinical variables. No log transformation. Plot only biomarker variable.

PlotProperty(data=input, biomarker.var="KRAS.mutant", biomarker.class="categorical",
             var=c("Country", "Age"), var.class=c("categorical", "numeric"),
             par.param = list(cex.axis=1.2),
             show.association = FALSE)

PlotRspBar(): Compare response outcome across different population

Plot response of one population

PlotRspBar (input, outcome.var="Response",
            rsp.levels=c("CR", "PR","SD","NON CR/PD", "PD","NE"))

Plot response of one population, binarize outcome (classify classes to responder vs non responder)

PlotRspBar (input, outcome.var="Response", 
            binary=TRUE,
            rsp.response = c("CR","PR"),
            rsp.nonresponse = c("SD", "PD","NON CR/PD","NE",NA))

Change color

PlotRspBar (input, outcome.var="Response", 
            binary=TRUE,
            rsp.response = c("CR","PR"),
            rsp.nonresponse = c("SD", "PD","NON CR/PD","NE",NA),
            col=c("green","orange"))

Plot horizontally

PlotRspBar (input, outcome.var="Response", 
            binary=TRUE,
            rsp.response = c("CR","PR"),
            rsp.nonresponse = c("SD", "PD","NON CR/PD","NE",NA),
            horiz=TRUE)

By arm

PlotRspBar (input, outcome.var="Response", 
            binary=FALSE,
            rsp.levels=c("CR", "PR","SD","NON CR/PD", "PD","NE"),
            trt="Arm")

PlotRspBar (input, outcome.var="Response", 
            binary=TRUE,
            rsp.response = c("CR","PR"),
            rsp.nonresponse = c("SD", "PD","NON CR/PD","NE",NA),
            trt="Arm")

Compare full population vs BEP

PlotRspBar (input, outcome.var="Response", 
            binary=TRUE,
            rsp.response = c("CR","PR"),
            rsp.nonresponse = c("SD", "PD","NON CR/PD","NE",NA),
            trt="Arm", compare.bep=TRUE,bep="BEP")

Compare subgroups

PlotRspBar (input, outcome.var="Response", 
            binary=TRUE,
            rsp.response = c("CR","PR"),
            rsp.nonresponse = c("SD", "PD","NON CR/PD","NE",NA),
            trt="Arm", compare.var=TRUE,var="KRAS.mutant")

Plot count instead of percentage

PlotRspBar (input, outcome.var="Response", 
            binary=FALSE,
            rsp.levels=c("CR", "PR","SD","NON CR/PD", "PD","NE"),
            trt="Arm", 
            compare.var=TRUE,var="Sex", plot.count = TRUE)

PlotKM(): Plot KM curves for subpopulations

Without subgroup

print(PlotKM(data=sample.data, tte="PFS",cen="PFS.event", 
             main="PFS ITT"))

Without subgroup, BEP

print(PlotKM(data=sample.data, bep="BEP",
             tte="PFS",cen="PFS.event", main="PFS BEP"))

By TRT

print(PlotKM(data=sample.data, tte="PFS",cen="PFS.event", 
             main="PFS ITT by treatment", trt="Arm"))

By TRT, change color, line type

print(PlotKM(data=sample.data, tte="PFS",cen="PFS.event", 
             main="PFS ITT by treatment", trt="Arm",
             col=c("orange","brown"),lty=c(1,2)))

Mark median PFS, no grid

print(PlotKM(data=sample.data, tte="PFS",cen="PFS.event", 
             main="PFS ITT by treatment", 
       trt="Arm", 
       plot.grid = FALSE, 
       plot.median=T))

By KRAS.mutant only

print(PlotKM(data=sample.data, tte="PFS",cen="PFS.event", 
             main="OS BEP by treatment, by KRAS mutation", 
              var="KRAS.mutant"))
print(PlotKM(data=sample.data, tte="PFS",cen="PFS.event", 
             main="OS BEP by treatment, by KRAS mutation", 
              var="KRAS.mutant", col=c("skyblue","darkgray")))

By TRT and KRAS.mutant

print(PlotKM(data=sample.data, tte="PFS",cen="PFS.event", 
             main="OS BEP by treatment, by KRAS mutation", 
             trt="Arm", var="KRAS.mutant"))

By TRT and KRAS.mutant, change color and line type

print(PlotKM(data=sample.data, tte="PFS",cen="PFS.event", 
             main="PFS BEP by treatment, by KRAS mutation", 
             trt="Arm", var="KRAS.mutant",
             col=c("orange","orange","brown","brown"),
             lty=c(3,1,3,1)))

By TRT and KRAS.expression (continuous biomarker, cut at median)

print(PlotKM(data=sample.data, tte="PFS",cen="PFS.event", 
             main="PFS BEP by treatment, by KRAS expression", 
             trt="Arm", var="KRAS.exprs", var.class="numeric",
             percentile.cutoff=0.5,xlim=c(0,18))
             )

By TRT and KRAS.expression (continuous biomarker, cut at a numerical cutoff)

print(PlotKM(data=sample.data, tte="PFS",cen="PFS.event", 
             main="PFS BEP by treatment, by KRAS expression", 
             trt="Arm", var="KRAS.exprs", var.class="numeric",
             numerical.cutoff=100)
             )

By TRT and KRAS.expression (continuous biomarker, cut at a numerical cutoff). High group defined as "greater than", instead of "greater than or equal to"

print(PlotKM(data=sample.data, tte="PFS",cen="PFS.event", 
             main="PFS BEP by treatment, by KRAS expression", 
             trt="Arm", var="KRAS.exprs", var.class="numeric",
             numerical.cutoff=100, equal.in.high = F)
             )

By TRT and KRAS.expression , more than 2 groups

print(PlotKM(data=sample.data, tte="PFS",cen="PFS.event",  
             main="PFS BEP by treatment, by KRAS expression", 
             trt="Arm", var="KRAS.exprs", var.class="numeric",
             numerical.cutoff=c(100,500), xlim=c(0, 20))
             )
print(PlotKM(data=sample.data, tte="PFS",cen="PFS.event", 
             main="PFS BEP by treatment, by KRAS expression", 
             trt="Arm", var="KRAS.exprs", var.class="numeric",
             numerical.cutoff=c(100,500),
             col=c("green","green","green","brown","brown","brown"),
             xlim=c(0,20))
             )

More flexibility, reorder subgroups

print(PlotKM(data=sample.data, tte="OS",cen="OS.event", 
             main="OS BEP by treatment, by KRAS mutation", 
             varlist=c("Arm","KRAS.mutant"), 
             varlist.levels=list(c("TRT","CTRL"),c("Wild Type","Mutant")),
             legend.loc="left"))

By TRT and KRAS.mutant, reorder and rename

print(PlotKM(data=sample.data, tte="OS",cen="OS.event", bep="BEP",
             main="OS BEP by treatment, by KRAS mutation", varlist=c("Arm","KRAS.mutant"), 
             varlist.levels=list(c("TRT","CTRL"),c("Wild Type","Mutant")),
             varlist.labels=list(c("trt","ctrl"),c("wt","mut")),
               plot.median=T,legend.loc="left"))

Legend location

print(PlotKM(data=sample.data, tte="PFS",cen="PFS.event", 
             var=c("Arm","KRAS.mutant"), 
             bep="BEP", legend.loc=NULL, legend.x=5, legend.y=.8))

PlotTabForestBiomarker() : forest plot and summary statistics table for a single biomarker (include cutoff exploration for cont. biomarker )

Survival outcome, 2-arm, categorical variable

by default BEP will be defined as patients non-NA biomarker measurement

PlotTabForestBiomarker(data=input,
                                  outcome.class="survival",
                                  outcome.var=c("PFS","PFS.event"),
                                  trt="Arm",
                                  var="KRAS.mutant", 
                                  var.class="categorical")

Survival outcome, another format

PlotTabForestBiomarker(data=input,
                                  outcome.class="survival",
                                  outcome.var=c("PFS","PFS.event"),
                                  trt="Arm",
                                  var="KRAS.mutant", 
                                  var.class="categorical",
                                  tabforest = TRUE)

Survival outcome, 2-arm, categorical variable, don't show ITT, BEP, rename variable name in display

user can also define BEP column

PlotTabForestBiomarker(data=input,
                                  outcome.class="survival",
                                  outcome.var=c("PFS","PFS.event"),
                                  trt="Arm",
                                  var="KRAS.mutant", 
                                  var.class="categorical",
                                  bep = 'BEP', 
                                  bep.indicator=1)
PlotTabForestBiomarker(data=input,
                                  outcome.class="survival",
                                  outcome.var=c("PFS","PFS.event"),
                                  trt="Arm",
                                  var="KRAS.mutant", 
                                  var.class="categorical", 
                                  var.name="KRAS mut",
                                  show.itt=FALSE, 
                                  show.bep=FALSE)

Survival outcome, 2-arm, continuous variable, greater than some percentage cutoffs

PlotTabForestBiomarker(data=input,
                                  outcome.class="survival",
                                  outcome.var=c("PFS","PFS.event"),
                                  trt="Arm",
                                  var="KRAS.exprs", 
                                  var.class="numeric", var.name="KRAS exprs",
                                  percentile.cutoff=c(.25,.5,.75), 
                              #  cols=c("black","black","darkgreen","darkgreen","darkgreen"),
                                  numerical.cutoff=NULL,
                                  greater=TRUE, less=FALSE,
                                  within.bin=FALSE,
                                  show.itt=TRUE, show.bep=TRUE)

Survival outcome, 2-arm, continuous variable, less than some percentage cutoffs

PlotTabForestBiomarker(data=input,
                                  outcome.class="survival",
                                  outcome.var=c("PFS","PFS.event"),
                                  trt="Arm",
                                  var="KRAS.exprs", 
                                  var.class="numeric", var.name="KRAS exprs",
                                  percentile.cutoff=c(.25,.5,.75), 
                                  numerical.cutoff=NULL,
                                  greater=FALSE, less=TRUE,
                                  within.bin=FALSE,
                                  show.itt=TRUE, show.bep=TRUE,
                                  bep = 'BEP', bep.indicator=1)

Survival outcome, 2-arm, continuous variable, greater and less than some percentage cutoffs

PlotTabForestBiomarker(data=input,
                                  outcome.class="survival",
                                  outcome.var=c("PFS","PFS.event"),
                                  trt="Arm",
                                  var="KRAS.exprs", 
                                  var.class="numeric", var.name="KRAS exprs",
                                  percentile.cutoff=c(.25,.5,.75), 
                                  numerical.cutoff=NULL,
                                  greater=TRUE, less=TRUE,
                                  within.bin=FALSE,
                                  show.itt=TRUE, show.bep=TRUE)

"Less" rows next to "Greater" rows:

PlotTabForestBiomarker(data=input,
                                  outcome.class="survival",
                                  outcome.var=c("PFS","PFS.event"),
                                  trt="Arm",
                                  var="KRAS.exprs", 
                                  var.class="numeric", var.name="KRAS exprs",
                                  percentile.cutoff=c(.25,.5,.75), 
                                  numerical.cutoff=NULL,
                                  greater=TRUE, less=TRUE, greater.by.less = TRUE,
                                  within.bin=FALSE,
                                  show.itt=TRUE, show.bep=TRUE)

Survival outcome, 2-arm, continuous variable, within cutoff bin

PlotTabForestBiomarker(data=input,
                                  outcome.class="survival",
                                  outcome.var=c("PFS","PFS.event"),
                                  trt="Arm",
                                  var="KRAS.exprs", 
                                  var.class="numeric", var.name="KRAS exprs",
                                  percentile.cutoff=c(.25,.5,.75), 
                                  numerical.cutoff=NULL,
                                  greater=FALSE, less=FALSE,
                                  within.bin=TRUE,
                                  show.itt=TRUE, show.bep=TRUE)

Survival outcome, 2-arm, continuous variable, greater than some numerical cutoffs

PlotTabForestBiomarker(data=input,
                                  outcome.class="survival",
                                  outcome.var=c("PFS","PFS.event"),
                                  trt="Arm",
                                  var="KRAS.exprs", 
                                  var.class="numeric", var.name="KRAS exprs",
                                  percentile.cutoff=NULL,
                                  numerical.cutoff=c(50,100),
                                  greater=TRUE, less=FALSE,
                                  within.bin=FALSE,
                                  show.itt=TRUE, show.bep=TRUE)

Survival outcome, 2-arm, continuous variable, adjust for covariates

PlotTabForestBiomarker(data=input,
                                  outcome.class="survival",
                                  outcome.var=c("PFS","PFS.event"),
                                  trt="Arm",
                                  var="KRAS.exprs", 
                                  var.class="numeric", var.name="KRAS exprs",
                                  percentile.cutoff=NULL,
                                  numerical.cutoff=c(50,100),
                                  greater=TRUE, less=FALSE,
                                  within.bin=FALSE,
                                  show.itt=TRUE, show.bep=TRUE,
                                  bep = 'BEP', bep.indicator=1, covariate="Age")

Survival outcome, 2-arm, continous variable, stratification

PlotTabForestBiomarker(data=input,
                                  outcome.class="survival",
                                  outcome.var=c("PFS","PFS.event"),
                                  trt="Arm",
                                  var="KRAS.exprs", 
                                  var.class="numeric", var.name="KRAS exprs",
                                  percentile.cutoff=NULL,
                                  numerical.cutoff=c(50,100),
                                  greater=TRUE, less=FALSE,
                                  within.bin=FALSE,
                                  show.itt=TRUE, show.bep=TRUE,
                                  bep = 'BEP', bep.indicator=1, strata="Sex")

Survival outcome, 2-arm, continuous variable, adjust for covariates and stratified by strata

PlotTabForestBiomarker(data=input,
                                  outcome.class="survival",
                                  outcome.var=c("PFS","PFS.event"),
                                  trt="Arm",
                                  var="KRAS.exprs", 
                                  var.class="numeric", var.name="KRAS exprs",
                                  percentile.cutoff=NULL,
                                  numerical.cutoff=c(50,100),
                                  greater=TRUE, less=FALSE,
                                  within.bin=FALSE,
                                  show.itt=TRUE, show.bep=TRUE,
                                  bep = 'BEP', bep.indicator=1,covariate="Age",strata="Sex")

Survival outcome, 1arm

within.bin, show.itt, show.bep will be ignored

PlotTabForestBiomarker(data=subset(input, Arm=="TRT"),
                                  outcome.class="survival",
                                  outcome.var=c("PFS","PFS.event"),
                                  trt=NULL,
                                  var="KRAS.exprs", 
                                  var.class="numeric", var.name="KRAS exprs",
                                  percentile.cutoff=NULL,
                                  numerical.cutoff=c(50,100),
                                  greater=TRUE, less=FALSE,
                                  within.bin=FALSE,
                                  show.itt=TRUE, show.bep=TRUE,covariate="Age",strata="Sex")

Survival outcome, 2arm, flip TRT/CTRL order (calculate ctrl over trt HR)

PlotTabForestBiomarker(data=input,
                                  outcome.class="survival",
                                  outcome.var=c("PFS","PFS.event"),
                                  trt="Arm",
                                  var="KRAS.exprs", 
                                  var.class="numeric", var.name="KRAS exprs",
                                  percentile.cutoff=c(.25,.5,.75), 
                                  numerical.cutoff=NULL,
                                  greater=TRUE, less=FALSE,
                                  within.bin=FALSE,
                                  show.itt=TRUE, show.bep=TRUE,
                                  covariate=NULL, #Sex
                                  strata=NULL, #Age
                                  placebo.code='TRT',
                                  active.code='CTRL')

Survival outcome, 2-arm, continuous variable, greater than some percentage cutoffs, show across-arm and within-arm results in the same plot

PlotTabForestBiomarker(data=input,
                                  outcome.class="survival",
                                  outcome.var=c("PFS","PFS.event"),
                                  trt="Arm",
                                  var="KRAS.exprs", 
                                  var.class="numeric", var.name="KRAS exprs",
                                  percentile.cutoff=c(.25,.5,.75), 
                                  numerical.cutoff=NULL,
                                  greater=TRUE, less=FALSE,
                                  within.bin=FALSE,
                                  show.itt=TRUE, show.bep=TRUE,
                       across.and.within = TRUE)

Response outcome, 2-arm, categorical variable

by default BEP will be defined as patients non-NA biomarker measurement

PlotTabForestBiomarker(data=input,
                                  outcome.class="binary",
                                  outcome.var=c("Response"),
                                  rsp.cat = TRUE,
                                  rsp.response = c("CR","PR"),
                                  rsp.nonresponse = c("SD", "PD","NON CR/PD","NE",NA),
                                  trt="Arm",
                                  var="KRAS.mutant", 
                                  var.class="categorical")

Response outcome, another format

PlotTabForestBiomarker(data=input,                                  
                                  outcome.class="binary",
                                  outcome.var=c("Response"),
                                  rsp.cat = TRUE,
                                  rsp.response = c("CR","PR"),
                                  rsp.nonresponse = c("SD", "PD","NON CR/PD","NE",NA),
                                  trt="Arm",
                                  var="KRAS.mutant", 
                                  var.class="categorical",
                                  tabforest = TRUE)

Continuous outcome, 2-arm, categorical variable

PlotTabForestBiomarker(data=input,
                                  outcome.class="continuous",
                                  outcome.var=c("Lab_ontrt"),
                                  trt="Arm",
                                  var="KRAS.mutant", 
                                  var.class="categorical")
PlotTabForestBiomarker(data=input,
                                  outcome.class="continuous",
                                  outcome.var=c("Lab_ontrt"),
                                  trt="Arm",
                                  var="KRAS.mutant", 
                                  var.class="categorical",tabforest=T)

PlotTabForestMulti(): Forest plots to compare multiple variates' effect in ITT vs BEP, or compare multiple variates' effect in subpopulations

2-arm, compare BEP vs ITT

PlotTabForestMulti(data=input,
                                  outcome.class="survival",
                                  outcome.var=c("PFS","PFS.event"),
                                  trt="Arm",
                                  var=c("Sex","Age"),
                   bep="BEP",bep.indicator=1,
                   compare.bep.itt=TRUE
                   )

2-arm, compare subgroups defined by biomarker

PlotTabForestMulti(data=input,
                                  outcome.class="survival",
                                  outcome.var=c("PFS","PFS.event"),
                                  trt="Arm",
                                  var=c("Sex","Age"),
                   bep="BEP",bep.indicator=1, compare.bep.itt=FALSE,
                   compare.subgroup=TRUE, subgroup="KRAS.mutant"
                   )

2-arm, compare subgroups defined by biomarker, also show ITT

PlotTabForestMulti(data=input,
                                  outcome.class="survival",
                                  outcome.var=c("PFS","PFS.event"),
                                  trt="Arm",
                                  var=c("Sex","Age"),
                   bep="BEP",bep.indicator=1, compare.bep.itt=FALSE,
                   compare.subgroup=TRUE, subgroup="KRAS.mutant", show.itt=TRUE
                   )

2-arm, compare subgroups defined by biomarker, also show BEP

PlotTabForestMulti(data=input,
                                  outcome.class="survival",
                                  outcome.var=c("PFS","PFS.event"),
                                  trt="Arm",
                                  var=c("Sex","Age"),
                   bep="BEP",bep.indicator=1, compare.bep.itt=FALSE,
                   compare.subgroup=TRUE, subgroup="KRAS.mutant", show.itt=TRUE, show.bep=TRUE
                   )

If bep column is not defined, the program will take the non NA entries in subgroups column as BEP

PlotTabForestMulti(data=input,
                                  outcome.class="survival",
                                  outcome.var=c("PFS","PFS.event"),
                                  trt="Arm",
                                  var=c("Sex","Age"), compare.bep.itt=FALSE,
                   compare.subgroup=TRUE, subgroup="KRAS.mutant", show.itt=TRUE, show.bep=TRUE
                   )

1-arm, compare ITT vs BEP

PlotTabForestMulti(data=subset(input,Arm=="TRT"),
                                  outcome.class="survival",
                                  outcome.var=c("PFS","PFS.event"),
                                  trt=NULL,
                                  var=c("Sex","Age"),
                   bep="BEP",bep.indicator=1, compare.bep.itt=TRUE
                   )

2-arm, compare subgroups defined by biomarker, multiple cutoffs for continuous biomarker

PlotTabForestMulti(data=input,
                                  outcome.class="survival",
                                  outcome.var=c("PFS","PFS.event"),
                                  trt="Arm", percentile.cutoff=c(.33,.66),
                                  var=c("Sex","Age"),
                   bep="BEP",bep.indicator=1, compare.bep.itt=FALSE,
                   compare.subgroup=TRUE, subgroup="KRAS.mutant"
                   )

2-arm, compare subgroups defined by biomarker, multiple cutoffs for continuous biomarker, calculate "< cutoff"

PlotTabForestMulti(data=input,
                                  outcome.class="survival",
                                  outcome.var=c("PFS","PFS.event"),
                                  trt="Arm", percentile.cutoff=c(.33,.66),less=TRUE,greater=FALSE,
                                  var=c("Sex","Age"),
                   bep="BEP",bep.indicator=1, compare.bep.itt=FALSE,
                   compare.subgroup=TRUE, subgroup="KRAS.mutant"
                   )

2-arm, compare subgroups defined by biomarker, multiple cutoffs for continuous biomarker, calculate within bin statistics

PlotTabForestMulti(data=input,
                                  outcome.class="survival",
                                  outcome.var=c("PFS","PFS.event"),
                                  trt="Arm", percentile.cutoff=c(.33,.66),within.bin=TRUE,
                                  var=c("Sex","Age"),
                   bep="BEP",bep.indicator=1, compare.bep.itt=FALSE,
                   compare.subgroup=TRUE, subgroup="KRAS.mutant"
                   )

Basic forest plot without comparison

PlotTabForestMulti(data=input,
                                  outcome.class="survival",
                                  outcome.var=c("PFS","PFS.event"),
                                  trt="Arm",
                                  var=c("Sex","Age"),
                   compare.bep.itt=FALSE, compare.subgroup=FALSE,itt.name=""
                   )

Response outcome

PlotTabForestMulti(data=input,
                                                                   outcome.class="binary",
                                  outcome.var=c("Response"),
                                  rsp.cat = TRUE,
                                  rsp.response = c("CR","PR"),
                                  rsp.nonresponse = c("SD", "PD","NON CR/PD","NE",NA),
                                  trt="Arm",
                                  var=c("Sex","Age"),
                   compare.bep.itt=FALSE, compare.subgroup=FALSE,itt.name=""
                   )
PlotTabForestMulti(data=input,
                                                                   outcome.class="binary",
                                  outcome.var=c("Response"),
                                  rsp.cat = TRUE,
                                  rsp.response = c("CR","PR"),
                                  rsp.nonresponse = c("SD", "PD","NON CR/PD","NE",NA),
                                  trt="Arm",
                                  var=c("Sex","Age"),
                   compare.bep.itt=FALSE, compare.subgroup=FALSE,itt.name="", tabforest=T
                   )

Continuous endpoint

PlotTabForestMulti(data=input,
                               outcome.class="continuous",
                                  outcome.var=c("Lab_ontrt"),
                                  trt="Arm",
                                  var=c("Sex","Age"),
                   compare.bep.itt=FALSE, compare.subgroup=FALSE,itt.name=""
                   )
PlotTabForestMulti(data=input,
                 outcome.class="continuous",
                                  outcome.var=c("Lab_ontrt"),
                                  trt="Arm",
                                  var=c("Sex","Age"),
                   compare.bep.itt=FALSE, compare.subgroup=FALSE,itt.name="", tabforest=T
                   )

PlotSTEPP(): STEPP (Subpopulation Treatment Effect Pattern Plot) from the given point estimates and confidence intervals at desired percentiles.

Survival outcome

PlotSTEPP(data = input,
          outcome.var = c("PFS", "PFS.event"),
          outcome.class = "survival",
          trt = "Arm",
          var = "KRAS.exprs",
          placebo.code = "CTRL",
          active.code = "TRT",
          csv.name = NULL,
          pdf.name = NULL
) 

Continuous outcome

PlotSTEPP(data = input,
          outcome.var = "Baseline.SLD",
          outcome.class = "continuous",
          trt = "Arm",
          var = "KRAS.exprs",
          covariate= "Sex",
          placebo.code = "CTRL",
          active.code = "TRT",
          csv.name = NULL,
          pdf.name = NULL
)

Binary outcome variable

PlotSTEPP(data = input,
          outcome.var = "ECOG",
          outcome.class = "binary",
          trt = "Arm",
          var = "KRAS.exprs",
          placebo.code = "CTRL",
          active.code = "TRT",
          csv.name = NULL,
          pdf.name = NULL
)

CoxTab(): fit cox proportional model for multiple covariates (additive model or separate models)

single covariate

CoxTab(data=sample.data, tte="OS", cens="OS.event",bep='BEP', var='Sex' )

multiple covariates, ITT

Additive model will be fitted.

kable(
CoxTab(data=sample.data,tte="OS", cens="OS.event",  var=c('Sex',"Country","Age"), 
       var.class=c("categorical","categorical","numeric"))
)

Simplify: automatically learn var.class from column class:

kable(
CoxTab(data=sample.data,tte="OS", cens="OS.event",  var=c('Sex',"Country","Age"))
)

BEP

kable(
CoxTab(data=sample.data,tte="OS", cens="OS.event",  var=c('Sex',"Country","Age"), 
       var.class=c("categorical","categorical","numeric"), bep="BEP")
)

Reorder Sex: M as reference

kable(
CoxTab(data=sample.data,tte="OS", cens="OS.event",  var=c('Sex',"Country","Age"), 
       var.class=c("ordered.factor","categorical","numeric"), 
       ordered.factor.levels.list=list(Sex=c("M","F")),bep="BEP")
)

Fit separate models for each variable instead of fitting an additive model

kable(
CoxTab(data=sample.data,tte="OS", cens="OS.event",  var=c('Sex',"Country","Age"),
       additive=FALSE)
)

SummaryTwoGroups()

Contunuous outcome

Create summary statistics

SummaryTwoGroups(outcome.var = input$OS, treatment.var = input$Arm, 
            placebo.code = "CTRL", active.code = "TRT", 
            outcome.class = "continuous")

Add a covariate variable

SummaryTwoGroups(outcome.var = input$OS, treatment.var = input$Arm, 
            placebo.code = "CTRL", active.code = "TRT", 
            outcome.class = "continuous", covariate.var = input$Sex)

Add return.fit = TRUE to return a table of summary statistics

SummaryTwoGroups(outcome.var = input$OS, treatment.var = input$Arm, 
            placebo.code = "CTRL", active.code = "TRT", 
            outcome.class = "continuous", covariate.var = input$Sex, 
            return.fit = TRUE)

Binary outcome

Create summary statistics

SummaryTwoGroups(outcome.var = input$OS.event, treatment.var = input$Arm, 
            placebo.code = "CTRL", active.code = "TRT", 
            outcome.class = "binary")

Survival variable

Create summary statistics

SummaryTwoGroups(outcome.var = input[, c("OS", "OS.event")], 
            treatment.var = input$Arm, placebo.code = "CTRL", 
            active.code = "TRT", outcome.class = "survival")

Add a covariate variable

SummaryTwoGroups(outcome.var = input[, c("OS", "OS.event")], 
            treatment.var = input$Arm, placebo.code = "CTRL", 
            active.code = "TRT", outcome.class = "survival", 
            covariate.var = input$Sex)

Add a stratification variable

SummaryTwoGroups(outcome.var = input[, c("OS", "OS.event")], 
            treatment.var = input$Arm, placebo.code = "CTRL", 
            active.code = "TRT", outcome.class = "survival", 
            covariate.var = input$Sex, strat.factor.var = input$Age)

LogRankTab(): log rank test for subgroup analysis

  kable(
    LogRankTab(data=input,tte="PFS",cens="PFS.event",var="Arm")
  )

BoxPlot(): advanced box plot function

Generate example dataset

example <- data.frame( y=c(rnorm(30)+10, rnorm(4)+20, rnorm(15)+15, NA), 
                            time=c(rep("t2", 30), rep("t4",4), rep("t1", 15), "t3"),
                            grp=sample(1:3, 50, TRUE), sex=sample(1:2, 50, TRUE))
head(example)
str(example)

Specify data as named list

BoxPlot(list(a=rnorm(50,,3), b=rnorm(25,1,4), c=rnorm(75,2,1)))

Same plot, now horizontally plotted

BoxPlot(list(a=rnorm(50,,3), b=rnorm(25,1,4), c=rnorm(75,2,1)), horizontal=TRUE,
             Xaxis=list(las=2, hadj=2), Xaxis2=list(las=2, hadj=-.25))

Specify data as numeric matrix

BoxPlot(matrix(rnorm(100), ncol=4, dimnames=list(NULL, LETTERS[1:4])) )

Specify data as numeric (unnamed) vectors

BoxPlot(rnorm(50,,3), rnorm(25,1,2), rnorm(75,2,1))

... horizontally plotted (no axis-label rotation done here)

BoxPlot(rnorm(50,,3), rnorm(25,1,2), rnorm(75,2,1), horizontal=TRUE)

Plot values 'y' according to time 'time' (factor levels are automatically ordered as e.g. function sort does)

BoxPlot(example, y~time, sc.pch=16)

Now as box-percentile plot

BoxPlot(example, y~time, sc.pch=16, box.type="bp")

With custom main title

BoxPlot(example, y~time, sc.pch=16, box.type="bp", Title=list(main="Custom Main Title"))

The same plot with trend line (connects either means or medians) and Y-axis label

BoxPlot(example, y~time, trend="median", ylab="Y-Axis Label")

Use an addition grouping variable to color points in the stripchart

BoxPlot(example, y~time, trend="median", ylab="Y-Axis Label",
           sc.col=c("red", "blue", "green")[example$grp] )

Use yet another grouping factor for plotting symbols in the stripchart

BoxPlot(example, y~time, trend="median", ylab="Y-Axis Label",
           sc.col=c("red", "blue", "green")[example$grp],
             sc.pch=c(5,10)[example$sex] )

legend("bottomright", fill=c("red", "green", "blue", "white", "white"), 
           legend=c("Stage I", "Stage II", "Stage III", "Female", "Male"), 
           pch=c(-1, -1, -1, 5, 10), border=NA)

Generate new dataset with different stucture

example2 <- data.frame(y1=12+rnorm(15), y2=15+rnorm(15), y3=25+rnorm(15))

Boxplot with trend lines (mean) and grid added to the plot

BoxPlot(example2, var=c("y1", "y2", "y3"), Grid=TRUE, trend="mean")

Now as box-percentile plot

BoxPlot(example2, var=c("y1", "y2", "y3"), box.type="bp", Grid=TRUE)

Use yet another way to specify the data

BoxPlot(rnorm(1856, 5), runif(1245, 2,10), exp(rnorm(2311)), sc.col=as.rgb("black", .05), 
            box.type="bp", Xaxis=list(labels=c("~N(5,1)", "~Unif(2,10)", "~exp(N(0,1))")), ylim=c(0,15))     

Specifying data as numeric matrix and using a trend-line connecting the means

    mat <- matrix(c(rep(10,45), rep(15,45), rep(35,45))+rnorm(135), ncol=3)
    BoxPlot(mat, trend="mean", trend.col="red", Ylabel=list(text="Example Measurements"))

Multiple grouping factors can be specified via the formula interface which is exemplified using the mtcars dataset, of interest is miles per gallon (mgp) depending on number of gears and on the number of cylinders

data(mtcars)
BoxPlot(mtcars, mpg~gear:cyl)  

Now 'cyl' is explicitly nested within 'gear' which changes the ordering of combined grouping factors (which is identical to using formula 'mpg~cyl:gear').

BoxPlot(mtcars, mpg~cyl %in% gear)     

More meaningful group-labels are best specified using custom factor-level names (increase width of the plot window)

dat <- mtcars
dat$cyl <- factor(dat$cyl, levels=c(4,6,8), labels=c("4Cyl", "6Cyl", "8Cyl"))
dat$gear <- factor(dat$gear, levels=c(3,4,5), labels=c("3Gear", "4Gear", "5Gear")) 
BoxPlot(dat, mpg~cyl %in% gear)

One can use a table as Xaxis label representing the factor-level combination defining sub-classes

BoxPlot(dat, mpg~cyl:gear, XaxisTab=list(),mar=c(8,3,5,1))

With the original factor levels and as horizontal plot

BoxPlot(mtcars, mpg~cyl:gear, XaxisTab=list(), mar=c(5,8,5,4), 
             horizontal=TRUE, Ylabel=list(text="Y-axis label now appearing on X-axis"))

Using smaller bottom margin will result in smaller table height

BoxPlot(dat, mpg~cyl:gear, XaxisTab=list(font=2, col="darkblue", cex=1.25), mar=c(5,3,5,1))

One can use different font-settings for rownames and cells of the table

BoxPlot(dat, mpg~cyl:gear, XaxisTab=list(Label=list(font=2, col="darkblue", cex=1.25), 
             Text=list(col="red")), mar=c(5,3,5,1))

Use more crossed factors

BoxPlot(dat, mpg~cyl:gear:vs, XaxisTab=list(), mar=c(5,3,5,1))

Alternatively one can use the 'Xaxis' argument, but the ordering of these labels is not checked which is not important for automatically generated group-labels as shown in the previous example

BoxPlot(mtcars, mpg~cyl %in% gear, 
             Xaxis=list(labels=paste(rep(c("4Cyl", "6Cyl", "8Cyl"),3), 
                        c(rep("3Gear",3), rep("4Gear",3), rep("5Gear",3)), sep=".")))

The same plot with some fancy options

BoxPlot(dat, mpg~cyl %in% gear, Title=list(main="Miles per Gallon by Number of Gears", 
             col.main="Green", cex.main=2.5), vline=c(3.5, 6.5), vl.lty=2, vl.col="gray", vl.lwd=2,
           Xaxis=list(labels=NA, at=1:9, tick=TRUE), col=c(rep("blue", 3), rep("red", 3), rep("green", 3)),
           Xaxis2=list(tick=FALSE), Yaxis=list(at=seq(10,34,2)), Grid=list(x=1:9, y=seq(10,34,2)),
           Xlabel=list(text=paste(rep(c("4Cyl", "6Cyl", "8Cyl"),3), c(rep("3Gear",3), rep("4Gear",3), rep("5Gear",3))),
                       at=1:9, las=2, adj=1, line=0.75, col=c(rep("blue", 3), rep("red", 3), rep("green", 3))), 
           mean.col=c(rep("cyan", 3), rep("orange", 3), rep("magenta", 3)), Box=FALSE, trend="mean",mar=c(6,4,5,2) )

Horizontal fancy plot

BoxPlot(mtcars, mpg~cyl %in% gear, Title=list(main="Miles per Gallon by Number of Gears", col.main="#84d52b", cex.main=1.5), 
        vline=c(3.5, 6.5), vl.lty=2, vl.col="gray", vl.lwd=2,
        Xaxis2=list(tick=FALSE, las=2, hadj=-.25), Yaxis=list(at=seq(10,34,2)), Grid=list(x=1:9, y=seq(10,34,2)),
        mean.col=c(rep("cyan", 3), rep("orange", 3), rep("magenta", 3)), Box=FALSE, trend="mean",
        mar=c(3, 7, 4, 4), horizontal=TRUE, sc.pch=c(0, 15)[dat$am+1], sc.col="wheat4",
        XaxisTab=list(Text=list(col=c(rep("cyan", 3), rep("orange", 3), rep("magenta", 3)))) )

 legend(x="topright", pch=c(0, 15), legend=c("automatic", "manual"), box.lty=0, col="wheat4")

Longitudinal analysis

In the context of biomarker analysis, the PlotLong function can be used to plot the longitudinal measurement of a biomarker endpoint for one or more patient subpopulations. Here we'll use the packaged dataset bmkr (biomarker) which has columns for patient ID (pid), treatment (trt), gender (sex), visitation month (vm) and endpoint reading (ep)

Biomarker Endpoint Progression

Mean +/- SEM Timecourse

Here we plot the mean and standard error of the mean over time. We can see clearly that the mean biomarker endpoint increases throughout the study.

PlotLong(longbmkr, aes(x=vm, y=ep),
         xlab = 'Visitation Month',
         ylab = 'Biomarker Endpoint',
         labs.title = 'Mean +/- SEM')

Tukey Hinges and Whiskers

However, we may be more interested in the population distrubtion progression where we'd want to plot the Tukey boxplot hinges and whiskers over time. From this plot, we can see that although there is a slow rise in population mean, the patient response also becomes more distributed.

PlotLong(longbmkr, aes(x=vm, y=ep), fun.data = 'tukey',
         xlab = 'Visitation Month',
         ylab = 'Biomarker Endpoint',
         labs.title = 'Tukey Whiskers and Hinges')

Plotting Subpopulations

PlotLong(longbmkr, aes(x=vm, y=ep, group=trt, color=trt, fill=trt), 
         fun.data = 'tukey', facet.fun = . ~ sex,
         xlab = 'Visitation Month',
         ylab = 'Biomarker Endpoint',
         labs.title = 'Biomarker Timecourse',
         labs.caption = 'Ribbons represent Tukey hinges and whiskers')

Including sample counts

Sample counts as table above plot

library(dplyr)
PlotLong(longbmkr %>% filter(vm <= 24), 
         aes(x=vm, y=ep, group=trt, color=trt, fill=trt), 
         fun.data = 'tukey', facet.fun = . ~ sex,
         show.counts = 'table',
         xlab = 'Visitation Month',
         ylab = 'Biomarker Endpoint',
         labs.title = 'Biomarker Timecourse',
         labs.caption = 'Ribbons represent Tukey hinges and whiskers')

Plotting Deviations as Errorbars

PlotLong(longbmkr %>% filter(vm <= 24), 
         aes(x=vm, y=ep, group=trt, color=trt, fill=trt), 
         fun.data = 'tukey', facet.fun = . ~ sex,
         show.counts = 'table',
         plot.style = 'errorbars',
         xlab = 'Visitation Month',
         ylab = 'Biomarker Endpoint',
         labs.title = 'Biomarker Timecourse',
         labs.caption = 'Ribbons represent Tukey hinges and whiskers')


lengning/gClinBiomarker documentation built on May 9, 2019, 2:55 p.m.