---
title: "visit Simulation Report"
author: "visit package"
date: "`r Sys.Date()`"
toc: true
output: 
  pdf_document:
    number_sections: true
---

```{r, echo=FALSE, eval=TRUE}
library(xtable);
data.all <- get.data();
```
\clearpage
# Simulation Parameters

Variables         | Values
------------------|--------------------------
Number of doses   | `r data.all$ndose`
decision cuts     | `r data.all$dec.cut[1:3]`
etas              | `r data.all$etas[1:2]`
probability model | `r data.all$probmdl`
cohort size       | `r data.all$size.cohort`
level size        | `r data.all$size.level`
n rep             | `r data.all$n.rep`
n core            | `r data.all$n.cores`



\clearpage
# Trueps Plots  
## Trueps Plots 1
Probability of DLT risk and immune response:  
```{r TRUEPS1, echo=FALSE, fig.cap="Scenario Plots", fig.height=6, fig.width=8, warning=FALSE}
if (!is.null(data.all$sm)) {
  plot(data.all$sm, draw.curves = 1:2, bg = 'transparent')
} else {
  "No scenario plot was generated from this session."
};
```

\clearpage
## Trueps Plots 2
Probability of each scenario:  
```{r TRUEPS2, echo=FALSE, fig.cap="Scenario Plots", fig.height=6, fig.width=8, warning=FALSE, fig.pos="down"}
if (!is.null(data.all$sm)) {
  plot(data.all$sm, draw.curves = 3:6, bg = 'transparent')
} else {
  "No scenario plot was generated from this session."
};
```


\clearpage


# Simulation Results
  
<center>
```{r, echo=FALSE, eval=TRUE, results='asis'}
if (!is.null(data.all$rst)) {
  for (i in 1:length(summary(data.all$rst))) {
    print(xtable(summary(data.all$rst)[[i]]), comment = FALSE)
  }
} else {
  "No simulation result was generated from this session."
}
```
</center>
  
\clearpage
# Observation   
vtTrack Plots  
```{r, fig.cap="track plot",echo=FALSE, eval=TRUE, results='asis'}
if(!is.null(data.all$om)) {
    vtTrack(data.all$om, end.width = 0.8, max.level = data.all$currentLevel)
    print(xtable(data.all$om, digits = 0), comment=FALSE, include.rownames=FALSE);
} else {
    "No observation plot was generated from this session."
}

```

\clearpage  

# Observation Interim
  
```{r, echo=FALSE, eval=TRUE}
par(pin=c(3,3));
if(!is.null(data.all$om)) {
    for (i in 1:data.all$ndose) {
        cur.obs.y <- data.all$om[i, -1];
        if (1 == i) {
            prev.obs.y <- NULL;
            prev.res   <- 0;
        } else {
            prev.obs.y <- p.data$om[i-1,-1];
            prev.res   <- NULL;
        }
        cat(paste("\nLevel", i))
        plot(vtInterim(cur.obs.y, prev.obs.y = prev.obs.y, prev.res = prev.res, dec.cut = data.all$dec.cut[1:3], etas = data.all$etas[1:2]));
    }
} else {
    "No observation plot was generated from this session."
}

```
