--- title: "Initial conditions" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Initial conditions} %\VignetteEncoding{UTF-8} %\VignetteEngine{knitr::rmarkdown} editor_options: chunk_output_type: console --- ```{r, results='asis', echo=F, message=F, warning=F} if (campsis::on_cran()) { cat( "This vignette was not built on CRAN. Please check out the online version [here](https://campsisverse.github.io/campsis.doc/articles/v08_initial_conditions.html)." ) knitr::knit_exit() } ``` ```{r, results='hide', echo=F, message=F, warning=F} library(campsis) ``` This vignette shows how initial conditions may be used in Campsis. ### Init central compartment Assume the following 2-compartment model is used. ```{r} model <- model_suite$nonmem$advan3_trans4 ``` We'd like to init the central compartment to a predefined value, e.g. 1000. This can be achieved as follows. ```{r} model <- model %>% add(InitialCondition(compartment = 1, rhs = "1000")) ``` The resulting model has now a new block `[INIT]` which describes the initial condition: ```{r} model ``` Let's now create a dataset with observations-only. ```{r} ds <- Dataset(50) %>% add(Observations(times = seq(0, 72, by = 0.5))) ``` We can now simulate this model: ```{r initial_condition , fig.align='center', fig.height=4, fig.width=8, message=F} results <- simulate(model = model, dataset = ds, seed = 1) shaded_plot(results, "CONC") ```