---
title: "Get started with CAMPSIS"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Get started with CAMPSIS}
  %\VignetteEncoding{UTF-8}
  %\VignetteEngine{knitr::rmarkdown}
editor_options: 
  chunk_output_type: console
---

### Library import

First import the `campsis` package:

```{r, message=FALSE}
library(campsis)
```

### Load model

Load 2-compartment PK model from built-in model library:

```{r}
model <- model_suite$pk$`2cpt_fo`
```

### Create dataset

Create your dataset in CAMPSIS. For instance, let's give 1000mg QD for 3 days and observe every hour.

```{r}
dataset <- Dataset(10) %>%
  add(Bolus(time=0, amount=1000, ii=24, addl=2)) %>%
  add(Observations(times=seq(0,72, by=1)))
```

### Simulate

Simulate this very simple protocol:

```{r, message=F}
results <- model %>% simulate(dataset, seed=1)
head(results)
```

### Plot results

Plot these results:

```{r get_started_spaguetti_plot, fig.align='center', fig.height=4, fig.width=8}
spaghettiPlot(results, "CONC")
```

A shaded plot may also be used:

```{r get_started_shaded_plot, fig.align='center', fig.height=4, fig.width=8}
shadedPlot(results, "CONC")
```

### Simulate 2 arms

We can also simulate two different treatment arms. Say the first arm receives 1000mg QD and the second arm 2000mg QD. This can be implemented as follows:

```{r get_started_2arms_plot, fig.align='center', fig.height=4, fig.width=8, message=F}
# First treatment arm
arm1 <- Arm(subjects=50, label="1000 mg QD") %>%
  add(Bolus(time=0, amount=1000, ii=24, addl=2)) %>%
  add(Observations(times=seq(0,72, by=1)))

# Second treatment arm
arm2 <- Arm(subjects=50, label="2000 mg QD") %>%
  add(Bolus(time=0, amount=2000, ii=24, addl=2)) %>%
  add(Observations(times=seq(0,72, by=1)))

dataset <- Dataset() %>% add(c(arm1, arm2))

results <- model %>% simulate(dataset, seed=1)
shadedPlot(results, "CONC", colour="ARM")
```

### Going further

We invite you to check out the other [vignettes](https://calvagone.github.io/campsis.doc/articles/). Have fun with CAMPSIS!
