---
title: "BEANZ Analysis Report"
author: "[BEANZ](http://sow.familyds.com/shiny/beans/)"
date: "`r Sys.Date()`"
toc: true
number_sections: true
output: pdf_document
---

\newpage

# Warnings

Subgroup analysis are only exploratory unless such analyses
were pre-specified in a study protocol at the design stage.
The users should be cautious with the choices of the priors
in Bayesian subgroup analysis. The users are encouraged to
conduct sensitivity analysis by trying different parameter
values in the prior distributions and examining the robustness
of the results.

# Data Summary

```{r, echo=FALSE, eval=TRUE}
dat.all <- get.data()
summary(dat.all)
```

# Subgroup Definition

```{r,echo=FALSE, eval=TRUE, results='asis'}
subgrp <- get.subgrp()
pander::pandoc.table(subgrp)
```


# Analysis Results

```{r,echo=FALSE, eval=TRUE, results='asis'}
arst <- ana.rst()
for (myi in 1:length(arst)) {
    cat("## Model:", names(arst)[myi], "\n\n");
    cat("### Subgroup Effects\n\n");

    pander::pandoc.table(bzSummary(arst[[myi]], sel.grps=input$subgrpselected));
    cat("\n\n");

    bzPlot(arst[[myi]], sel.grps=input$subgrpselected);
    cat("\n\n");

    bzForest(arst[[myi]], sel.grps=input$subgrpselected);
    cat("\n\n");

    cat("### Subgroup Effects Comparison\n\n");

    pander::pandoc.table(bzSummaryComp(arst[[myi]], sel.grps=input$subgrpselected));
    cat("\n\n");

    bzPlotComp(arst[[myi]], sel.grps=input$subgrpselected);
    cat("\n\n");

    bzForestComp(arst[[myi]], sel.grps=input$subgrpselected);
    cat("\n\n");
}
```


# Summary

```{r,echo=FALSE, eval=TRUE, results='asis'}
    dat        <- get.subgrp();
    disp.cut   <- input$displaycut;
    disp.digit <- input$displaydigit;
    sub.cov    <- get.sub.cov();

    dic        <- get.all.dic();
    min.mdl    <- which.min(dic);
    mdls       <- get.ana.models();
    rst        <- bzRptTbl(arst, dat, sub.cov, disp.cut, disp.digit);
```

Based on leave-one-out cross-validation information
criterion (LOOIC), results from the `r mdls[min.mdl]` 
model are reported here. However, this does not imply that the selected
model is significantly better than the other models. Please consider the
totality of the information for drawing the conclusions. 

Based on LOOIC, `r mdls[min.mdl]` model is selected for the analysis dataset.
The summary result table is as follows:

```{r,echo=FALSE, eval=TRUE, results='asis'}
    pander::pandoc.table(rst);
    cat("\n\n");
```
