Skip to contents

Perform visual predictive check for NLME models

Usage

vpcmodel(
  model,
  vpcParams,
  params,
  hostPlatform = NULL,
  runInBackground = FALSE,
  ...
)

Arguments

model

PK/PD model class object.

vpcParams

VPC argument setup. See NlmeVpcParams. If missing, default values generated by NlmeVpcParams() are used.

params

Engine argument setup. See engineParams. The following arguments are the subject of interest: sort, ODE, rtolODE, atolODE, maxStepsODE. If missing, default values generated by engineParams(model) are used.

hostPlatform

Host definition for model execution. See hostParams. If missing, simple local host is used.

runInBackground

Set to TRUE to run in background and return prompt.

...

Additional class initializer arguments for NlmeVpcParams or hostParams, or arguments available inside engineParams functions. If engineParams arguments are supplied through both params argument and additional argument (i.e., ellipsis), then the arguments in params will be ignored and only the additional arguments will be used with warning. If hostParams arguments are supplied through both hostPlatform argument and additional argument, then its values will be overridden by additional arguments. In addition, if NlmeVpcParams arguments are supplied through both vpcParams argument and additional argument, then its slots will be overridden by additional arguments.

Value

if runInBackground is TRUE, it returns job properties. Otherwise,

  • If the function is called in an interactive mode, the resulting simulated tables and summary statistics tables will be loaded and presented as a list;

  • If the function is called in a non-interactive mode, it returns the full paths of the tables generated

Examples

# \donttest{
model <- pkmodel(
  numComp = 1,
  absorption = "Extravascular",
  ID = "Subject",
  Time = "Act_Time",
  CObs = "Conc",
  Aa = "Amount",
  data = pkData,
  modelName = "PkModel",
  workingDir = tempdir()
)

 host <- hostParams(
  sharedDirectory = tempdir(),
  parallelMethod = "NONE",
  hostName = "local",
  numCores = 1
 )

job <- fitmodel(model = model,
                hostPlatform = host)
#> 
#> NLME Job
#> 
#> Compiling 1 of 1 NLME models
#> TDL5 version: 25.7.1.1
#> 
#> Status: OK
#> License expires: 2026-08-06
#> Refresh until: 2025-09-05 07:01:25
#> Current Date: 2025-08-06
#> The model compiled
#> 
#> 
#>  Iteration         -2LL     tvKa      tvV     tvCl nSubj nObs
#>          1 1.994694e+09 1.000000 1.000000 1.000000    16  112
#>          2 1.105887e+09 1.000000 1.000000 1.000000    16  112
#>          3 5.289122e+08 1.000000 1.000000 1.000000    16  112
#>          4 2.683141e+08 1.000000 1.000000 1.000000    16  112
#>          5 1.331841e+08 1.000000 1.000000 1.000000    16  112
#>          6 6.670444e+07 1.000000 1.000000 1.000000    16  112
#>          7 3.330637e+07 1.000000 1.000000 1.000000    16  112
#>          8 1.665502e+07 1.000000 1.000000 1.000000    16  112
#>          9 8.325699e+06 1.000000 1.000000 1.000000    16  112
#>         10 4.163575e+06 1.000000 1.000000 1.000000    16  112
#>         11 4.163575e+06 1.000000 1.000000 1.000000    16  112
#>         12 3.030272e+06 0.986951 0.526228 1.000040    16  112
#>         13 2.414036e+06 0.986078 0.552713 1.091940    16  112
#>         14 2.197233e+06 1.008050 0.556518 1.117300    16  112
#>         15 1.248481e+06 1.018500 0.541097 1.195840    16  112
#>         16 1.248481e+06 1.018500 0.541097 1.195840    16  112
#>         17 5.155618e+05 1.031220 0.546366 0.906401    16  112
#>         18 2.602570e+05 1.021620 0.552988 0.951693    16  112
#>         19 1.163796e+05 1.017350 0.555889 0.995225    16  112
#>         20 6.653264e+04 1.021310 0.558975 1.033720    16  112
#>         21 3.316336e+04 1.021200 0.565210 1.080030    16  112
#>         22 1.835841e+04 1.020950 0.569509 1.116360    16  112
#>         23 1.007382e+04 1.020870 0.574333 1.159190    16  112
#>         24 6.305650e+03 1.020930 0.578809 1.198910    16  112
#>         25 4.388810e+03 1.020910 0.583362 1.239470    16  112
#>         26 3.479240e+03 1.020910 0.587750 1.278590    16  112
#>         27 3.050900e+03 1.020920 0.591980 1.316400    16  112
#>         28 2.864540e+03 1.020990 0.595878 1.351220    16  112
#>         29 2.794160e+03 1.021040 0.599139 1.380520    16  112
#>         30 2.773150e+03 1.021090 0.601567 1.402290    16  112
#>         31 2.769420e+03 1.021140 0.603770 1.421790    16  112
#>         32 2.769240e+03 1.021150 0.603450 1.418950    16  112
#>         33 2.769230e+03 1.021170 0.603483 1.419190    16  112
#>         34 2.769120e+03 1.021300 0.603526 1.419270    16  112
#>         35 2.763770e+03 1.033130 0.607641 1.429080    16  112
#>         36 2.762090e+03 1.034870 0.608505 1.433630    16  112
#>         37 2.760000e+03 1.038610 0.610145 1.440780    16  112
#>         38 2.760000e+03 1.038610 0.610145 1.440780    16  112
#>         39 2.702990e+03 1.038610 0.610145 1.440780    16  112
#>         40 2.699260e+03 1.038610 0.610145 1.440780    16  112
#>         41 2.611010e+03 1.038610 0.610014 1.440780    16  112
#>         42 2.611010e+03 1.038610 0.610014 1.440780    16  112
#>         43 2.562180e+03 1.038610 0.608207 1.440780    16  112
#>         44 2.562180e+03 1.038610 0.608207 1.440780    16  112
#>         45 2.546930e+03 1.149980 0.693723 2.074670    16  112
#>         46 2.546930e+03 1.149980 0.693723 2.074670    16  112
#>         47 2.543730e+03 1.149980 0.693723 2.074670    16  112
#>         48 2.543730e+03 1.149980 0.693723 2.074670    16  112
#> 
#> Trying to generate job results...
#> 
#> Generating Overall.csv
#> Generating EtaEta.csv
#> Generating Eta.csv
#> Generating EtaStacked.csv
#> Generating bluptable.dat
#> Generating ConvergenceData.csv
#> Generating initest.csv
#> Generating doses.csv
#> Generating omega.csv
#> Generating theta.csv
#> Generating thetaCorrelation.csv
#> Generating thetaCovariance.csv
#> Generating Covariance.csv
#> Generating Residuals.csv
#> Generating posthoc.csv
#> 
#> Finished summarizing results. Transferring data and loading the results...
#> Done generating job results.

finalModelVPC <- copyModel(model,
                           acceptAllEffects = TRUE,
                           modelName = "model_VPC",
                           workingDir = tempdir())

# View the model
print(finalModelVPC)
#> 
#>  Model Overview 
#>  ------------------------------------------- 
#> Model Name        :  model_VPC
#> Working Directory :  C:\Users\jcraig\AppData\Local\Temp\RtmpI3HPMy
#> Is population     :  TRUE
#> Model Type        :  PK
#> 
#>  PK 
#>  ------------------------------------------- 
#> Parameterization  :  Clearance
#> Absorption        :  FirstOrder
#> Num Compartments  :  1
#> Dose Tlag?        :  FALSE
#> Elimination Comp ?:  FALSE
#> Infusion Allowed ?:  FALSE
#> Sequential        :  FALSE
#> Freeze PK         :  FALSE
#> 
#>  PML 
#>  ------------------------------------------- 
#> test(){
#>     cfMicro(A1,Cl/V, first = (Aa = Ka))
#>     dosepoint(Aa)
#>     C = A1 / V
#>     error(CEps=628.509289505977)
#>     observe(CObs=C * ( 1 + CEps))
#>     stparm(Ka = tvKa * exp(nKa))
#>     stparm(V = tvV * exp(nV))
#>     stparm(Cl = tvCl * exp(nCl))
#>     fixef( tvKa = c(,1.14998472307097,))
#>     fixef( tvV = c(,0.693723326857944,))
#>     fixef( tvCl = c(,2.07466660878669,))
#>     ranef(diag(nKa,nV,nCl) = c(1.12055347272733,1.86975623088902,1.48746566512628))
#> 
#> }
#> 
#>  Structural Parameters 
#>  ------------------------------------------- 
#>  Ka V Cl
#>  ------------------------------------------- 
#> Observations:
#> Observation Name :  CObs
#> Effect Name      :  C
#> Epsilon Name     :  CEps
#> Epsilon Type     :  Multiplicative
#> Epsilon frozen   :  FALSE
#> is BQL           :  FALSE
#>  ------------------------------------------- 
#>  Column Mappings 
#>  ------------------------------------------- 
#> Model Variable Name : Data Column name
#> id                  : Subject
#> time                : Act_Time
#> Aa                  : Amount
#> CObs                : Conc
#> 

# Set up VPC arguments to have PRED outputted to simulation output dataset "predout.csv"
vpcSetup <- NlmeVpcParams(outputPRED = TRUE)

# Run VPC using the default host, default values for the relevant NLME engine arguments
finalVPCJob <- vpcmodel(model = finalModelVPC, vpcParams = vpcSetup, hostPlatform = host)
#> Using localhost without parallelization.
#> 
#> NLME Job
#> 
#> Compiling 1 of 1 NLME models
#> TDL5 version: 25.7.1.1
#> 
#> Status: OK
#> License expires: 2026-08-06
#> Refresh until: 2025-09-05 07:01:25
#> Current Date: 2025-08-06
#> The model compiled
#> 
#> Trying to generate job results...
#> 
#> Copying tables predcheck0.csv, predcheck0_cat.csv, predcheck1.csv, predcheck1_cat.csv, predcheck1_npd.csv, predcheck2.csv, predcheck2_cat.csv, predcheck2_npd.csv, predcheck_bql.csv, predout.csv
#> 
#> Finished summarizing results. Transferring data and loading the results...
#> Done generating job results.
#> 
#> VPC/Simulation results are ready in C:/Users/jcraig/AppData/Local/Temp/RtmpI3HPMy
#> Loading the results
#> Loading predcheck_bql.csv
#> Loading predcheck0.csv
#> Loading predcheck0_cat.csv
#> Loading predcheck1.csv
#> Loading predcheck1_cat.csv
#> Loading predcheck2.csv
#> Loading predcheck2_cat.csv
#> Loading predout.csv
# the same as:
# finalVPCJob <- vpcmodel(model = finalModelVPC, outputPRED = TRUE)

# Observed dataset predcheck0.csv
dt_ObsData <- finalVPCJob$predcheck0

# Simulation output dataset predout.csv
dt_SimData <- finalVPCJob$predout

# Add PRED from REPLICATE = 0 of simulation output dataset to observed input dataset
dt_ObsData$PRED <- dt_SimData[REPLICATE == 0]$PRED

# tidyvpc package VPC example:
# library(tidyvpc)
# library(magrittr)
# Create a regular VPC plot with binning method set to be "jenks"
# binned_VPC <- observed(dt_ObsData, x = IVAR, yobs = DV) %>%
# simulated(dt_SimData, ysim = DV) %>%
# binning(bin = "jenks") %>%
# vpcstats()

# plot_binned_VPC <- plot(binned_VPC)

# Create a pcVPC plot with binning method set to be "jenks"
# binned_pcVPC <- observed(dt_ObsData, x = IVAR, yobs = DV) %>%
#   simulated(dt_SimData, ysim = DV) %>%
#   binning(bin = "jenks") %>%
#   predcorrect(pred = PRED) %>%
#   vpcstats()

# plot_binned_pcVPC <- plot(binned_pcVPC)
# }