Learn R Programming

RsNLME

Overview

R Speaks Non Linear Mixed Effects Modeling, RsNLME, is a suite of R packages and supplementary Shiny apps developed by Certara that supports pharmacometric modeling inside R.

When used together, these packages can add a level of speed and flexibility to your pharmacometrics workflow that cannot be achieved with point-and-click type tools.

Whether you're still learning R or a seasoned expert, efficiently build, execute, and analyze your models from the Shiny GUI, then generate the corresponding R code to reproduce and expand your workflow from the R command line.

Usage

Certara.RsNLME uses tidyverse syntax to generate and update pharmacometric models in R. All functions can easily be chained together using the %>% operator from magrittr. See RsNLME Examples.

library(Certara.RsNLME)
library(magrittr)


# Create two-compartment pharmacokinetic model
model <- pkmodel(numCompartments = 2, data = pkData, 
                ID = "Subject", Time = "Act_Time", A1 = "Amount", CObs = "Conc",
                modelName = "TwCpt_IVBolus_FOCE_ELS") 
                

# Update initial estimates              
model <- model %>%
          fixedEffect(effect = c("tvV", "tvCl", "tvV2", "tvCl2"), value = c(15, 5, 40, 15)) 

Model Builder

If you are still learning the command line syntax, use the Certara.RsNLME.ModelBuilder Shiny application from either RStudio or Pirana to build your NLME model from the GUI and generate the corresponding R and PML code to reproduce your model across multiple environments.

library(Certara.RsNLME)
library(Certara.RsNLME.ModelBuilder)

model <- modelBuilderUI(data = pkData)

Learn more about Certara.RsNLME.ModelBuilder here

Fit model

Next, we can execute the above model we created from the Shiny GUI inside R using the command fitmodel():

job <- fitmodel(model)

print(job$Overall)
   Scenario RetCode    LogLik     -2LL      AIC      BIC nParm nObs nSub EpsShrinkage Condition
1: WorkFlow       1 -632.7953 1265.591 1283.591 1308.057     9  112   16      0.17297   3.34287

Model Executor

Or alternatively, use the Certara.RsNLME.ModelExecutor Shiny application to specify additional engine arguments, change the estimation algorithm, add output tables, and more - all from the Shiny GUI!

library(Certara.RsNLME.ModelExecutor)

modelExecutorUI(model)

Learn more about Certara.RsNLME.ModelExecutor here

Xpose NLME

After executing the model, we use the Certara.Xpose.NLME, xpose, ggplot2, and flextable packages to generate our model diagnostic plots.

library(Certara.Xpose.NLME)
library(xpose)
library(ggplot2)

xpdb <- xposeNlmeModel(model, job)

res_vs_idv(xpdb) + 
   theme_classic()

Learn more about Certara.Xpose.NLME here

Model Results

Or alternatively, use the Certara.ModelResults Shiny application to easily preview, customize, and report model diagnostics plots and tables from the Shiny GUI. Furthermore, the application will generate the corresponding .R and .Rmd code to reproduce your model diagnostics.

library(Certara.ModelResults)

resultsUI(model)

Learn more about Certara.ModelResults here

Fit VPC model

Lastly, users can execute a vpcmodel() to generate a Visual Predictive Check (VPC) plot and assess model fit.

Using the Certara.RsNLME package, we will execute the function vpcmodel() to return our observed and simulated data used to generate our VPC.

library(Certara.RsNLME)

vpcJob <- vpcmodel(model)

Next we'll extract our observed and simulated data from the return value of vpcmodel().

obs_data <- vpcJob$predcheck0

sim_data <- vpcJob$predout

tidyvpc

Then we can use the tidyvpc package to parameterize our VPC.

library(tidyvpc)

 vpc <- observed(obs_data, y = DV, x = IVAR) %>%
      simulated(sim_data, y = DV) %>%
      binless() %>%
      vpcstats()

Learn more about tidyvpc here

VPC Results

Or alternatively, use the Certara.VPCResults Shiny application to easily parameterize, customize, and report VPC plots from the Shiny GUI. Furthermore, the application will generate the corresponding .R and .Rmd code to reproduce your VPC's in R.

vpcResultsUI(obs_data, sim_data)

Learn more about Certara.VPCResults here

Copy Link

Version

Install

install.packages('Certara.RsNLME')

Monthly Downloads

535

Version

3.1.0.1

License

LGPL-3

Maintainer

James Craig

Last Published

September 3rd, 2025

Functions in Certara.RsNLME (3.1.0.1)

NlmeErrorModel-class

Class represents an NLME/PML error model
NlmePkParameters-class

Class represents an NLME/PML PK model parameters
NlmeIndirectParameters-class

Class represents an NLME/PML Indirect PD model parameters
NlmeParamsMapping-class

Class represents mapping list between model variables and data columns
NlmeParallelMethod-class

Class initializer for NlmeParallelMethod
NlmePmlModel-class

Class initializaer for NlmePmlModel object
NlmeJobStatus

Reads progress file and returns the status of a job
NlmeEngineExtraParams-class

NlmeEngineExtraParams : Defines all engine parameters for NLME models Wrapped up by engineParams function.
ResetColumnInfo-class

Class initializer for ResetColumnInfo
NlmeRemoteExecutor-class

Class initializer for NlmeRemoteExecutor
NlmeSimTableDef-class

Class initializer for NlmeSimTableDef
NlmeResidualEffect-class

Class represents an NLME/PML residual error model
addADDL

Adds ADDL extra column definition to model object
NlmeParallelHost-class

NlmeParallelHost Class
addExtraDef

Adds user defined extra column/table definitions to column definition file
cancelJob

Generic function for cancelling a job
addInfusion

Change existing dosing compartment to infusion
NlmeScenario-class

Class initializer for NlmeScenario
acceptAllEffects

Accepts all estimates for fixed effects, Sigma, and random effects
bootstrap

Executes an NLME Bootstrap
RunProfilePertubation

Execute an NLME profile perturbation
NlmeTableDef-class

Class initializer for NlmeTableDef
NlmeUserAuthentication-class

Class initializer for NlmeUserAuthentication
NlmeVpcParams-class

Arguments for VPC runs
addReset

Adds reset instructions to the model
StepwiseParams-class

Class initializer for NLME StepwiseParams
SortColumns-class

Class initializer for SortColumns
createModelInfo

Parse the model and get the list of terms
emaxmodel_MappingParameters

Emax model mapping parameters
engineParams

Main function to specify engine parameters
addSecondary

Adds a secondary parameter to model definition
colMapping

Add column mappings
extraDoseLines

Return extra dose lines
NlmeSimulationParams-class

Class initializer for NlmeSimulationParams
covariatePartsString

Creates string from each covariate attribute
fixedEffect

Specifies the initial values, lower bounds, upper bounds, and units for fixed effects in a model
extraDoseNames

Return extra dose names
addCovariate

Add covariate to model object
getRandomEffectNames

Return random effect names in model
checkHostParams

Check Host Parameters
generatePML

Generates PML statements based on the current model
NlmeStrucParamStyle

Class represents style of structural parameter
addDoseCycle

Adds a dosing cycle to model
OneCpt_IVInfusionData

Pharmacokinetic dataset containing 100 subjects with single dose given by infusion
create_model_from_metamodel

Use to create model object from parsed metamodel
emaxmodel

Create an Emax or Imax model
linearmodel

Create linear model
editModel

Directly edit PML text in model object
ProfileParameters-class

Class initializer for ProfileParameters
copyModel

Copy model object to iterate over base model
addSteadyState

Adds Steady State extra column definition to model object
addToErrorModel

Add to the NLME Error model
doseNames

Return dose names
deleteSecondary

Deletes a secondary parameter from the model
covariateEffect<-

Sets style for a covariate/variable
parse_NLMEHosts

Create NlmeParallelHost object from json file with host definition
linearmodel_MappingParameters

Linear model mapping parameters
pkData

Pharmacokinetic dataset containing 16 subjects with single bolus dose
getThetas

Return theta names and values
pkcovbqlData

Pharmacokinetic pediatric dataset containing 80 subjects with single bolus dose.
pklinearmodel

Create PK linear model
pkmodel

Creates a PK model
pkpdData

Pharmacokinetic/Pharmacodynamic dataset containing 200 subjects with single bolus dose
pkmodel_MappingParameters

PK model mapping parameters
dataMapping

Initialize input data for PK/PD model
fitmodel

Executes an NLME simple estimation
obtain_NLMELicense

Obtain NLME License
extract_mmdl

extract files used for powershell script
modelVariableNames

Return model variable names
addLabel

Add levels and labels to categorical or occasion covariate
parsePMLColMap

Embed column definition info into the model
ProfileVar-class

NLME Profile variable
addMDV

Adds MDV extra column definition to model object
covariateNames

Return covariate names
covariateModel

Creates set of covariate effects
remove_NLMELicense

Remove NLME License
residualEffectNames

Return residual effect terms available in model
residualError

Assign residual error model to model object
hostParams

Create an NLME Parallel Host Configuration
listCovariateEffectNames

Lists covariate effect names in the model
initFixedEffects

Display/Set initial estimates for fixed effects
print.NlmePmlModel

Print generic for class NlmePmlModel
residualEffect<-

Sets residual effect attributes
tableParams

Wrapper around NlmeTableDef/NlmeSimTableDef-classes initializers.
loadModel

Load model.rda file
pkindirectmodel

Create a PK/Indirect response model
observationNames

Get observation names
removeCovariate

Remove covariate from structural parameters in a model object.
randomEffect

Sets or updates the covariance matrix of random effects
pkindirectmodel_MappingParameters

PK Indirect model mapping parameters
textualmodel

Create a textual model object
saveUpdatedMetamodel

workhorse for change_ThetasMmdlin RsNLME.ModelBuilder
sortfit

Executes an NLME simple estimation with sort keys and given scenarios
vpcmodel

Perform visual predictive check for NLME models
stepwiseSearch

Executes an NLME stepwise covariate search
writeDefaultFiles

Writes out data/column mapping and engine parameter files for the engine
pkemaxmodel

Create a PK/Emax or PK/Imax model
print.NlmeEngineExtraParams

Print generic for class NlmeEngineExtraParams
secondaryParameterNames

Get secondary parameter names
run_metamodel

Fit the NLME metamodel
structuralParameter

Set structural parameter in model object
structuralParameterNames

Get structural parameter names
simmodel

Executes an NLME simulation
shotgunSearch

Executes an NLME shotgun covariate search
saveModel

Save model object to .rda file
profilePertubate

Executes an NLME profile perturbation
randomBlockStatement

Returns random block statement
print.SimpleNlmeJob

Print generic for class Simple.NlmeJob
print.NlmeParallelHost

Print an NlmeParallelHost Object
BootstrapParams-class

Represents parameters for a bootstrap run
NlmeColumnMapping-class

Class represents mapping list between model variables and dataset columns
ExtraDoseItem-class

Defines an extra dose point
NlmeDataset-class

NLME dataset object
CovariateEffectModel-class

NLME covariate effects model object class
ExtraDoseDataType-class

Creates an extra dose parameter
NlmeDoseMapping-class

Class represents mapping list between model variables and dose columns
NlmeColumnMap-class

Class represents map between a model variable and a dataset column
NlmeCovariateParameter-class

NlmeCovariateParameter
NlmeCovarItem-class

Class represents an NLME Covariate parameter
NlmeObservationVar-class

Class initializer for NlmeObservationVar-class
NlmeEmaxParameters-class

Class represents an NLME/PML Emax model parameters
NlmeEngineExtraParams

Create a new NlmeEngineExtraParams object