---
title: |
    | `r projectName`
fig: no crop
geometry: left=1mm, right=1mm, top=1mm, bottom=1mm, asymmetric
indent: TRUE
output:
  html_document:
    df_print: paged
    fig_caption: yes
  word_document: default
  pdf_document: default
header-includes: 
    - \usepackage{placeins}
    - \usepackage{indentfirst}
    - \usepackage{setspace}\doublespacing
    - \usepackage{lineno}
    - \linenumbers
author: "`r 'PFIM 6.0' `"
date: "`r paste( 'Date:' , Sys.Date())`"
---

```{r setup, include=FALSE}
options(kableExtra.latex.load_packages = FALSE)
options(kableExtra.auto_format = FALSE)
knitr::opts_chunk$set(echo = TRUE)
```

```{r, echo=FALSE}
title_shrinkage = FALSE
variance_components = TRUE
if ( fimType == "BayesianFim" )
{
  title_shrinkage = TRUE
  variance_components = FALSE
}
```

# Model outputs 

```{r modelOutputs, echo = FALSE, comment='', fig.height = 5, fig.width = 10, fig.align = "center"} 
tablesEvaluationFIMIntialDesignResults$tablesModelEquations$outcomes
```

# Model equations

```{r modelEquations, echo = FALSE, comment='', fig.height = 5, fig.width = 10, fig.align = "center"} 
tablesEvaluationFIMIntialDesignResults$tablesModelEquations$equations
```

# Model error

```{r modelError, echo = FALSE, comment='', fig.height = 5, fig.width = 10, fig.align = "center"} 
tablesEvaluationFIMIntialDesignResults$tablesModelError
```

# Model parameters

```{r modelParameters, echo = FALSE, comment='', fig.height = 5, fig.width = 10, fig.align = "center"} 
tablesEvaluationFIMIntialDesignResults$tablesModelParameters
```

# Administration parameters

```{r administrationParameters, echo = FALSE, comment='', fig.height = 5, fig.width = 10, fig.align = "center"} 
tablesEvaluationFIMIntialDesignResults$tablesAdministration
```

# Initial design 

```{r initialDesignParameters, echo = FALSE, comment='', fig.height = 5, fig.width = 10, fig.align = "center"} 
tablesEvaluationFIMIntialDesignResults$tablesDesign
```

# Administration and sampling time constraints  

```{r samplingTimeConstraints, echo = FALSE, comment='', fig.height = 5, fig.width = 10, fig.align = "center"} 

variableSelection = c("Design","Arm","Outcome", "Doses", "Initial sampling times","Fixed times", "Number of samplings optimisable")

table = tablesOptimizationObject$tablesSamplingConstraints[,variableSelection]
colnames( table ) = variableSelection

knitr::kable( table ) %>%
  kable_styling( font_size = 12,
                 latex_options = c("hold_position","striped", "condensed", "bordered" ),
                 full_width = T)
```

## Determinant, condition numbers and D-criterion of the FIM

```{r criteriaFimInitialDesignTable, echo = FALSE, comment='', fig.height = 5, fig.width = 10, fig.align = "center"} 
tablesEvaluationFIMIntialDesignResults$tablesFIM$criteriaFimTable 
```

# Optimal design

```{r optimalDesignParameters, echo = FALSE, comment='', fig.height = 5, fig.width = 10, fig.align = "center"} 
tablesOptimizationObject$tablesDesign
```

## Fisher information matrix

### Fixed effects

```{r FIMFixedEffectsTable, echo = FALSE, comment='', fig.height = 5, fig.width = 10, fig.align = "center"} 
tablesOptimizationObject$tablesFIM$FIMFixedEffectsTable 
```

`r if ( variance_components ) '### Variance effects'`
```{r FIMVarianceEffectsTable, eval = variance_components, echo = FALSE, comment='', fig.height = 5, fig.width = 10, fig.align = "center"} 
tablesOptimizationObject$tablesFIM$FIMVarianceEffectsTable 
```

## Correlation matrix

### Fixed effects

```{r correlationMatrixFixedEffectsTable, echo = FALSE, comment='', fig.height = 5, fig.width = 10, fig.align = "center"} 
tablesOptimizationObject$tablesFIM$correlationMatrixFixedEffectsTable 
```

`r if ( variance_components ) '### Variance effects'`
```{r correlationMatrixVarianceEffectsTable, eval = variance_components, echo = FALSE, comment='', fig.height = 5, fig.width = 10, fig.align = "center"} 
tablesOptimizationObject$tablesFIM$correlationMatrixVarianceEffectsTable 
```

## Determinant, condition numbers and D-criterion of the FIM

```{r criteriaFimTable, echo = FALSE, comment='', fig.height = 5, fig.width = 10, fig.align = "center"} 
tablesOptimizationObject$tablesFIM$criteriaFimTable 
```

## Values for SE and RSE

```{r SEandRSETable, echo = FALSE, comment='', fig.height = 5, fig.width = 10, fig.align = "center"} 
tablesOptimizationObject$tablesFIM$SEandRSETable 
```

# Graphs for the responses

```{r plotOutcomesEvaluation, echo = FALSE, comment='', fig.height = 5, fig.width = 10, fig.align = "center"}

plotOutcomesEvaluation = tablesOptimizationObject$tablesPlot$plotOutcomesEvaluation

designNames = names( plotOutcomesEvaluation )

for ( designName in designNames )
{
  armNames = names( plotOutcomesEvaluation[[ designName ]] )
  
  for ( armName in armNames )
  { 
    outcomes = names( plotOutcomesEvaluation[[ designName ]][[armName]] )
    
    for ( outcome in outcomes )
    {
      print( plotOutcomesEvaluation[[designName]][[armName]][[outcome]] )
    }
  }
}
```

# Graphs for the sensitivity indices

```{r plotOutcomesGradient, echo = FALSE, comment='', fig.height = 5, fig.width = 10, fig.align = "center"} 
plotOutcomesGradient = tablesOptimizationObject$tablesPlot$plotOutcomesGradient

designNames = names( plotOutcomesGradient )

for ( designName in designNames )
{
  armNames = names( plotOutcomesGradient[[ designName ]] )
  
  for ( armName in armNames )
  { 
    outcomes = names( plotOutcomesGradient[[ designName ]][[armName]] )
    
    for ( outcome in outcomes )
    {
      parameterNames = names( plotOutcomesGradient[[ designName ]][[armName]][[outcome]] )
      
      for ( parameterName in parameterNames )
      {
        print( plotOutcomesGradient[[designName]][[armName]][[outcome]][[parameterName]] )
      }
    }
  }
}

```

# Graphs for the SE and RSE

```{r plotSEandRSE, echo = FALSE, comment='', fig.height = 5, fig.width = 10, fig.align = "center"} 

plotSE = tablesOptimizationObject$tablesPlot$plotSE
plotRSE = tablesOptimizationObject$tablesPlot$plotRSE

designNames = names( plotSE )

for ( designName in designNames )
{
  print( plotSE[[designName]] )
  print( plotRSE[[designName]] )
}
```

`r if ( title_shrinkage ) '# Graph of shrinkage'`
```{r shrinkage, eval = title_shrinkage, echo = FALSE, fig.height = 5, fig.width = 10, fig.align = "center"}
if ( title_shrinkage ==TRUE)
{
  plotShrinkage = tablesOptimizationObject$tablesPlot$plotShrinkage
  
  designNames = names( plotShrinkage )
  
  for ( designName in designNames )
  {
    print( plotShrinkage[[designName]] )
  }
}
```
