```
using Pumas
using DataFramesMeta
using PumasUtilities
```

# Case Study III - Development of a Population PKPD Model

## 1 From NONMEM to Pumas

In Case Study I through III we re-did the analyses from here as they would have to be done in Pumas. Many new users of Pumas come from a background in NONMEM. A common question is then: “How do I translate my NONMEM model into Pumas?” Hopefully, this tutorial will help with the understand of the connection between parts of a NONMEM control stream and a Pumas model script for Case Study III.

## 2 Case Study III: PK Model

The full control stream for Case Study III looks as follows.

```
;DATE 6-2-04 PROGRAMMER:XXXX
$PROBLEM PROJECT singledose i.v infusion ;UNITS: Time=hour, Concentration=ng/ml
;Dose=100mg, Clearance=L/hr, Volume = L
=C
$DATA cs3_ivinfest.csv IGNORE=DV AMT RATE MDV
$INPUT ID TIME CONC;RATE specifies the infusion rate, for a dose of 100mg, rate of 16.7mg/hr
;means infusion for 6hrs
; A one compartment model from PREDPP library
$SUBROUTINE ADVAN1 TRANS2
$PK= THETA(1)
TVCL= TVCL*EXP(ETA(1)) ;Clearance in L/hr
CL= THETA(2)
TVV= TVV*EXP(ETA(2)) ;Volume of distribution in L
V=V/1000 ;scaling factor to match concentration in ng/ml
S1
$ERROR=F
IPRED=F+F*ERR(1)+ERR(2) ;Combined residual error model
Y
5,25) ;POPCL
$THETA (10,86) ;POPV
$THETA (
0.09 ;BSVCL;30% BSV for Clearance
$OMEGA 0.09 ;BSVV;30% BSV for volume
$OMEGA
0.02 ;ERRCV;Proportional error = 15%
$SIGMA 10 ;ERRSD;Additive error =3ng/ml
$SIGMA
=0 MAXEVAL=9990 PRINT=10 POSTHOC
$ESTIMATION METHOD
$COVARIANCE
$TABLE ID TIME DV IPRED AMT CL V ETA1 ETA2= NOPRINT ONEHEADER FILE
```

In order to understand how write this in Pumas we need to break it down. We will go by the order of the control stream and in the end we will write out the code in full.

### 2.1 `$PROBLEM`

The first part of the control stream is the problem title

` $PROBLEM PROJECT singledose i.v infusion`

Pumas does not have a direct `$PROBLEM`

equivalent. In NONMEM, it is used to give a title to the project including model, estimation, inference, and more. In Pumas, each analysis is much more flexible such that one script can contain several calls to inference using `infer`

(including bootstraps). There is the possibility of adding a name to a model. Inside the the `@model`

block it is possible to add a description using the `@metadata`

block including the unit of time for example.

```
@model begin
@metadata begin
= "singledose i.v infusion"
desc = u"hr" # hour
timeu end
end
```

### 2.2 `$DATA`

The next part of the control stream is the data input.

`=C $DATA cs3_ivinfest.csv IGNORE`

Here, we point to the data set and rows to ignore. The specific line tells us to ignore all rows that start with C (for Comment). In Pumas, we also have to read in the data from a source such as `xpt`

, `sas7bdat`

, or `csv`

. In Case Study III, the equivalent line is

`= CSV.read("cs3_ivinfest.csv", DataFrame; header=5) pkdata `

`CSV.read`

expects a source first (the path to the file) and a sink (the type of table to construct, here a `DataFrame`

). The `header`

keyword tells us to ignore the first 5 lines (those that start with C),

### 2.3 `$INPUT`

The $INPUT statement in NONMEM allows you to name the columns from the file in the $DATA statement.

`=DV AMT RATE MDV $INPUT ID TIME CONC`

The `CONC=DV`

statements indicates that the third column should use the name CONC and that it is the reserved `DV`

keyword. In other words, the thirds column is the dependent variable and we want all output regarding this variable to have the `CONC`

label in the output.

The dataset used in the tutorial was ready for NONMEM, but not exactly in the format we expect in Pumas. The tutorial has the required data steps. After those, the equivalent in Pumas is the following.

```
= read_pumas(
population_pk
pkdata;= :ID,
id = :TIME,
time = [:CONC],
observations = :EVID,
evid = :AMT,
amt = :RATE,
rate = :CMT,
cmt )
```

This looks extra verbose, but this is only because we are using “NONMEM” style column names. If all the column names had been lowercase instead, we can simply write the step as follows.

`= read_pumas(pkdata; observations = [:conc],) population_pk `

### 2.4 `$SUBROUTINE`

The next statement in the control stream is the `$SUBROUTINE`

. This specifies the ADVAN and the parameter format.

`; A one compartment model from PREDPP library $SUBROUTINE ADVAN1 TRANS2 `

The equivalent code in Pumas is found in the `@model`

. The `@dynamics`

block specifies the equivalent to `ADVAN1 TRANS2`

below.

```
@model begin
@metadata begin
= "PROJECT multipledose oral study"
desc = u"hr" # hour
timeu end
@dynamics Central1
end
```

### 2.5 `$PK`

The `$PK`

statement specifies the model parameters including random effects and covariate models in NONMEM.

```
$PK= THETA(1)
TVCL = TVCL*EXP(ETA(1)) ;Clearance in L/hr
CL = THETA(2)
TVV = TVV*EXP(ETA(2)) ;Volume of distribution in L
V = V/1000 ;scaling factor to match concentration in ng/ml S1
```

`ADVAN1 TRANS2`

understands the reserved keywords `CL`

, `V`

, and `S1`

. There is no scale (`S1`

) equivalent in Pumas. Instead, you can scale the variables when needed. The other parameters have similar reserved parameter names in Pumas when using the `Central1`

model:

`CL`

in NONMEM is`CL`

in Pumas`V`

in NONMEM is`Vc`

in Pumas (Volume of distribution for Central)

This results in the following `@pre`

block (the Pumas equivalent to `$PK`

)

```
@model begin
@metadata begin
= "PROJECT multipledose oral study"
desc = u"hr" # hour
timeu end
@pre begin
= θcl * exp(η[1])
CL = θvc * exp(η[2])
Vc end
@dynamics Central1
end
```

So far, the Pumas model looks as follows.

```
@model begin
@metadata begin
= "PROJECT multipledose oral study"
desc = u"hr" # hour
timeu end
@pre begin
= θcl * exp(η[1])
CL = θvc * exp(η[2])
Vc end
@dynamics Central1
end
```

### 2.6 `$ERROR`

The statistical model of the modeled concentrations are specified in the `$ERROR`

statement.

```
$ERROR=F
IPRED=F+F*ERR(1)+ERR(2) ;Combined residual error model Y
```

Here, `F`

specifies the prediction of the model given the parameters and solution. Since this statement is evaluated with `etas`

during estimation, `F`

is assigned to `IPRED`

here. Then we build the error model with `ERR`

statements. In Pumas, we do not build the distribution of `Y`

like this. Rather we specify the distributional assumption directly.

```
@model begin
@metadata begin
= "PROJECT multipledose oral study"
desc = u"hr" # hour
timeu end
@pre begin
= θcl * exp(η[1])
CL = θvc * exp(η[2])
Vc end
@dynamics Central1
@derived begin
:= @. Central / Vc
conc_model ~ @. Normal(conc_model, sqrt(σ_add^2 + (conc_model*σ_prop)^2))
CONC end
end
```

Here, `σ_add`

is the standard deviation associated with `ERR(2)`

in the NONMEM model and `σ_prop`

is the same for `ERR(1)`

.

### 2.7 `$THETA`

, `$OMEGA`

, `$SIGMA`

Finally, we get to the last part of the model code: the fixed effects and random effects specification. In Pumas, these are typically placed first instead of last. If we start with the fixed effects, these are specified as follows in the control stream.

```
5,25) ;POPCL
$THETA (10,86) ;POPV
$THETA (
0.09 ;BSVCL;30% BSV for Clearance
$OMEGA 0.09 ;BSVV;30% BSV for volume
$OMEGA
0.02 ;ERRCV;Proportional error = 15%
$SIGMA 10 ;ERRSD;Additive error =3ng/ml $SIGMA
```

In Pumas, this is equivalent to:

```
@param begin
∈ RealDomain(lower=0.0)
θcl ∈ RealDomain(lower=0.0)
θvc ∈ PDiagDomain(2)
Ω ∈ RealDomain(lower=0.0)
σ_add ∈ RealDomain(lower=0.0)
σ_prop end
```

Since we specify the “SIGMA” parameters as standard deviations in this example in Pumas, we have to square the initial values. We put no restriction on names and where different parameters can be used in other blocks, but we do suggest the best practice of using `Ω`

for variance-covariance matrices for random effects, `ω`

for individual standard deviations used in scalar random effect specifications, and `σ`

for standard deviations used in error models. If you prefer to specify variances over standard deviations, we suggest using `ω²`

and `σ²`

respectively.

In NONMEM, the random effect specification was implicit based on the `OMEGA`

s. In Pumas, we have more flexibility with respect to the specification of named random effects and the distributions of them (say, a `Beta`

distributed random effect for a bioavailability). In the current case study, the random effects specification is simple.

```
@random begin
~ MvNormal(Ω)
η end
```

Then, the final model looks as follows.

```
= @model begin
inf1cmt @param begin
∈ RealDomain(lower=0.0)
θcl ∈ RealDomain(lower=0.0)
θvc ∈ PDiagDomain(2)
Ω ∈ RealDomain(lower=0.0)
σ_add ∈ RealDomain(lower=0.0)
σ_prop end
@random begin
~ MvNormal(Ω)
η end
@pre begin
= θcl * exp(η[1])
CL = θvc * exp(η[2])
Vc end
@dynamics Central1
@derived begin
:= @. Central / Vc
conc_model ~ @. Normal(conc_model, sqrt(σ_add^2 + (conc_model*σ_prop)^2))
CONC end
end
```

As you may have noticed, we write the parameter, random effects, pk parameters, dynamical system specification and error model in a different order than what was in the original control stream. This is because we find it more clear when reading the code to define things before they are used.

### 2.8 `$ESTIMATION`

Just as we had for the `$DATA`

and `$INPUT`

statements, we have a difference between the two systems when it comes to `$ESTIMATION`

. In Pumas, we do not include this information in the “model” because the workflow is typically more interactive.

`=0 MAXEVAL=9990 PRINT=10 POSTHOC $ESTIMATION METHOD`

The equivalent to the above is something like

```
= (
param0 = 1.0,
θcl = 1.0,
θvc = Diagonal([0.09, 0.09]),
Ω = sqrt(10.0),
σ_add = sqrt(0.01),
σ_prop
)= fit(inf1cmt, population_pk, param0, Pumas.FOCE(); optim_options=(show_every=10, iterations=9990,)) inf1cmt_results
```

Here, `METHOD=0`

is equivalent to specifying `FO()`

in Pumas, `MEXAEVAL`

is the same as the `iterations`

key in `optim_options`

, `PRINT`

is roughly equivalent to `show_every`

. `POSTHOC`

can be obtained by called the `empirical_bayes`

function later in the script. The specification in NONMEM is necessary because FO does not need to estimate the empirical bayes estimates (EBEs) during fitting. POSTHOC forces the calculation of the EBEs at the end.

### 2.9 `$COVARIANCE`

In Pumas, the `$COVARIANCE`

step is equivalent to the `infer`

function.

` $COVARIANCE `

To calculate the asymptotic variance-covariance matrix, use the `infer`

function on the fit output and grab the `vcov`

field.

```
= infer(model_fit)
model_infer = model_infer.vcov model_vcov
```

### 2.10 `$TABLE`

Since each NONMEM run is invoked based on the control stream it is necessary to specify what to output when the fitting and inference steps have completed. In Pumas, it is possible interactively work with the objects and save what is needed when the users wishes.

` $TABLE ID TIME DV IPRED AMT CL V ETA1 ETA2`

The above information can also be saved by computing the `inspect`

quantities, convert them to a `DataFame`

and save them to a file.

```
= inspect(inf1cmt_results)
inf1cmt_insp = DataFrame(inf1cmt_insp)
df_inspect write("inspect_file.csv", df_inspect) CSV.
```

Then, the PK model is translated.

## 3 Case Study III: PD model

```
-PD MODELING ;DATE 6-2-04 PROGRAMMER:XXXX
$PROBLEM PROJECT POPULATION PK;UNITS: Time=hour, Concentration=ng/ml
;Dose=100mg/6HR, Clearance=L/hr, Volume = L
;Biomarker = Blood Histamine
;concentration,ng/ml
=C
$DATA cs3_ivinfpdest.csv IGNORE=DV AMT CMT RATE MDV CLI VI
$INPUT ID TIME HIST
=3 ;User defined model written as differential equations
$SUBROUTINE ADVAN6 TRANS1 TOL;$MODEL defines the no of compartments in the model
$MODEL = CENTRAL
COMP = EFFECT
COMP
$PK= CLI ;Individual clearance estimates from PK analysis
CL = VI ;Individual Volume estimates
V = V/1000 ;To get concentration in ng/ml
S1 = THETA(1)*EXP(ETA(1))
KIN = THETA(2)*EXP(ETA(2))
KOUT = THETA(3)*EXP(ETA(3))
IC50 = KIN/KOUT ;Initializing to baseline; R0 = kin/kout
F2
$DES1) = -CL/V*A(1) ;Plasma
DADT(= A(1)/(IC50+A(1)) ;Inhibitory function
INH 2) = KIN*(1-INH) - KOUT*A(2) ;Inhibition of input (Inhibitory Indirect Response model)
DADT(
$ERROR= A(1)/S1
CP1 = F
IPRED = F+F*ERR(1)+ERR(2)
Y
0.1,7) ;POPKin
$THETA (0.01,0.3) ;POPKout
$THETA (0.1,6) ;POPIC50
$THETA (
0.09 ;BSV Kin
$OMEGA 0.09 ;BSV Kout
$OMEGA 0.09 ;BSV IC50
$OMEGA
0.01 ;ERRCCV
$SIGMA 1 ;ERRADD
$SIGMA
=0 MAXEVAL=9990 PRINT=10 POSTHOC
$ESTIMATION METHOD
$COVARIANCE
$TABLE ID TIME HIST IPRED AMT CMT RATE= NOPRINT ONEHEADER FILE
```

### 3.1 `$PROBLEM`

The first part of the control stream is the problem title

`-PD MODELING $PROBLEM PROJECT POPULATION PK`

This is

```
@model begin
@metadata begin
= "POPULATION PK-PD MODELING"
desc = u"hr" # hour
timeu end
end
```

### 3.2 `$DATA`

The next part of the control stream is the data input. This time we input the data that has been augmented with PK predictions.

`=C $DATA cs3_ivinfpdest.csv IGNORE`

Here, we point to the data set and rows to ignore. The specific line tells us to ignore all rows that start with C (for Comment). In Pumas, we also have to read in the data from a source such as `xpt`

, `sas7bdat`

, or `csv`

. In Case Study III, the equivalent line is

`= CSV.read("cs3_ivinfest.csv", DataFrame; header=5) pkdata `

`CSV.read`

expects a source first (the path to the file) and a sink (the type of table to construct, here a `DataFrame`

). The `header`

keyword tells us to ignore the first 5 lines (those that start with C),

### 3.3 `$INPUT`

For this `$INPUT`

statement we also need to input the PD derived variable and the individually predicted PK parameters from the PK model.

`=DV AMT CMT RATE MDV CLI VI $INPUT ID TIME HIST`

The `HIST=DV`

statements indicates that the third column should use the name HIST and that it is the reserved `DV`

keyword as it did for the PK model.

In Pumas, this is equivalent to the following after a bit of data wrangling that is shown in the tutorial:

```
= read_pumas(
population_pd
pd_dataframe;= :ID,
id = :TIME,
time = [:HIST],
observations = :AMT,
amt = :CMT,
cmt = :RATE,
rate = [:CLi, :Vci],
covariates )
```

This looks extra verbose, but this is only because we are using “NONMEM” style column names. If all the column names had been lowercase instead, we can simply write the step as follows.

```
= read_pumas(
population_pd
pd_dataframe;= [:HIST],
observations = [:CLi, :Vci],
covariates )
```

### 3.4 `$SUBROUTINE`

The next statement in the control stream is the `$SUBROUTINE`

. This specifies the ADVAN and the parameter format.

`=3 ;User defined model written as differential equations $SUBROUTINE ADVAN6 TRANS1 TOL`

Note, that this time we use ADVAN6 ans TRANS1 as well as a tolerance. We are going to write out the model manually and use a numerical integrator to solve the model. For this reason, we also need to define the compartment name as is done in the `$MODEL`

statement:

```
$MODEL ;$MODEL defines the no of compartments in the model
COMP = CENTRAL
COMP = EFFECT
```

and the dynamics in the `$DES`

statement

```
$DES
DADT(1) = -CL/V*A(1) ;Plasma
INH = A(1)/(IC50+A(1)) ;Inhibitory function
DADT(2) = KIN*(1-INH) - KOUT*A(2) ;Inhibition of input (Inhibitory Indirect Response model)
```

The equivalent code in Pumas is found in the `@model`

. The `@dynamics`

block below specifies the equivalent to the NONMEM model statements:

```
@init begin
= bsl
Response end
@dynamics begin
' = -CL/Vc*Central
Central' = kin*(1 - imax*(Central/Vc)/(ic50 + Central/Vc)) - kout*Response
Responseend
```

The baseline parameter `bsl`

is going to be defined below.

ADVAN6 and TOL are specified in the model, but we specify this in the calls later on in Pumas

### 3.5 `$PK`

The `$PK`

statement specifies the model parameters including random effects and covariate models in NONMEM.

```
$PK= CLI ;Individual clearance estimates from PK analysis
CL = VI ;Individual Volume estimates
V = V/1000 ;To get concentration in ng/ml
S1 = THETA(1)*EXP(ETA(1))
KIN = THETA(2)*EXP(ETA(2))
KOUT = THETA(3)*EXP(ETA(3))
IC50 = KIN/KOUT ;Initializing to baseline; R0 = kin/kout F2
```

This time there are no reserved keywords in the Pumas model because we are using handwritten systems, but NONMEM does make use of some reserved keywords. `F2`

is the bioabailability of drug going into `A(2)`

(the response compartment). Note, that we do not *have* a dose affecting response this way. This is a way to set the initial conditions. In the dataset, the are doses of 1 unit going into compartment 2 and if we multiply this my `KIN/KOUT`

we get that `A(2)`

starts at `KIN/KOUT`

. Notice, that this is a bit of a strange way to do it, as there is the option to use `A_0(2) = KIN/KOUT`

in `$PK`

.

This results in the following `@pre`

block (the Pumas equivalent to `$PK`

)

```
@covariates CLi Vci
@pre begin
= tvkin*exp(η[1])
kin = tvkout*exp(η[2])
kout = tvic50*exp(η[3])
ic50 = kin/kout
bsl = tvimax
imax = CLi
CL = Vci
Vc end
```

We included the `imax`

parameter because it belongs in the model, but it will be fixed to `1`

later. So far, the Pumas model looks as follows. The two covariates we bring in (`CLi`

, `Vci`

) are the predicted individual parameters from the PK model.

```
= @model begin
irm1 @metadata begin
= "POPULATION PK-PD MODELING"
desc = u"hr" # hour
timeu end
@covariates CLi Vci
@pre begin
= tvkin*exp(η[1])
kin = tvkout*exp(η[2])
kout = kin/kout
bsl = tvic50*exp(η[3])
ic50 = tvimax
imax = CLi
CL = Vci
Vc end
@init begin
= bsl
Response end
@dynamics begin
' = -CL/Vc*Central
Central' = kin*(1 - imax*(Central/Vc)/(ic50 + Central/Vc)) - kout*Response
Responseend
end
```

### 3.6 `$ERROR`

The statistical model of the modeled concentrations are specified in the `$ERROR`

statement.

```
$ERROR= A(1)/S1
CP1 = F
IPRED = F+F*ERR(1)+ERR(2) Y
```

Here, `F`

specifies the prediction of the model given the parameters and solution. Since this statement is evaluated with `etas`

during estimation, `F`

is assigned to `IPRED`

here. Then we build the error model with `ERR`

statements. In Pumas, we do not build the distribution of `Y`

like this. Rather we specify the distributional assumption directly.

```
@derived begin
~ @. Normal(Response, sqrt(σ_add_pd^2 + (Response*σ_prop_pd)^2))
HIST end
```

Here, `σ_add_pd`

is the standard deviation associated with `ERR(2)`

in the NONMEM model and `σ_pro_pd_`

is the same for `ERR(1)`

.

### 3.7 `$THETA`

, `$OMEGA`

, `$SIGMA`

Finally, we get to the last part of the model code: the fixed effects and random effects specification. In Pumas, these are typically placed first instead of last. If we start with the fixed effects, these are specified as follows in the control stream.

```
0.1,7) ;POPKin
$THETA (0.01,0.3) ;POPKout
$THETA (0.1,6) ;POPIC50
$THETA (
0.09 ;BSV Kin
$OMEGA 0.09 ;BSV Kout
$OMEGA 0.09 ;BSV IC50
$OMEGA
0.01 ;ERRCCV
$SIGMA 1 ;ERRADD $SIGMA
```

In Pumas, this is equivalent to:

```
@param begin
∈ RealDomain(lower=0)
tvkin ∈ RealDomain(lower=0)
tvkout ∈ RealDomain(lower=0)
tvic50 ∈ RealDomain(lower=0)
tvimax ∈ PDiagDomain(3)
Ω ∈ RealDomain(lower=0)
σ_add_pd ∈ RealDomain(lower=0)
σ_prop_pd end
```

Since we specify the “SIGMA” parameters as standard deviations in this example in Pumas, we have to square the initial values. We put no restriction on names and where different parameters can be used in other blocks, but we do suggest the best practice of using `Ω`

for variance-covariance matrices for random effects, `ω`

for individual standard deviations used in scalar random effect specifications, and `σ`

for standard deviations used in error models. If you prefer to specify variances over standard deviations, we suggest using `ω²`

and `σ²`

respectively.

In NONMEM, the random effect specification was implicit based on the `OMEGA`

s. In Pumas, we have more flexibility with respect to the specification of named random effects and the distributions of them (say, a `Beta`

distributed random effect for a bioavailability). In the current case study, the random effects specification is simple.

```
@random begin
~ MvNormal(Ω)
η end
```

Then, the final model looks as follows.

```
= @model begin
irm1 @metadata begin
= "POPULATION PK-PD MODELING"
desc = u"hr" # hour
timeu end
@param begin
∈ RealDomain(lower=0)
tvkin ∈ RealDomain(lower=0)
tvkout ∈ RealDomain(lower=0)
tvic50 ∈ RealDomain(lower=0)
tvimax ∈ PDiagDomain(3)
Ω ∈ RealDomain(lower=0)
σ_add_pd ∈ RealDomain(lower=0)
σ_prop_pd end
@random begin
~ MvNormal(Ω)
η end
@covariates CLi Vci
@pre begin
= tvkin*exp(η[1])
kin = tvkout*exp(η[2])
kout = kin/kout
bsl = tvic50*exp(η[3])
ic50 = tvimax
imax = CLi
CL = Vci
Vc end
@init begin
= bsl
Response end
@dynamics begin
' = -CL/Vc*Central
Central' = kin*(1 - imax*(Central/Vc)/(ic50 + Central/Vc)) - kout*Response
Responseend
@derived begin
~ @. Normal(Response, sqrt(σ_add_pd^2 + (Response*σ_prop_pd)^2))
HIST end
end
```

As you may have noticed, we write the parameter, random effects, pk parameters, dynamical system specification and error model in a different order than what was in the original control stream. This is because we find it more clear when reading the code to define things before they are used.

### 3.8 `$ESTIMATION`

Just as we had for the `$DATA`

and `$INPUT`

statements, we have a difference between the two systems when it comes to `$ESTIMATION`

. In Pumas, we do not include this information in the “model” because the workflow is typically more interactive.

`=0 MAXEVAL=9990 PRINT=10 POSTHOC $ESTIMATION METHOD`

The equivalent to the above is something like

```
= (
param0 = 5.4,
tvkin = 0.3,
tvkout =3.9,
tvic50=1.0,
tvimax= Diagonal([0.2, 0.2, 0.2]),
Ω =0.05,
σ_add_pd=0.05)
σ_prop_pd= fit(irm1, population_pd, init_θ, Pumas.FOCE(); constantcoef=(tvimax=1.0,), optim_options = (show_every=10, optim_options=(iterations=9990,)) inf1cmt_results
```

Here, `METHOD=0`

is equivalent to specifying `FO()`

in Pumas, `MEXAEVAL`

is the same as the `iterations`

key in `optim_options`

, `PRINT`

is roughly similar to `show_every`

. `POSTHOC`

can be obtained by called the `empirical_bayes`

function later in the script. The specification in NONMEM is necessary because FO does not need to estimate the empirical bayes estimates (EBEs) during fitting. POSTHOC forces the calculation of the EBEs at the end.

### 3.9 `$COVARIANCE`

In Pumas, the `$COVARIANCE`

step is equivalent to the `infer`

function.

` $COVARIANCE `

To calculate the asymptotic variance-covariance matrix, use the `infer`

function on the fit output and grab the `vcov`

field.

```
= infer(inf1cmt_results)
model_infer = model_infer.vcov model_vcov
```

### 3.10 `$TABLE`

Since each NONMEM run is invoked based on the control stream it is necessary to specify what to output when the fitting and inference steps have completed. In Pumas, it is possible interactively work with the objects and save what is needed when the users wishes.

` $TABLE ID TIME HIST IPRED AMT CMT RATE`

The above information can also be saved by computing the `inspect`

quantities, convert them to a `DataFame`

and save them to a file.

```
= inspect(inf1cmt_results)
inf1cmt_insp = DataFrame(inf1cmt_insp)
df_inspect write("inspect_file.csv", df_inspect) CSV.
```

Then the PD model is translated.

## 4 Conclusion

In this tutorial, we saw how to translate the ACCP Case Study III from NONMEM to Pumas. Hopefully, this helps new users connect the dots and understand how one section of a NONMEM control stream relates to a model block or function call in Pumas. This case study was a little bit more complicated as it took in parameter from one model into the other, but using the functionality for subject covariates we could easily do sequential modeling in Pumas.