---
output:
  html_notebook: default
params:
  m: NA
title: "`r paste0(ctl_path(params$m), ': GOF')`"
author: "`r Sys.info()['user']`"
date: "`r Sys.time()`"
---

<!-- To run as a notebook: -->
<!--   1. define .m to be your model in your workspace (e.g. .m <- m1) -->
<!--   2. run as normal notebook -->

<!-- To run as a report: -->
<!--   1. Use the nm_render() on your object -->
<!--   (e.g. m1 <- m1 %>% nm_render("path/to/this/report")) -->
<!--   2. see ?nm_render for additional information including results location -->

<!-- To make your own report (this is only a bare template) -->
<!--   1. start with an already run model object (e.g. m1) -->
<!--   2. add code and run as a notebook (see above) to see results -->
<!--   3. when finished, run as a report (see above) to see report -->
<!--   4. use nm_render() to run on other model objects -->


```{r setup, include=F}
## DO NOT MODIFY THIS BLOCK (unless you know what you're doing)
library(knitr)
library(rprojroot)
opts_knit$set(root.dir = find_root(
  has_file(".Rprofile") | 
    is_rstudio_project | 
    is_r_package | 
    is_git_root
))
opts_chunk$set(echo = FALSE)
opts_chunk$set(message = FALSE)
if(!is.null(knitr::opts_knit$get('rmarkdown.pandoc.to'))){
  .m <- params$m  
}
```

```{r lib_load, echo=FALSE,message=FALSE}
## LOAD PACKAGES HERE

library(dplyr)
library(ggplot2)

```

## model object

```{r wait_for_run_finish}
wait_finish(.m)
.m
```

## convergence

```{r plot_iter}
plot_iter(.m)
```

## outputs

```{r rr}
rr(.m)
```

## Diagnostics

```{r cov_plot}

covariance_plot(.m)

```


```{r ggplot}

## simple ggplot example

library(ggplot2)

.m %>%
  output_table_first() %>%
  ggplot(aes(x = PRED, y = DV)) +
  theme_bw() +
  geom_point() +
  geom_abline()

.m %>%
  output_table_first() %>%
  ggplot(aes(x = TIME, y = DV)) +
  theme_bw() +
  geom_point() +
  geom_line(aes(y = IPRED, group = ID), colour = "red")

```

```{r xpose_plot, warning=FALSE}

## simple xpose example

library(xpose)

xpdb <- xpose_data(runno = run_id(.m), dir = run_in(.m))

dv_vs_pred(xpdb)
dv_vs_ipred(xpdb)
ind_plots(xpdb, page = 1)

```

## Appendix

### control file

```{r txt}
.m %>% text() %>% dplyr::first()
```

### control file diff

```{r diff}
.m %>% nm_diff()
```


