---
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

# 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(r.summary.stan(arst[[myi]], sel.grps=input$subgrpselected));
    cat("\n\n");

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

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

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

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

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

    r.forest.comp(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        <- r.rpt.summary(arst, dat, sub.cov, disp.cut, disp.digit);
```

Based on DIC, `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");
```
