Built 2024-04-18 using NMsim 0.1.0.901.

### Generating a simulation input data set

The pop PK model was estimated using an ADVAN subroutine with
extravascular dosing in compartment 1 and the central compartment is
compartment 2. This information is needed because the compartment
numbers in the simulation data set will be created to match this. We
shall see that this is the only information needed about the model for
`NMsim`

to be able to simulate it.

It does not matter to NMsim how we create a simulation data set as long as we get it into a data.frame structure. For the example, we used functions included with NMsim, but you can use anything. We create a regimen with a loading dose of 300 mg followed by 150 QD for 6 days. Notice that the compartment numbers match the compartment numbers that were used when estimating the model.

```
### multiple dose regimens with loading are easily created with NMcreateDoses too
## We use ADDL+II (either method easy)
doses <- NMcreateDoses(TIME=c(0,24),AMT=c(300,150),addl=data.frame(ADDL=c(0,5),II=c(0,24)),CMT=1)
doses <- transform(doses,trt="300 mg then 150 mg QD")
## Add simulation records - longer for QD regimens
dat.sim <- addEVID2(doses,time.sim=0:(24*7),CMT=2)
## sort data set
setorder(dat.sim,ID,TIME,EVID)
## Adding a row identifier (generally not necessary)
dat.sim$ROW <- 1:nrow(dat.sim)
```

`NMwriteData(dat.sim,file="simulate-results/dat_sim.fst",formats.write="fst",genText=FALSE)`

We check the simulation data set for various potential issues in
Nonmem data sets using `NMdata::NMcheckData`

and summarize
the number of doses and observations:

```
NMcheckData(dat.sim,type.data="sim")
#> No findings. Great!
```

A brief overview of the number of events broken down by event type
`EVID`

and dose amount `AMT`

:

trt | EVID | AMT | Nrows |
---|---|---|---|

300 mg then 150 mg QD | 1 | 150 | 6 |

300 mg then 150 mg QD | 1 | 300 | 1 |

300 mg then 150 mg QD | 2 | NA | 169 |

Showing the top five rows for understanding what the data now looks
like. Notice that the following are *not* issues:

- Data contains a mix of numeric and non-numeric columns
- Columns are not sorted in Nonmem-friendly style with non-numeric columns to the right

```
#> ID TIME EVID CMT AMT II ADDL MDV trt DV
#> <int> <num> <num> <num> <num> <num> <num> <num> <char> <num>
#> 1: 1 0 1 1 300 0 0 1 300 mg then 150 mg QD NA
#> 2: 1 0 2 2 NA NA NA 1 300 mg then 150 mg QD NA
#> 3: 1 1 2 2 NA NA NA 1 300 mg then 150 mg QD NA
#> 4: 1 2 2 2 NA NA NA 1 300 mg then 150 mg QD NA
#> 5: 1 3 2 2 NA NA NA 1 300 mg then 150 mg QD NA
#> ROW
#> <int>
#> 1: 1
#> 2: 2
#> 3: 3
#> 4: 4
#> 5: 5
```