`## Loading required package: beanz`

`## Loading required package: Rcpp`

`## Loading required package: rstan`

`## Loading required package: ggplot2`

`## Loading required package: StanHeaders`

`## rstan (Version 2.15.1, packaged: 2017-04-19 05:03:57 UTC, GitRev: 2e1f913d3ca3)`

```
## For execution on a local, multicore CPU with excess RAM we recommend calling
## rstan_options(auto_write = TRUE)
## options(mc.cores = parallel::detectCores())
```

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 *bzGetSubgrpRaw* for estimating subgroup effect for each subgroup. The return value from *bzGetSubgrpRaw* is a data frame with the format of *Summary treatment effect data*.

The example is as follows:

```
var.cov <- c("lvef", "sodium", "any.vasodilator.use");
var.resp <- "y";
var.trt <- "trt";
var.censor <- "censor";
resptype <- "survival";
subgrp.effect <- bzGetSubgrpRaw(solvd.sub,
var.resp = var.resp,
var.trt = var.trt,
var.cov = var.cov,
var.censor = var.censor,
resptype = resptype);
print(subgrp.effect);
```

```
## Subgroup lvef sodium 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.79235451 0.03939983 237
## 4 4 0 1 1 -0.39334304 0.02969421 250
## 5 5 1 0 0 0.06776454 0.04629163 223
## 6 6 1 0 1 -0.23655764 0.02400353 341
## 7 7 1 1 0 0.15435495 0.10365396 104
## 8 8 1 1 1 0.05947290 0.07761840 123
```

The function *bzCallStan* calls *rstan::sampling* to draw samples for different Bayesian models. The following models are available in the current version of **beanz**:

*nse*: No subgroup effect model*fs*: Full stratification model*sr*: Simple regression model*bs*: Basic shrinkage model*srs*: Simple regression with shrinkage model*ds*: Dixon-Simon model*eds*: Extended Dixon-Simon model.

The following examples show how *No subgroup effect model* (*nse), *Simple regression model* (*sr*) and *Basic shrinkage model* (*bs*) are called:

```
var.estvar <- c("Estimate", "Variance");
rst.nse <- bzCallStan("nse", dat.sub=subgrp.effect,
var.estvar = var.estvar, var.cov = var.cov,
par.pri = c(B=1000),
chains=4, iter=4000,
warmup=2000, seed=1000, cores=1);
```

```
##
## SAMPLING FOR MODEL 'nse' NOW (CHAIN 1).
##
## Gradient evaluation took 2.6e-05 seconds
## 1000 transitions using 10 leapfrog steps per transition would take 0.26 seconds.
## Adjust your expectations accordingly!
##
##
## Iteration: 1 / 4000 [ 0%] (Warmup)
## Iteration: 400 / 4000 [ 10%] (Warmup)
## Iteration: 800 / 4000 [ 20%] (Warmup)
## Iteration: 1200 / 4000 [ 30%] (Warmup)
## Iteration: 1600 / 4000 [ 40%] (Warmup)
## Iteration: 2000 / 4000 [ 50%] (Warmup)
## Iteration: 2001 / 4000 [ 50%] (Sampling)
## Iteration: 2400 / 4000 [ 60%] (Sampling)
## Iteration: 2800 / 4000 [ 70%] (Sampling)
## Iteration: 3200 / 4000 [ 80%] (Sampling)
## Iteration: 3600 / 4000 [ 90%] (Sampling)
## Iteration: 4000 / 4000 [100%] (Sampling)
##
## Elapsed Time: 0.214905 seconds (Warm-up)
## 0.109263 seconds (Sampling)
## 0.324168 seconds (Total)
##
##
## SAMPLING FOR MODEL 'nse' NOW (CHAIN 2).
##
## Gradient evaluation took 1e-05 seconds
## 1000 transitions using 10 leapfrog steps per transition would take 0.1 seconds.
## Adjust your expectations accordingly!
##
##
## Iteration: 1 / 4000 [ 0%] (Warmup)
## Iteration: 400 / 4000 [ 10%] (Warmup)
## Iteration: 800 / 4000 [ 20%] (Warmup)
## Iteration: 1200 / 4000 [ 30%] (Warmup)
## Iteration: 1600 / 4000 [ 40%] (Warmup)
## Iteration: 2000 / 4000 [ 50%] (Warmup)
## Iteration: 2001 / 4000 [ 50%] (Sampling)
## Iteration: 2400 / 4000 [ 60%] (Sampling)
## Iteration: 2800 / 4000 [ 70%] (Sampling)
## Iteration: 3200 / 4000 [ 80%] (Sampling)
## Iteration: 3600 / 4000 [ 90%] (Sampling)
## Iteration: 4000 / 4000 [100%] (Sampling)
##
## Elapsed Time: 0.182268 seconds (Warm-up)
## 0.101289 seconds (Sampling)
## 0.283557 seconds (Total)
##
##
## SAMPLING FOR MODEL 'nse' NOW (CHAIN 3).
##
## Gradient evaluation took 9e-06 seconds
## 1000 transitions using 10 leapfrog steps per transition would take 0.09 seconds.
## Adjust your expectations accordingly!
##
##
## Iteration: 1 / 4000 [ 0%] (Warmup)
## Iteration: 400 / 4000 [ 10%] (Warmup)
## Iteration: 800 / 4000 [ 20%] (Warmup)
## Iteration: 1200 / 4000 [ 30%] (Warmup)
## Iteration: 1600 / 4000 [ 40%] (Warmup)
## Iteration: 2000 / 4000 [ 50%] (Warmup)
## Iteration: 2001 / 4000 [ 50%] (Sampling)
## Iteration: 2400 / 4000 [ 60%] (Sampling)
## Iteration: 2800 / 4000 [ 70%] (Sampling)
## Iteration: 3200 / 4000 [ 80%] (Sampling)
## Iteration: 3600 / 4000 [ 90%] (Sampling)
## Iteration: 4000 / 4000 [100%] (Sampling)
##
## Elapsed Time: 0.185591 seconds (Warm-up)
## 0.108087 seconds (Sampling)
## 0.293678 seconds (Total)
##
##
## SAMPLING FOR MODEL 'nse' NOW (CHAIN 4).
##
## Gradient evaluation took 9e-06 seconds
## 1000 transitions using 10 leapfrog steps per transition would take 0.09 seconds.
## Adjust your expectations accordingly!
##
##
## Iteration: 1 / 4000 [ 0%] (Warmup)
## Iteration: 400 / 4000 [ 10%] (Warmup)
## Iteration: 800 / 4000 [ 20%] (Warmup)
## Iteration: 1200 / 4000 [ 30%] (Warmup)
## Iteration: 1600 / 4000 [ 40%] (Warmup)
## Iteration: 2000 / 4000 [ 50%] (Warmup)
## Iteration: 2001 / 4000 [ 50%] (Sampling)
## Iteration: 2400 / 4000 [ 60%] (Sampling)
## Iteration: 2800 / 4000 [ 70%] (Sampling)
## Iteration: 3200 / 4000 [ 80%] (Sampling)
## Iteration: 3600 / 4000 [ 90%] (Sampling)
## Iteration: 4000 / 4000 [100%] (Sampling)
##
## Elapsed Time: 0.301243 seconds (Warm-up)
## 0.09777 seconds (Sampling)
## 0.399013 seconds (Total)
```

```
rst.sr <- bzCallStan("sr", dat.sub=subgrp.effect,
var.estvar = var.estvar, var.cov = var.cov,
par.pri = c(B=1000, C=1000),
chains=4, iter=4000,
warmup=2000, seed=1000, cores=1);
```

```
##
## SAMPLING FOR MODEL 'sr' NOW (CHAIN 1).
##
## Gradient evaluation took 4e-05 seconds
## 1000 transitions using 10 leapfrog steps per transition would take 0.4 seconds.
## Adjust your expectations accordingly!
##
##
## Iteration: 1 / 4000 [ 0%] (Warmup)
## Iteration: 400 / 4000 [ 10%] (Warmup)
## Iteration: 800 / 4000 [ 20%] (Warmup)
## Iteration: 1200 / 4000 [ 30%] (Warmup)
## Iteration: 1600 / 4000 [ 40%] (Warmup)
## Iteration: 2000 / 4000 [ 50%] (Warmup)
## Iteration: 2001 / 4000 [ 50%] (Sampling)
## Iteration: 2400 / 4000 [ 60%] (Sampling)
## Iteration: 2800 / 4000 [ 70%] (Sampling)
## Iteration: 3200 / 4000 [ 80%] (Sampling)
## Iteration: 3600 / 4000 [ 90%] (Sampling)
## Iteration: 4000 / 4000 [100%] (Sampling)
##
## Elapsed Time: 0.288076 seconds (Warm-up)
## 0.338413 seconds (Sampling)
## 0.626489 seconds (Total)
##
##
## SAMPLING FOR MODEL 'sr' NOW (CHAIN 2).
##
## Gradient evaluation took 1.8e-05 seconds
## 1000 transitions using 10 leapfrog steps per transition would take 0.18 seconds.
## Adjust your expectations accordingly!
##
##
## Iteration: 1 / 4000 [ 0%] (Warmup)
## Iteration: 400 / 4000 [ 10%] (Warmup)
## Iteration: 800 / 4000 [ 20%] (Warmup)
## Iteration: 1200 / 4000 [ 30%] (Warmup)
## Iteration: 1600 / 4000 [ 40%] (Warmup)
## Iteration: 2000 / 4000 [ 50%] (Warmup)
## Iteration: 2001 / 4000 [ 50%] (Sampling)
## Iteration: 2400 / 4000 [ 60%] (Sampling)
## Iteration: 2800 / 4000 [ 70%] (Sampling)
## Iteration: 3200 / 4000 [ 80%] (Sampling)
## Iteration: 3600 / 4000 [ 90%] (Sampling)
## Iteration: 4000 / 4000 [100%] (Sampling)
##
## Elapsed Time: 0.300621 seconds (Warm-up)
## 0.376143 seconds (Sampling)
## 0.676764 seconds (Total)
##
##
## SAMPLING FOR MODEL 'sr' NOW (CHAIN 3).
##
## Gradient evaluation took 1.5e-05 seconds
## 1000 transitions using 10 leapfrog steps per transition would take 0.15 seconds.
## Adjust your expectations accordingly!
##
##
## Iteration: 1 / 4000 [ 0%] (Warmup)
## Iteration: 400 / 4000 [ 10%] (Warmup)
## Iteration: 800 / 4000 [ 20%] (Warmup)
## Iteration: 1200 / 4000 [ 30%] (Warmup)
## Iteration: 1600 / 4000 [ 40%] (Warmup)
## Iteration: 2000 / 4000 [ 50%] (Warmup)
## Iteration: 2001 / 4000 [ 50%] (Sampling)
## Iteration: 2400 / 4000 [ 60%] (Sampling)
## Iteration: 2800 / 4000 [ 70%] (Sampling)
## Iteration: 3200 / 4000 [ 80%] (Sampling)
## Iteration: 3600 / 4000 [ 90%] (Sampling)
## Iteration: 4000 / 4000 [100%] (Sampling)
##
## Elapsed Time: 0.279301 seconds (Warm-up)
## 0.278326 seconds (Sampling)
## 0.557627 seconds (Total)
##
##
## SAMPLING FOR MODEL 'sr' NOW (CHAIN 4).
##
## Gradient evaluation took 1.4e-05 seconds
## 1000 transitions using 10 leapfrog steps per transition would take 0.14 seconds.
## Adjust your expectations accordingly!
##
##
## Iteration: 1 / 4000 [ 0%] (Warmup)
## Iteration: 400 / 4000 [ 10%] (Warmup)
## Iteration: 800 / 4000 [ 20%] (Warmup)
## Iteration: 1200 / 4000 [ 30%] (Warmup)
## Iteration: 1600 / 4000 [ 40%] (Warmup)
## Iteration: 2000 / 4000 [ 50%] (Warmup)
## Iteration: 2001 / 4000 [ 50%] (Sampling)
## Iteration: 2400 / 4000 [ 60%] (Sampling)
## Iteration: 2800 / 4000 [ 70%] (Sampling)
## Iteration: 3200 / 4000 [ 80%] (Sampling)
## Iteration: 3600 / 4000 [ 90%] (Sampling)
## Iteration: 4000 / 4000 [100%] (Sampling)
##
## Elapsed Time: 0.306292 seconds (Warm-up)
## 0.301358 seconds (Sampling)
## 0.60765 seconds (Total)
```

```
## Warning: Some Pareto k diagnostic values are too high. See help('pareto-k-
## diagnostic') for details.
```

```
rst.bs <- bzCallStan("bs", dat.sub=subgrp.effect,
var.estvar = var.estvar, var.cov = var.cov,
par.pri = c(B=1000, D=1),
chains=4, iter=4000, warmup=2000, seed=1000, cores=1);
```

```
##
## SAMPLING FOR MODEL 'bs' NOW (CHAIN 1).
##
## Gradient evaluation took 1.8e-05 seconds
## 1000 transitions using 10 leapfrog steps per transition would take 0.18 seconds.
## Adjust your expectations accordingly!
##
##
## Iteration: 1 / 4000 [ 0%] (Warmup)
## Iteration: 400 / 4000 [ 10%] (Warmup)
## Iteration: 800 / 4000 [ 20%] (Warmup)
## Iteration: 1200 / 4000 [ 30%] (Warmup)
## Iteration: 1600 / 4000 [ 40%] (Warmup)
## Iteration: 2000 / 4000 [ 50%] (Warmup)
## Iteration: 2001 / 4000 [ 50%] (Sampling)
## Iteration: 2400 / 4000 [ 60%] (Sampling)
## Iteration: 2800 / 4000 [ 70%] (Sampling)
## Iteration: 3200 / 4000 [ 80%] (Sampling)
## Iteration: 3600 / 4000 [ 90%] (Sampling)
## Iteration: 4000 / 4000 [100%] (Sampling)
##
## Elapsed Time: 0.381202 seconds (Warm-up)
## 0.277337 seconds (Sampling)
## 0.658539 seconds (Total)
##
##
## SAMPLING FOR MODEL 'bs' NOW (CHAIN 2).
##
## Gradient evaluation took 1.3e-05 seconds
## 1000 transitions using 10 leapfrog steps per transition would take 0.13 seconds.
## Adjust your expectations accordingly!
##
##
## Iteration: 1 / 4000 [ 0%] (Warmup)
## Iteration: 400 / 4000 [ 10%] (Warmup)
## Iteration: 800 / 4000 [ 20%] (Warmup)
## Iteration: 1200 / 4000 [ 30%] (Warmup)
## Iteration: 1600 / 4000 [ 40%] (Warmup)
## Iteration: 2000 / 4000 [ 50%] (Warmup)
## Iteration: 2001 / 4000 [ 50%] (Sampling)
## Iteration: 2400 / 4000 [ 60%] (Sampling)
## Iteration: 2800 / 4000 [ 70%] (Sampling)
## Iteration: 3200 / 4000 [ 80%] (Sampling)
## Iteration: 3600 / 4000 [ 90%] (Sampling)
## Iteration: 4000 / 4000 [100%] (Sampling)
##
## Elapsed Time: 0.361912 seconds (Warm-up)
## 0.497498 seconds (Sampling)
## 0.85941 seconds (Total)
##
##
## SAMPLING FOR MODEL 'bs' NOW (CHAIN 3).
##
## Gradient evaluation took 1.1e-05 seconds
## 1000 transitions using 10 leapfrog steps per transition would take 0.11 seconds.
## Adjust your expectations accordingly!
##
##
## Iteration: 1 / 4000 [ 0%] (Warmup)
## Iteration: 400 / 4000 [ 10%] (Warmup)
## Iteration: 800 / 4000 [ 20%] (Warmup)
## Iteration: 1200 / 4000 [ 30%] (Warmup)
## Iteration: 1600 / 4000 [ 40%] (Warmup)
## Iteration: 2000 / 4000 [ 50%] (Warmup)
## Iteration: 2001 / 4000 [ 50%] (Sampling)
## Iteration: 2400 / 4000 [ 60%] (Sampling)
## Iteration: 2800 / 4000 [ 70%] (Sampling)
## Iteration: 3200 / 4000 [ 80%] (Sampling)
## Iteration: 3600 / 4000 [ 90%] (Sampling)
## Iteration: 4000 / 4000 [100%] (Sampling)
##
## Elapsed Time: 0.421371 seconds (Warm-up)
## 0.251017 seconds (Sampling)
## 0.672388 seconds (Total)
##
##
## SAMPLING FOR MODEL 'bs' NOW (CHAIN 4).
##
## Gradient evaluation took 1.1e-05 seconds
## 1000 transitions using 10 leapfrog steps per transition would take 0.11 seconds.
## Adjust your expectations accordingly!
##
##
## Iteration: 1 / 4000 [ 0%] (Warmup)
## Iteration: 400 / 4000 [ 10%] (Warmup)
## Iteration: 800 / 4000 [ 20%] (Warmup)
## Iteration: 1200 / 4000 [ 30%] (Warmup)
## Iteration: 1600 / 4000 [ 40%] (Warmup)
## Iteration: 2000 / 4000 [ 50%] (Warmup)
## Iteration: 2001 / 4000 [ 50%] (Sampling)
## Iteration: 2400 / 4000 [ 60%] (Sampling)
## Iteration: 2800 / 4000 [ 70%] (Sampling)
## Iteration: 3200 / 4000 [ 80%] (Sampling)
## Iteration: 3600 / 4000 [ 90%] (Sampling)
## Iteration: 4000 / 4000 [100%] (Sampling)
##
## Elapsed Time: 0.398197 seconds (Warm-up)
## 0.255514 seconds (Sampling)
## 0.653711 seconds (Total)
```

```
## Warning: There were 15 divergent transitions after warmup. Increasing adapt_delta above 0.8 may help. See
## http://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
```

`## Warning: Examine the pairs() plot to diagnose sampling problems`

```
## Warning: Some Pareto k diagnostic values are too high. See help('pareto-k-
## diagnostic') for details.
```

Posterior subgroup treatment effect can be summarized and presented by functions *bzSummary*, *bzPlot* and *bzForest*. 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 <- bzSummary(rst.sr, ref.stan.rst=rst.nse, ref.sel.grps=1);
print(tbl.sub);
```

```
## Subgroup Mean SD 2.5%
## Subgroup 1 "Subgroup 1" "-0.401" "0.095" "-0.586"
## Subgroup 2 "Subgroup 2" "-0.381" "0.087" "-0.555"
## Subgroup 3 "Subgroup 3" "-0.488" "0.134" "-0.748"
## Subgroup 4 "Subgroup 4" "-0.468" "0.128" "-0.717"
## Subgroup 5 "Subgroup 5" "-0.061" "0.136" "-0.327"
## Subgroup 6 "Subgroup 6" "-0.041" "0.122" "-0.282"
## Subgroup 7 "Subgroup 7" "-0.148" "0.161" "-0.465"
## Subgroup 8 "Subgroup 8" "-0.128" "0.149" "-0.419"
## No subgroup effect(1) "No subgroup effect(1)" "-0.322" "0.057" "-0.433"
## 25% Median 75% 97.5% Prob<0
## Subgroup 1 "-0.465" "-0.399" "-0.338" "-0.212" "1"
## Subgroup 2 "-0.44" "-0.38" "-0.321" "-0.208" "1"
## Subgroup 3 "-0.579" "-0.487" "-0.398" "-0.223" "1"
## Subgroup 4 "-0.552" "-0.47" "-0.382" "-0.219" "1"
## Subgroup 5 "-0.154" "-0.061" "0.028" "0.206" "0.678"
## Subgroup 6 "-0.123" "-0.04" "0.041" "0.195" "0.63"
## Subgroup 7 "-0.256" "-0.147" "-0.04" "0.17" "0.822"
## Subgroup 8 "-0.228" "-0.128" "-0.03" "0.168" "0.808"
## No subgroup effect(1) "-0.36" "-0.322" "-0.284" "-0.21" "1"
```

`bzPlot(rst.sr, sel.grps = sel.grps, ref.stan.rst=rst.nse, ref.sel.grps=1);`

`bzForest(rst.sr, sel.grps = sel.grps, ref.stan.rst=rst.nse, ref.sel.grps=1);`

```
tbl.sub <- bzSummary(rst.bs, ref.stan.rst=rst.nse, ref.sel.grps=1);
print(tbl.sub);
```

```
## Subgroup Mean SD 2.5%
## Subgroup 1 "Subgroup 1" "-0.352" "0.095" "-0.549"
## Subgroup 2 "Subgroup 2" "-0.333" "0.087" "-0.506"
## Subgroup 3 "Subgroup 3" "-0.519" "0.186" "-0.925"
## Subgroup 4 "Subgroup 4" "-0.346" "0.131" "-0.623"
## Subgroup 5 "Subgroup 5" "-0.145" "0.182" "-0.432"
## Subgroup 6 "Subgroup 6" "-0.268" "0.124" "-0.497"
## Subgroup 7 "Subgroup 7" "-0.167" "0.22" "-0.507"
## Subgroup 8 "Subgroup 8" "-0.18" "0.194" "-0.488"
## No subgroup effect(1) "No subgroup effect(1)" "-0.322" "0.057" "-0.433"
## 25% Median 75% 97.5% Prob<0
## Subgroup 1 "-0.413" "-0.349" "-0.288" "-0.17" "1"
## Subgroup 2 "-0.392" "-0.333" "-0.276" "-0.163" "1"
## Subgroup 3 "-0.645" "-0.494" "-0.377" "-0.23" "1"
## Subgroup 4 "-0.425" "-0.343" "-0.264" "-0.088" "0.994"
## Subgroup 5 "-0.281" "-0.168" "-0.028" "0.253" "0.789"
## Subgroup 6 "-0.352" "-0.276" "-0.191" "-0.003" "0.976"
## Subgroup 7 "-0.32" "-0.208" "-0.042" "0.357" "0.797"
## Subgroup 8 "-0.318" "-0.213" "-0.066" "0.269" "0.825"
## No subgroup effect(1) "-0.36" "-0.322" "-0.284" "-0.21" "1"
```

`bzPlot(rst.bs, sel.grps = sel.grps, ref.stan.rst=rst.nse, ref.sel.grps=1);`

`bzForest(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 *bzSummaryComp*, *bzPlotComp* and *bzForestComp*.

```
tbl.sub <- bzSummaryComp(rst.sr, sel.grps=sel.grps);
print(tbl.sub);
```

```
## Comparison Mean SD 2.5% 25% Median
## Subgroup 4-1 "Subgroup 4-1" "-0.069" "0.159" "-0.378" "-0.176" "-0.068"
## Subgroup 5-1 "Subgroup 5-1" "0.342" "0.168" "0.015" "0.228" "0.341"
## Subgroup 5-4 "Subgroup 5-4" "0.409" "0.185" "0.042" "0.284" "0.411"
## 75% 97.5% Prob<0
## Subgroup 4-1 "0.039" "0.247" "0.668"
## Subgroup 5-1 "0.454" "0.672" "0.021"
## Subgroup 5-4 "0.535" "0.768" "0.014"
```

`bzPlot(rst.sr, sel.grps = sel.grps);`

`bzForest(rst.sr, sel.grps = sel.grps);`

```
tbl.sub <- bzSummaryComp(rst.bs, sel.grps=sel.grps);
print(tbl.sub);
```

```
## Comparison Mean SD 2.5% 25% Median
## Subgroup 4-1 "Subgroup 4-1" "0.004" "0.162" "-0.326" "-0.099" "0.005"
## Subgroup 5-1 "Subgroup 5-1" "0.206" "0.206" "-0.147" "0.056" "0.19"
## Subgroup 5-4 "Subgroup 5-4" "0.201" "0.227" "-0.198" "0.044" "0.181"
## 75% 97.5% Prob<0
## Subgroup 4-1 "0.11" "0.327" "0.487"
## Subgroup 5-1 "0.339" "0.646" "0.158"
## Subgroup 5-4 "0.348" "0.679" "0.189"
```

`bzPlotComp(rst.bs, sel.grps = sel.grps);`

`bzForestComp(rst.bs, sel.grps = sel.grps);`

**beanz** provides function *bzRptTbl* 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 <- bzRptTbl(lst.rst, dat.sub = subgrp.effect, var.cov = var.cov);
print(tbl.summary);
```

```
## Model Subgroup lvef sodium any.vasodilator.use
## Subgroup 1 No subgroup effect 1 0 0 0
## Subgroup 2 No subgroup effect 2 0 0 1
## Subgroup 3 No subgroup effect 3 0 1 0
## Subgroup 4 No subgroup effect 4 0 1 1
## Subgroup 5 No subgroup effect 5 1 0 0
## Subgroup 6 No subgroup effect 6 1 0 1
## Subgroup 7 No subgroup effect 7 1 1 0
## Subgroup 8 No subgroup effect 8 1 1 1
## Mean SD Prob < 0
## Subgroup 1 -0.322 0.057 1
## Subgroup 2 -0.322 0.057 1
## Subgroup 3 -0.322 0.057 1
## Subgroup 4 -0.322 0.057 1
## Subgroup 5 -0.322 0.057 1
## Subgroup 6 -0.322 0.057 1
## Subgroup 7 -0.322 0.057 1
## Subgroup 8 -0.322 0.057 1
```

Function *bzPredSubgrp* generates the predictive distribution of the subgrooup treatment effects.

```
pred.dist <- bzPredSubgrp(rst.sr,
dat.sub=subgrp.effect,
var.estvar = var.estvar);
head(pred.dist);
```

```
## [,1] [,2] [,3] [,4] [,5] [,6]
## [1,] -0.4106544 -0.2729639 -0.2833678 -0.7086735 0.13863143 -0.2401073
## [2,] -0.4630472 -0.3204252 -0.9663035 -0.2008835 -0.24174135 0.1217357
## [3,] -0.4849539 -0.4366923 -0.2509129 -0.2227768 -0.10303756 0.1424272
## [4,] -0.2268182 -0.2608901 -0.6716770 -0.8505750 0.01726514 0.1487775
## [5,] -0.2992915 -0.3812735 -0.3459893 -0.4149678 0.12845771 -0.1192461
## [6,] -0.3805680 -0.3576529 -0.2266444 -0.3892325 -0.05297515 0.0350540
## [,7] [,8]
## [1,] -0.6384271 -0.29498853
## [2,] -0.4920581 -0.30013648
## [3,] 0.5270383 -0.04475668
## [4,] -0.5698921 0.03575675
## [5,] -0.7750399 0.07979306
## [6,] -0.4110462 -0.06400478
```

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

`bzShiny();`

Package **beanz** provides function *bzGailSimon* that implements the Gail-Simon test for qualitative interactions:

```
gs.pval <- bzGailSimon(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.