## Loading required package: beanz
## Loading required package: Rcpp
In patient-centered outcomes research, it is vital to assess the heterogeneity of treatment effects (HTE) when making health care decisions for an individual patient or a group of patients. Nevertheless, it remains challenging to evaluate HTE based on information collected from clinical studies that are often designed and conducted to evaluate the efficacy of a treatment for the overall population. The Bayesian framework offers a principled and flexible approach to estimate and compare treatment effects across subgroups of patients defined by their characteristics.
R package beanz provides functions to facilitate the conduct of Bayesian analysis of HTE and a web-based graphical user interface for users to conduct such Bayesian analysis in an interactive and user-friendly manner.
There are two types of data structures that beanz recognizes:
Summary treatment effect data: Each row should represent a subgroup with covariates that define the subgroup, estimated treatment effect in the subgroup and variance for the estimation.
Patient level raw data: Each row should represent a patient with covariates that define the subgroup in which the patient belongs to, treatment indicator and outcome. The outcome can be binary, continuous, or time to event.
The beanz package provides dataset solvd.sub from the SOLVD trial as an example Patient level raw data dataset.
If Patient level raw data is provided, the package provides function r.get.subgrp.raw for estimating subgroup effect for each subgroup. The return value from r.get.subgrp.raw is a data frame with the format of Summary treatment effect data.
The example is as follows:
var.cov <- c("sodium", "lvef", "any.vasodilator.use");
var.resp <- "y";
var.trt <- "trt";
var.censor <- "censor";
resptype <- "survival";
subgrp.effect <- r.get.subgrp.raw(solvd.sub,
var.resp = var.resp,
var.trt = var.trt,
var.cov = var.cov,
var.censor = var.censor,
resptype = resptype);
print(subgrp.effect);
## Subgroup sodium lvef any.vasodilator.use Estimate Variance N
## 1 1 0 0 0 -0.37783038 0.01212786 562
## 2 2 0 0 1 -0.34655336 0.01004499 695
## 3 3 0 1 0 0.06776454 0.04629163 223
## 4 4 0 1 1 -0.23655764 0.02400353 341
## 5 5 1 0 0 -0.79235451 0.03939983 237
## 6 6 1 0 1 -0.39334304 0.02969421 250
## 7 7 1 1 0 0.15435495 0.10365396 104
## 8 8 1 1 1 0.05947290 0.07761840 123
The function call.stan calls rstan::sampling to draw samples for different Bayesian models. The following models are available in the current version of beanz:
The following examples show how No subgroup effect model (nse), Simple regression model* (sr) and Basic shrinkage model (bs) are called:
var.cov <- c("sodium", "lvef", "any.vasodilator.use");
var.estvar <- c("Estimate", "Variance");
rst.nse <- call.stan("nse", dat.sub=subgrp.effect,
var.estvar = var.estvar, var.cov = var.cov,
lst.par.pri = list(vtau=1000, vrange=c(0,0)),
chains=1, iter=4000,
warmup=2000, thin=2, seed=1000);
##
## SAMPLING FOR MODEL 'nse' NOW (CHAIN 1).
##
## Chain 1, Iteration: 1 / 4000 [ 0%] (Warmup)
## Chain 1, Iteration: 400 / 4000 [ 10%] (Warmup)
## Chain 1, Iteration: 800 / 4000 [ 20%] (Warmup)
## Chain 1, Iteration: 1200 / 4000 [ 30%] (Warmup)
## Chain 1, Iteration: 1600 / 4000 [ 40%] (Warmup)
## Chain 1, Iteration: 2000 / 4000 [ 50%] (Warmup)
## Chain 1, Iteration: 2001 / 4000 [ 50%] (Sampling)
## Chain 1, Iteration: 2400 / 4000 [ 60%] (Sampling)
## Chain 1, Iteration: 2800 / 4000 [ 70%] (Sampling)
## Chain 1, Iteration: 3200 / 4000 [ 80%] (Sampling)
## Chain 1, Iteration: 3600 / 4000 [ 90%] (Sampling)
## Chain 1, Iteration: 4000 / 4000 [100%] (Sampling)
## Elapsed Time: 0.104963 seconds (Warm-up)
## 0.059284 seconds (Sampling)
## 0.164247 seconds (Total)
rst.sr <- call.stan("sr", dat.sub=subgrp.effect,
var.estvar = var.estvar, var.cov = var.cov,
lst.par.pri = list(vtau=1000, vgamma=1000, vrange=c(0,0)),
chains=1, iter=4000,
warmup=2000, thin=2, seed=1000);
##
## SAMPLING FOR MODEL 'sr' NOW (CHAIN 1).
##
## Chain 1, Iteration: 1 / 4000 [ 0%] (Warmup)
## Chain 1, Iteration: 400 / 4000 [ 10%] (Warmup)
## Chain 1, Iteration: 800 / 4000 [ 20%] (Warmup)
## Chain 1, Iteration: 1200 / 4000 [ 30%] (Warmup)
## Chain 1, Iteration: 1600 / 4000 [ 40%] (Warmup)
## Chain 1, Iteration: 2000 / 4000 [ 50%] (Warmup)
## Chain 1, Iteration: 2001 / 4000 [ 50%] (Sampling)
## Chain 1, Iteration: 2400 / 4000 [ 60%] (Sampling)
## Chain 1, Iteration: 2800 / 4000 [ 70%] (Sampling)
## Chain 1, Iteration: 3200 / 4000 [ 80%] (Sampling)
## Chain 1, Iteration: 3600 / 4000 [ 90%] (Sampling)
## Chain 1, Iteration: 4000 / 4000 [100%] (Sampling)
## Elapsed Time: 0.205756 seconds (Warm-up)
## 0.118499 seconds (Sampling)
## 0.324255 seconds (Total)
rst.bs <- call.stan("bs", dat.sub=subgrp.effect,
var.estvar = var.estvar, var.cov = var.cov,
lst.par.pri = list(vtau=1000, vw=100, vrange=c(-0.1,0.1)),
chains=1, iter=4000, warmup=2000, thin=2, seed=1000);
##
## SAMPLING FOR MODEL 'bs' NOW (CHAIN 1).
##
## Chain 1, Iteration: 1 / 4000 [ 0%] (Warmup)
## Chain 1, Iteration: 400 / 4000 [ 10%] (Warmup)
## Chain 1, Iteration: 800 / 4000 [ 20%] (Warmup)
## Chain 1, Iteration: 1200 / 4000 [ 30%] (Warmup)
## Chain 1, Iteration: 1600 / 4000 [ 40%] (Warmup)
## Chain 1, Iteration: 2000 / 4000 [ 50%] (Warmup)
## Chain 1, Iteration: 2001 / 4000 [ 50%] (Sampling)
## Chain 1, Iteration: 2400 / 4000 [ 60%] (Sampling)
## Chain 1, Iteration: 2800 / 4000 [ 70%] (Sampling)
## Chain 1, Iteration: 3200 / 4000 [ 80%] (Sampling)
## Chain 1, Iteration: 3600 / 4000 [ 90%] (Sampling)
## Chain 1, Iteration: 4000 / 4000 [100%] (Sampling)
## Elapsed Time: 0.186707 seconds (Warm-up)
## 0.169244 seconds (Sampling)
## 0.355951 seconds (Total)
Posterior subgroup treatment effect can be summarized and presented by functions r.summary.stan, r.plot.stan and r.forest.stan. These functions allows to include a subgroup from another model (i.e. No subgroup effect model) as a reference in the results.
sel.grps <- c(1,4,5);
tbl.sub <- r.summary.stan(rst.sr, ref.stan.rst=rst.nse, ref.sel.grps=1);
print(tbl.sub);
## Subgroup Mean SD 2.5%
## Subgroup 1 "Subgroup 1" "-0.406" "0.089" "-0.571"
## Subgroup 2 "Subgroup 2" "-0.382" "0.085" "-0.54"
## Subgroup 3 "Subgroup 3" "-0.06" "0.131" "-0.316"
## Subgroup 4 "Subgroup 4" "-0.036" "0.119" "-0.259"
## Subgroup 5 "Subgroup 5" "-0.488" "0.124" "-0.745"
## Subgroup 6 "Subgroup 6" "-0.465" "0.126" "-0.706"
## Subgroup 7 "Subgroup 7" "-0.142" "0.16" "-0.443"
## Subgroup 8 "Subgroup 8" "-0.119" "0.154" "-0.411"
## No subgroup effect(1) "No subgroup effect(1)" "-0.318" "0.058" "-0.437"
## 25% Median 75% 97.5% Prob < 0
## Subgroup 1 "-0.466" "-0.408" "-0.35" "-0.229" "1"
## Subgroup 2 "-0.44" "-0.384" "-0.327" "-0.223" "1"
## Subgroup 3 "-0.148" "-0.056" "0.024" "0.199" "0.688"
## Subgroup 4 "-0.116" "-0.035" "0.045" "0.195" "0.614"
## Subgroup 5 "-0.571" "-0.489" "-0.406" "-0.252" "1"
## Subgroup 6 "-0.555" "-0.467" "-0.378" "-0.225" "1"
## Subgroup 7 "-0.256" "-0.142" "-0.037" "0.177" "0.816"
## Subgroup 8 "-0.226" "-0.116" "-0.015" "0.197" "0.785"
## No subgroup effect(1) "-0.355" "-0.319" "-0.281" "-0.2" "1"
r.plot.stan(rst.sr, sel.grps = sel.grps, ref.stan.rst=rst.nse, ref.sel.grps=1);
r.forest.stan(rst.sr, sel.grps = sel.grps, ref.stan.rst=rst.nse, ref.sel.grps=1);
tbl.sub <- r.summary.stan(rst.bs, ref.stan.rst=rst.nse, ref.sel.grps=1);
print(tbl.sub);
## Subgroup Mean SD 2.5%
## Subgroup 1 "Subgroup 1" "-0.358" "0.106" "-0.563"
## Subgroup 2 "Subgroup 2" "-0.341" "0.093" "-0.52"
## Subgroup 3 "Subgroup 3" "-0.06" "0.193" "-0.415"
## Subgroup 4 "Subgroup 4" "-0.246" "0.141" "-0.523"
## Subgroup 5 "Subgroup 5" "-0.627" "0.189" "-0.999"
## Subgroup 6 "Subgroup 6" "-0.356" "0.154" "-0.665"
## Subgroup 7 "Subgroup 7" "-0.079" "0.266" "-0.535"
## Subgroup 8 "Subgroup 8" "-0.083" "0.231" "-0.483"
## No subgroup effect(1) "No subgroup effect(1)" "-0.318" "0.058" "-0.437"
## 25% Median 75% 97.5% Prob < 0
## Subgroup 1 "-0.426" "-0.359" "-0.282" "-0.153" "1"
## Subgroup 2 "-0.406" "-0.343" "-0.275" "-0.163" "1"
## Subgroup 3 "-0.2" "-0.069" "0.073" "0.312" "0.639"
## Subgroup 4 "-0.346" "-0.242" "-0.15" "0.017" "0.961"
## Subgroup 5 "-0.766" "-0.617" "-0.485" "-0.289" "1"
## Subgroup 6 "-0.453" "-0.355" "-0.263" "-0.051" "0.987"
## Subgroup 7 "-0.27" "-0.101" "0.084" "0.504" "0.654"
## Subgroup 8 "-0.248" "-0.096" "0.071" "0.393" "0.671"
## No subgroup effect(1) "-0.355" "-0.319" "-0.281" "-0.2" "1"
r.plot.stan(rst.bs, sel.grps = sel.grps, ref.stan.rst=rst.nse, ref.sel.grps=1);
r.forest.stan(rst.bs, sel.grps = sel.grps, ref.stan.rst=rst.nse, ref.sel.grps=1);
Posterior subgroup treatment effect can be compared between subgroups by functions r.summary.comp, r.plot.comp and r.forest.comp.
tbl.sub <- r.summary.comp(rst.sr, sel.grps=sel.grps);
print(tbl.sub);
## Comparison Mean SD 2.5% 25% Median
## Subgroup 4-1 "Subgroup 4-1" "0.368" "0.153" "0.066" "0.258" "0.371"
## Subgroup 5-1 "Subgroup 5-1" "-0.078" "0.157" "-0.401" "-0.179" "-0.078"
## Subgroup 5-4 "Subgroup 5-4" "-0.452" "0.166" "-0.772" "-0.559" "-0.452"
## 75% 97.5% Prob <0
## Subgroup 4-1 "0.471" "0.658" "0.008"
## Subgroup 5-1 "0.029" "0.205" "0.685"
## Subgroup 5-4 "-0.342" "-0.133" "0.997"
r.plot.stan(rst.sr, sel.grps = sel.grps);
r.forest.stan(rst.sr, sel.grps = sel.grps);
tbl.sub <- r.summary.comp(rst.bs, sel.grps=sel.grps);
print(tbl.sub);
## Comparison Mean SD 2.5% 25% Median
## Subgroup 4-1 "Subgroup 4-1" "0.118" "0.177" "-0.243" "-0.003" "0.112"
## Subgroup 5-1 "Subgroup 5-1" "-0.272" "0.22" "-0.723" "-0.424" "-0.274"
## Subgroup 5-4 "Subgroup 5-4" "-0.385" "0.241" "-0.885" "-0.542" "-0.382"
## 75% 97.5% Prob <0
## Subgroup 4-1 "0.244" "0.462" "0.26"
## Subgroup 5-1 "-0.122" "0.136" "0.884"
## Subgroup 5-4 "-0.221" "0.069" "0.943"
r.plot.comp(rst.bs, sel.grps = sel.grps);
r.forest.comp(rst.bs, sel.grps = sel.grps);
beanz provides function r.rpt.tbl to generate the summary posterior subgroup treatment effect table from the model selected by DIC (i.e. the model with the smallest DIC):
lst.rst <- list(nse=rst.nse, sr=rst.sr, bs=rst.bs);
tbl.summary <- r.rpt.tbl(lst.rst, dat.sub = subgrp.effect, var.cov = var.cov);
print(tbl.summary);
## Subgroup sodium lvef any.vasodilator.use Mean SD Prob < 0
## Subgroup 1 1 0 0 0 -0.358 0.106 1.000
## Subgroup 2 2 0 0 1 -0.341 0.093 1.000
## Subgroup 3 3 0 1 0 -0.060 0.193 0.639
## Subgroup 4 4 0 1 1 -0.246 0.141 0.961
## Subgroup 5 5 1 0 0 -0.627 0.189 1.000
## Subgroup 6 6 1 0 1 -0.356 0.154 0.987
## Subgroup 7 7 1 1 0 -0.079 0.266 0.654
## Subgroup 8 8 1 1 1 -0.083 0.231 0.671
With package shiny installed, beaz provides a web-based graphical user interface (GUI) for conducting the HTE analysis in an user-friendly interactive manner. The GUI can be started by
run.beanz();
Package beanz provides function r.gailsimon that implements the Gail-Simon test for qualitative interactions:
gs.pval <- r.gailsimon(subgrp.effect$Estimate,
sqrt(subgrp.effect$Variance));
print(gs.pval);
## [1] 0.9191656
The result show that there is no significant qualitative interactions according to the Gail-Simon test.