Title: | Enhances 'xpose' Diagnostics for Pharmacometric Models from 'Certara.RsNLME' and Phoenix NLME |
---|---|
Description: | Facilitates the creation of 'xpose' data objects from Nonlinear Mixed Effects (NLME) model outputs produced by 'Certara.RsNLME' or Phoenix NLME. This integration enables users to utilize all 'ggplot2'-based plotting functions available in 'xpose' for thorough model diagnostics and data visualization. Additionally, the package introduces specialized plotting functions tailored for covariate model evaluation, extending the analytical capabilities beyond those offered by 'xpose' alone. |
Authors: | James Craig [aut, cre], Michael Tomashevskiy [aut], Soltanshahi Fred [aut], Shuhua Hu [ctb], Certara USA, Inc [cph, fnd] |
Maintainer: | James Craig <[email protected]> |
License: | LGPL-3 |
Version: | 2.0.2 |
Built: | 2025-01-29 05:40:23 UTC |
Source: | https://github.com/cran/Certara.Xpose.NLME |
Plot ETAs against a continuous or categorical covariate.
eta_vs_cov( xpdb, covariate, mapping = NULL, drop_fixed = FALSE, group = "ID", type = "bpls", title = "ETAs vs @x | @run", subtitle = "Based on @nind individuals", caption = "@dir", tag = NULL, log = NULL, guide = FALSE, onlyfirst = TRUE, facets, .problem, quiet, ... )
eta_vs_cov( xpdb, covariate, mapping = NULL, drop_fixed = FALSE, group = "ID", type = "bpls", title = "ETAs vs @x | @run", subtitle = "Based on @nind individuals", caption = "@dir", tag = NULL, log = NULL, guide = FALSE, onlyfirst = TRUE, facets, .problem, quiet, ... )
xpdb |
An xpose database object. |
covariate |
Character; String of covariate name |
mapping |
List of aesthetics mappings to be used for the xpose plot
(e.g. |
drop_fixed |
Logical; Logic specifying whether ETAs having same value for the given covariate value should be removed from plotting |
group |
Grouping variable to be used for lines. |
type |
Character; String setting the type of plot to be used. Must be 'b' for categorical covariates, one or a combination of 'p','l','s' for continuous covariates. |
title |
Character; Plot title. Use |
subtitle |
Character; Plot subtitle. Use |
caption |
Character; Page caption. Use |
tag |
Character; Plot identification tag. Use |
log |
Character; String assigning logarithmic scale to axes, can be either ”, 'x', y' or 'xy'. |
guide |
Logical; Should the guide (e.g. reference distribution) be displayed. |
onlyfirst |
Logical; Should the data be filtered to retain first value for each group/facet. |
facets |
Either a character string to use |
.problem |
The $problem number to be used. By default returns the last estimation problem. |
quiet |
Logical, if |
... |
Any additional aesthetics to be passed on |
An object of class xpose_plot
, ggplot
, and gg
. This object represents a customized plot created using ggplot2
.
The xpose_plot
class provides additional metadata and integration with xpose
workflows, allowing for advanced
customization and compatibility with other xpose
functions. Users can interact with the plot object as they
would with any ggplot2
object, including modifying aesthetics, adding layers, or saving the plot.
Plots can be customized by mapping arguments to specific layers. The naming convention is layer_option where layer is one of the names defined in the list below and option is any option supported by this layer e.g. boxplot_fill = 'blue', etc.
box plot: options to geom_boxplot
point plot: options to geom_point
line plot: options to geom_line
smooth plot: options to geom_smooth
xscale: options to scale_x_continuous
or scale_x_log10
yscale: options to scale_y_continuous
or scale_y_log10
eta_vs_cov(xpose::xpdb_ex_pk, covariate = "WT", type = "ps", smooth_color = "red", point_color = "green", point_shape = "square", point_alpha = .5, point_size = 3 ) eta_vs_cov(xpose::xpdb_ex_pk, covariate = "AGE", type = "ps", facets = DOSE ~ variable, guide = TRUE, guide_color = "red", guide_slope = 0, guide_intercept = 0 )
eta_vs_cov(xpose::xpdb_ex_pk, covariate = "WT", type = "ps", smooth_color = "red", point_color = "green", point_shape = "square", point_alpha = .5, point_size = 3 ) eta_vs_cov(xpose::xpdb_ex_pk, covariate = "AGE", type = "ps", facets = DOSE ~ variable, guide = TRUE, guide_color = "red", guide_slope = 0, guide_intercept = 0 )
Access model fit diagnostics from an xpdb object generated by xposeNlme.
get_overallNlme(xpdb, .problem = 1, .subprob = 0, .method = NULL)
get_overallNlme(xpdb, .problem = 1, .subprob = 0, .method = NULL)
xpdb |
An |
.problem |
The problem to be used. |
.subprob |
The subproblem to be used. |
.method |
The estimation method to be used. |
A tibble for single problem/subproblem.
# Store the parameter table prmOverall <- get_overallNlme(xpdb_ex_Nlme)
# Store the parameter table prmOverall <- get_overallNlme(xpdb_ex_Nlme)
Access model parameter estimates from an xpdb object generated by xposeNlme.
get_prmNlme( xpdb, .problem = 1, .subprob = 0, .method = NULL, digits = 6, show_all = FALSE, level = 0.95 )
get_prmNlme( xpdb, .problem = 1, .subprob = 0, .method = NULL, digits = 6, show_all = FALSE, level = 0.95 )
xpdb |
An |
.problem |
The problem to be used. |
.subprob |
The subproblem to be used. |
.method |
The estimation method to be used. |
digits |
Integer specifying the number of significant digits to be displayed. |
show_all |
Logical specifying whether the 0 off-diagonal omega elements should be removed from the output or not. |
level |
Numeric specifying confidence level to compute confidence intervals, which are calculated based on Student’s t distribution. |
A tibble for single problem/subproblem.
# Store the parameter table prm <- get_prmNlme(xpdb_ex_Nlme) # Set the desired number of significant digits to display results # Note: To have results displayed in the number of significant digits # specified in the digits argument, one needs to make sure that # the value of pillar.sigfig option (default value is 3) is greater # than or equal to this specified value. options(pillar.sigfig = 6) get_prmNlme(xpdb_ex_Nlme, digits = 4)
# Store the parameter table prm <- get_prmNlme(xpdb_ex_Nlme) # Set the desired number of significant digits to display results # Note: To have results displayed in the number of significant digits # specified in the digits argument, one needs to make sure that # the value of pillar.sigfig option (default value is 3) is greater # than or equal to this specified value. options(pillar.sigfig = 6) get_prmNlme(xpdb_ex_Nlme, digits = 4)
Use to create covariates scatterplot.
nlme.cov.splom( xpdb, covColNames, ggupper = list(continuous = "cor", combo = "box_no_facet", discrete = "count", na = "na"), gglower = list(continuous = GGally::wrap("smooth", alpha = 0.3, size = 0.1), combo = "facethist", discrete = "facetbar", na = "na"), ggdiag = list(continuous = "densityDiag", discrete = "barDiag", na = "naDiag"), ... )
nlme.cov.splom( xpdb, covColNames, ggupper = list(continuous = "cor", combo = "box_no_facet", discrete = "count", na = "na"), gglower = list(continuous = GGally::wrap("smooth", alpha = 0.3, size = 0.1), combo = "facethist", discrete = "facetbar", na = "na"), ggdiag = list(continuous = "densityDiag", discrete = "barDiag", na = "naDiag"), ... )
xpdb |
An xpose database object. |
covColNames |
Character vector of covariates to build the matrix |
ggupper |
See |
gglower |
See |
ggdiag |
See |
... |
Parameters to be passed to |
ggmatrix
object.
nlme.cov.splom(xpdb = xpdb_ex_Nlme, covColNames = c("sex", "wt", "age") )
nlme.cov.splom(xpdb = xpdb_ex_Nlme, covColNames = c("sex", "wt", "age") )
Use to create a stack of plots of parameter estimates plotted against covariates.
nlme.par.vs.cov(xpdb, covColNames, nrow = 1, ncol = 1, ...)
nlme.par.vs.cov(xpdb, covColNames, nrow = 1, ncol = 1, ...)
xpdb |
An xpose database object. |
covColNames |
Character vector of covariates to build the matrix. |
nrow |
Number of rows. |
ncol |
Number of columns; if ncol=1, each gtable object is treated separately. |
... |
Parameters to be passed to |
List of gtable
nlme.par.vs.cov( xpdb = xpdb_ex_Nlme, covColNames = c("sex", "wt", "age") )
nlme.par.vs.cov( xpdb = xpdb_ex_Nlme, covColNames = c("sex", "wt", "age") )
Use to create a stack of plots of random parameter estimates plotted against covariates.
nlme.ranpar.vs.cov(xpdb, covColNames, nrow = 1, ncol = 1, ...)
nlme.ranpar.vs.cov(xpdb, covColNames, nrow = 1, ncol = 1, ...)
xpdb |
An xpose database object. |
covColNames |
Character vector of covariates to build the matrix. |
nrow |
Number of rows. |
ncol |
Number of columns; if ncol=1, each gtable object is treated separately. |
... |
Parameters to be passed to |
List of gtable
nlme.ranpar.vs.cov(xpdb = xpose::xpdb_ex_pk, covColNames = c("SEX", "CLCR", "AGE") )
nlme.ranpar.vs.cov(xpdb = xpose::xpdb_ex_pk, covColNames = c("SEX", "CLCR", "AGE") )
The type of plot depends on the type of covariate: boxplot for categorical, geom_point and geom_smooth for continuous.
nlme.var.vs.cov(xpdb, covColNames, nrow = 1, ncol = 1, yVar = "WRES", ...)
nlme.var.vs.cov(xpdb, covColNames, nrow = 1, ncol = 1, yVar = "WRES", ...)
xpdb |
An xpose database object. |
covColNames |
Character vector of covariates to build the matrix. |
nrow |
Number of rows. |
ncol |
Number of columns; if ncol=1, each gtable object is treated separately. |
yVar |
Variable from xpdb data to build a plot. |
... |
Parameters to be passed to |
List of gtable
nlme.var.vs.cov( xpdb = xpdb_ex_Nlme, covColNames = c("sex", "wt", "age"), yVar = "WRES", nrow = 2, ncol = 2 )
nlme.var.vs.cov( xpdb = xpdb_ex_Nlme, covColNames = c("sex", "wt", "age"), yVar = "WRES", nrow = 2, ncol = 2 )
Plot Parameters against a continuous or categorical covariate.
prm_vs_cov( xpdb, covariate, mapping = NULL, drop_fixed = FALSE, group = "ID", type = "bpls", title = "Parameters vs @x | @run", subtitle = "Based on @nind individuals", caption = "@dir", tag = NULL, log = NULL, guide = FALSE, onlyfirst = FALSE, facets, .problem, quiet, ... )
prm_vs_cov( xpdb, covariate, mapping = NULL, drop_fixed = FALSE, group = "ID", type = "bpls", title = "Parameters vs @x | @run", subtitle = "Based on @nind individuals", caption = "@dir", tag = NULL, log = NULL, guide = FALSE, onlyfirst = FALSE, facets, .problem, quiet, ... )
xpdb |
An xpose database object. |
covariate |
Character; String of covariate name |
mapping |
List of aesthetics mappings to be used for the xpose plot
(e.g. |
drop_fixed |
Logical; logic specifying whether structural parameters having same value for the given covariate value should be removed from plotting |
group |
Grouping variable to be used for lines. |
type |
Character; String setting the type of plot to be used. Must be 'b' for categorical covariates, one or a combination of 'p','l','s' for continuous covariates. |
title |
Character; Plot title. Use |
subtitle |
Character; Plot subtitle. Use |
caption |
Character; Page caption. Use |
tag |
Character; Plot identification tag. Use |
log |
Character; String assigning logarithmic scale to axes, can be either ”, 'x', y' or 'xy'. |
guide |
Logical; Enable guide display (e.g. unity line). |
onlyfirst |
Logical; Should the data be filtered to retain first value for each group/facet. |
facets |
Either a character string to use |
.problem |
The $problem number to be used. By default returns the last estimation problem. |
quiet |
Logical, if |
... |
Any additional aesthetics to be passed on |
An object of class xpose_plot
, ggplot
, and gg
. This object represents a customized plot created using ggplot2
.
The xpose_plot
class provides additional metadata and integration with xpose
workflows, allowing for advanced
customization and compatibility with other xpose
functions. Users can interact with the plot object as they
would with any ggplot2
object, including modifying aesthetics, adding layers, or saving the plot.
Plots can be customized by mapping arguments to specific layers. The naming convention is layer_option where layer is one of the names defined in the list below and option is any option supported by this layer e.g. boxplot_fill = 'blue', etc.
box plot: options to geom_boxplot
point plot: options to geom_point
line plot: options to geom_line
smooth plot: options to geom_smooth
xscale: options to scale_x_continuous
or scale_x_log10
yscale: options to scale_y_continuous
or scale_y_log10
prm_vs_cov(xpose::xpdb_ex_pk, covariate = "AGE", type = "ps", log = "y", yscale_breaks = scales::trans_breaks("log10", function(x) 10^x), yscale_labels = scales::trans_format("log10", scales::math_format(10^.x)), caption = NULL ) prm_vs_cov(xpose::xpdb_ex_pk, covariate = "SEX", type = "b", boxplot_fill = "blue", boxplot_color = "black", boxplot_outlier.color = "red" )
prm_vs_cov(xpose::xpdb_ex_pk, covariate = "AGE", type = "ps", log = "y", yscale_breaks = scales::trans_breaks("log10", function(x) 10^x), yscale_labels = scales::trans_format("log10", scales::math_format(10^.x)), caption = NULL ) prm_vs_cov(xpose::xpdb_ex_pk, covariate = "SEX", type = "b", boxplot_fill = "blue", boxplot_color = "black", boxplot_outlier.color = "red" )
Plot Residuals against a continuous or categorical covariate.
res_vs_cov( xpdb, mapping = NULL, covariate, res = "CWRES", group = "ID", type = "bpls", title = "Residuals vs @x | @run", subtitle = "Based on @nind individuals", caption = "@dir", tag = NULL, log = NULL, guide = TRUE, facets, .problem, quiet, ... )
res_vs_cov( xpdb, mapping = NULL, covariate, res = "CWRES", group = "ID", type = "bpls", title = "Residuals vs @x | @run", subtitle = "Based on @nind individuals", caption = "@dir", tag = NULL, log = NULL, guide = TRUE, facets, .problem, quiet, ... )
xpdb |
An xpose database object. |
mapping |
List of aesthetics mappings to be used for the xpose plot
(e.g. |
covariate |
Character; String of covariate name |
res |
Character; String of residual name; CWRES by default. |
group |
Grouping variable to be used for lines. |
type |
Character; String setting the type of plot to be used. Must be 'b' for categorical covariates, one or a combination of 'p','l','s' for continuous covariates. |
title |
Character; Plot title. Use |
subtitle |
Character; Plot subtitle. Use |
caption |
Character; Page caption. Use |
tag |
Character; Plot identification tag. Use |
log |
Character; String assigning logarithmic scale to axes, can be either ”, 'x', y' or 'xy'. |
guide |
Logical; Should the guide (e.g. reference distribution) be displayed. |
facets |
Either a character string to use |
.problem |
The $problem number to be used. By default returns the last estimation problem. |
quiet |
Logical, if |
... |
Any additional aesthetics to be passed on |
An object of class xpose_plot
, ggplot
, and gg
. This object represents a customized plot created using ggplot2
.
The xpose_plot
class provides additional metadata and integration with xpose
workflows, allowing for advanced
customization and compatibility with other xpose
functions. Users can interact with the plot object as they
would with any ggplot2
object, including modifying aesthetics, adding layers, or saving the plot.
Plots can be customized by mapping arguments to specific layers. The naming convention is
layer_option where layer is one of the names defined in the list below and option is
any option supported by this layer e.g. boxplot_fill = 'blue'
, etc.
box plot: options to geom_boxplot
point plot: options to geom_point
line plot: options to geom_line
smooth plot: options to geom_smooth
xscale: options to scale_x_continuous
or scale_x_log10
yscale: options to scale_y_continuous
or scale_y_log10
res_vs_cov(xpose::xpdb_ex_pk, covariate = "SEX", type = "b", res = "WRES" ) res_vs_cov(xpose::xpdb_ex_pk, covariate = "AGE", type = "ps", res = c("CWRES", "WRES", "IRES", "IWRES") )
res_vs_cov(xpose::xpdb_ex_pk, covariate = "SEX", type = "b", res = "WRES" ) res_vs_cov(xpose::xpdb_ex_pk, covariate = "AGE", type = "ps", res = c("CWRES", "WRES", "IRES", "IWRES") )
One compartment NLME model with 3 covariates
xpose_data
example built from simulated values.
An xpose::xpose_data
object
print(xpdb_ex_Nlme)
print(xpdb_ex_Nlme)
Manually generate categorical covariate box plots against eta.
xplot_box( xpdb, mapping = NULL, type = "b", guide = FALSE, yscale = "continuous", title = NULL, subtitle = NULL, caption = NULL, tag = NULL, plot_name = "box_plot", gg_theme, xp_theme, opt, quiet, ... )
xplot_box( xpdb, mapping = NULL, type = "b", guide = FALSE, yscale = "continuous", title = NULL, subtitle = NULL, caption = NULL, tag = NULL, plot_name = "box_plot", gg_theme, xp_theme, opt, quiet, ... )
xpdb |
An xpose database object. |
mapping |
List of aesthetics mappings to be used for the xpose plot
(e.g. |
type |
String setting the type of plot to be used. Only 'b' applicable. |
guide |
Enable guide display (e.g. unity line). |
yscale |
Scale type for y axis (e.g. 'continuous', 'discrete', 'log10'). |
title |
Plot title. Use |
subtitle |
Plot subtitle. Use |
caption |
Page caption. Use |
tag |
Plot identification tag. Use |
plot_name |
Name to be used by |
gg_theme |
A complete ggplot2 theme object (e.g.
|
xp_theme |
A complete xpose theme object (e.g.
|
opt |
A list of options in order to create appropriate data input for
ggplot2. For more information see |
quiet |
Logical, if |
... |
Any additional aesthetics to be passed on |
An object of class xpose_plot
, ggplot
, and gg
. This object represents a customized plot created using ggplot2
.
The xpose_plot
class provides additional metadata and integration with xpose
workflows, allowing for advanced
customization and compatibility with other xpose
functions. Users can interact with the plot object as they
would with any ggplot2
object, including modifying aesthetics, adding layers, or saving the plot.
Every xpose plot function has built-in faceting functionalities. Faceting arguments
are passed to the functions facet_wrap_paginate
when the facets
argument is a character string (e.g. facets = c('SEX', 'MED1')
) or
facet_grid_paginate
when facets is a formula (e.g. facets = SEX~MED1
).
All xpose plot functions accept all the arguments for the facet_wrap_paginate
and facet_grid_paginate
functions e.g. dv_vs_ipred(xpdb_ex_pk,
facets = SEX~MED1, ncol = 3, nrow = 3, page = 1, margins = TRUE, labeller = 'label_both')
.
Faceting options can either be defined in plot functions (e.g. dv_vs_ipred(xpdb_ex_pk,
facets = 'SEX')
) or assigned globally to an xpdb object via the xp_theme
(e.g. xpdb
<- update_themes(xpdb_ex_pk, xp_theme = list(facets = 'SEX'))
). In the latter example all plots
generate from this xpdb will automatically be stratified by 'SEX'.
By default, some plot functions use a custom stratifying variable named 'variable', e.g.
eta_distrib()
. When using the facets
argument, 'variable' needs to be added manually
e.g. facets = c('SEX', 'variable')
or facets = c('SEX', 'variable')
, but is optional,
when using the facets
argument in xp_theme
variable is automatically added whenever needed.
Plots can be customized by mapping arguments to specific layers. The naming convention is layer_option where layer is one of the names defined in the list below and option is any option supported by this layer e.g. boxplot_fill = 'blue', etc.
box plot: options to geom_boxplot
yscale: options to scale_y_continuous
or scale_y_log10
# Categorical Covariate MED1 vs ETA1 xplot_box(xpose::xpdb_ex_pk, ggplot2::aes(x = MED1, y = ETA1)) # Categorical Covariate SEX vs CL xplot_box(xpose::xpdb_ex_pk, ggplot2::aes(x = SEX, y = CL))
# Categorical Covariate MED1 vs ETA1 xplot_box(xpose::xpdb_ex_pk, ggplot2::aes(x = MED1, y = ETA1)) # Categorical Covariate SEX vs CL xplot_box(xpose::xpdb_ex_pk, ggplot2::aes(x = SEX, y = CL))
Imports results of an NLME run into xpose database
Use to import NLME model output files into xpdb
object that is compatible
with existing model diagnostic function in Xpose
package.
xposeNlme( dir = "", modelName = "", dmpFile = "dmp.txt", dmp.txt = NULL, dataFile = "data1.txt", logFile = "nlme7engine.log", ConvergenceData = NULL, progresstxt = "progress.txt" )
xposeNlme( dir = "", modelName = "", dmpFile = "dmp.txt", dmp.txt = NULL, dataFile = "data1.txt", logFile = "nlme7engine.log", ConvergenceData = NULL, progresstxt = "progress.txt" )
dir |
Path to NLME Run directory. Current working directory is used if |
modelName |
name of the model to be written in |
dmpFile |
NLME generated output file. |
dmp.txt |
NLME generated output from dmpFile (substitutes dmpFile if presented). |
dataFile |
Input file for NLME Run. |
logFile |
engine log file |
ConvergenceData |
optional data frame with Nlme convergence info. |
progresstxt |
optional NLME-generated file 'progress.txt' with convergence info.
|
Not all functionality from the xpose
package is supported.
xpdb
object
# files in arguments supposed to be in the current working directory: xp <- xposeNlme( dir = getwd(), modelName = "PMLModel", dmpFile = "dmp.txt", dataFile = "data1.txt", logFile = "nlme7engine.log", progresstxt = "progress.txt" ) # using dmp.txt structure and Convergence Data loaded previously: xp <- xposeNlme( dir = "~/Model1/", modelName = "Model1", dmp.txt = dmp.txt, dataFile = "Data.csv", logFile = "nlme7engine.log", ConvergenceData = ConvergenceData ) # explore unique covariate plots specific to Certara.Xpose.NLME: nlme.cov.splom(xp, covColNames = c("AGE", "WT")) nlme.par.vs.cov(xp, covColNames = c("AGE", "WT")) res_vs_cov(xp, covariate = "AGE", res = "IWRES") # or use existing plotting functions from the xpose package library(xpose) dv_vs_pred(xp) res_vs_idv(xp)
# files in arguments supposed to be in the current working directory: xp <- xposeNlme( dir = getwd(), modelName = "PMLModel", dmpFile = "dmp.txt", dataFile = "data1.txt", logFile = "nlme7engine.log", progresstxt = "progress.txt" ) # using dmp.txt structure and Convergence Data loaded previously: xp <- xposeNlme( dir = "~/Model1/", modelName = "Model1", dmp.txt = dmp.txt, dataFile = "Data.csv", logFile = "nlme7engine.log", ConvergenceData = ConvergenceData ) # explore unique covariate plots specific to Certara.Xpose.NLME: nlme.cov.splom(xp, covColNames = c("AGE", "WT")) nlme.par.vs.cov(xp, covColNames = c("AGE", "WT")) res_vs_cov(xp, covariate = "AGE", res = "IWRES") # or use existing plotting functions from the xpose package library(xpose) dv_vs_pred(xp) res_vs_idv(xp)
Imports results of an NLME run into xpose database
Use to import NLME model object and NLME object output
into xpdb
object that is compatible
with existing model diagnostic function in Xpose
package.
xposeNlmeModel(model, fitmodelOutput)
xposeNlmeModel(model, fitmodelOutput)
model |
NlmePmlModel model class object generated by |
fitmodelOutput |
the output object of |
Not all functionality from the xpose
package is supported.
xpdb
object
library(Certara.RsNLME) library(Certara.Xpose.NLME) model <- pkmodel( parameterization = "Clearance", numCompartments = 2, data = pkData, ID = "Subject", Time = "Act_Time", A1 = "Amount", CObs = "Conc" ) fit <- fitmodel(model) xp <- xposeNlmeModel( model = model, fitmodelOutput = fit )
library(Certara.RsNLME) library(Certara.Xpose.NLME) model <- pkmodel( parameterization = "Clearance", numCompartments = 2, data = pkData, ID = "Subject", Time = "Act_Time", A1 = "Amount", CObs = "Conc" ) fit <- fitmodel(model) xp <- xposeNlmeModel( model = model, fitmodelOutput = fit )