Home PK intro R NONMEM Calculators Data checker

Basics

‹ Back
VPC Bootstrap SCM

Pirana/PsN

Working with Pirana and PsN


Create a VPC in Pirana
Select a model, open the menu (right mouse click) and go to 'PsN' -> 'Model Diagnotics' -> 'VPC'.



vpc -samples=1000  -bin_by_count=0 -bin_array=2,4,6,8 -idv=TAD -predcorr run001.mod -directory=vpc001


Bootstrap
Select a model, open the menu (right click), go to 'PsN' -> 'Model diagnostics' -> 'Bootstrap'.

bootstrap -samples=1000 -threads=7 -dir=bs_001 001.mod


Stepwise Covariate Model-building (SCM)
To run a SCM the best way is to create a config file. This can be used for multiple models (with some minor tweaking)
For functionality and options refer to the scm guide or -help function. Note that the confif file has to be stored as .scm file.
See: PsN documentation

; In the model parameters should be defined as typical values, e.g.: 
; TVCL = THETA(2) 
; CL = TVCL*EXP(ETA(1))

model=008.mod
directory=scm_dir1
search_direction=both
p_forward=0.1
p_backward=0.05
continuous_covariates=WT,AGE,HT,BMI,BSA
categorical_covariates=GNDR,CYP1,CYP2

missing_data_token=-99
linearize=0
nm_version=default
retries=1
threads=6
tweak_inits=1
picky=0

[test_relations]
CL=WT,AGE,HT,BMI,BSA,GNDR,CYP1,CYP2
V=WT,AGE,HT,BMI,BSA,GNDR,CYP1,CYP2

[valid_states]
continuous=1,2,3
categorical=1,2
The numbers in the valid_states refer to the way the covariates are tested (linear, exponential, power, etc)
Select a model, open the menu (right click) and go to 'PsN' -> 'Covariates' -> 'SCM'.
scm -config_file=scm6.scm -model=011.mod -dir=scm6
Refer to the config file. Most of the settings in the config file can also be specified here with the run.


R scripts for pirana

R-scripts can be added to pirana by putting the R file in the pirana 'scripts' directory.
This directory can be found in the pirana installation location. This folder also contains a template.
Pirana exports a file with a lot of information concerning the selected model. This can be loaded in R and used in many ways.

The scripts can be run by selecting and double clicking the script (or right click for more options)
Scripts can be opened within R by selecting model, right click script and select 'Open script in R':

Pirana scripts
Basic DV versus TIME plot
# Below an example of an R script which can be run from pirana to plot the DV and TIME from the SDTAB table produced by nonmem. 
# It saves the plot in a pdf and opens the file from its location. Hence it can all be done without manually having to use R.
# Note that it makes use of the info sent by pirana ('#PIRANA_IN'). 
# Table naming in nonmem can be arbitrary, preferably use conventional naming. 
library(tidyverse) library(wrapr) models <- #PIRANA_IN model_names <- names(models) model_1 <- models[[model_names[1]]] for(i in 1:length(model_1$tables)){ if(startsWith(model_1$tables[i],'SD')){ SDTAB <- model_1$tables[i] SDTAB <- read.table (SDTAB, skip=1, header=T) } else if (startsWith(model_1$tables[i],'PA')){ PATAB <- model_1$tables[i] PATAB <- read.table (PATAB, skip=1, header=T) } else if (startsWith(model_1$tables[i],'CO')){ COTAB <- model_1$tables[i] COTAB <- read.table (COTAB, skip=1, header=T) } else{ print('Not a table starting with SD, PA or CO') } } ##### Start rest of script with loaded data SDTAB %>% filter(DV > 0) %.>% plot(.$DV~.$TIME) ## Create output file if (!file.exists("pirana_temp")) {dir.create ("pirana_temp")} filename <- "pirana_temp/test.pdf" pdf (file = filename) plot (x=tab$TIME, tab$DV, main=model_1$descr); dev.off() ## open created file cat (paste("OUTPUT: ", fname, sep="")) if (file.exists(filename) && open_res) { if (Sys.info()['sysname'] == 'Windows') { shell.exec(paste(getwd(),"/",filename,sep="")) } # windows else if (Sys.info()['sysname'] == 'Darwin') { system(paste ("open ",filename, sep="")) } # mac else { system(paste("xdg-open ", fname, sep=""), ignore.stdout=TRUE, ignore.stderr=TRUE, wait=FALSE) } # linux } quit()
VPC plot

library(xpose4)

models <- #PIRANA_IN
model_names <- names(models)
model_1     <- models[[model_names[1]]]


### VPC ###
vpcnam <- paste('/vpc_',model_names, sep='')
vpcdir <- getwd()
vpcdir <- paste(vpcdir, vpcnam, sep='')
setwd(vpcdir)

vpc <- xpose.VPC(vpc.info = "vpc_results.csv", vpctab = "vpctab", 
          main = list("Visual Predictive Check"), PI.ci = "area", PI.real= T, type ="p")

### Create output file ###
fname <- paste(names(models)[1],"_VPC.pdf", sep="")

pdf (file = fname)
print(vpc)
dev.off()

### Open created file ###
cat (paste("OUTPUT: ", fname, sep=""))
if (file.exists(fname) && open_res) {
  if (Sys.info()['sysname'] == 'Windows') {
    shell.exec(paste(getwd(),"/",fname,sep=""))
  }  # windows
  else if (Sys.info()['sysname'] == 'Darwin'){
    system(paste ("open ",fname, sep="")) 
  } # mac
  else {
    system(paste("xdg-open ", fname, sep=""), ignore.stdout=TRUE, ignore.stderr=TRUE, wait=FALSE) 
  } # linux
}

quit()