Learn R Programming

R Package "invivoPKfit"

invivoPKfit estimates the most likely parameter values for models describing the pharmacokinetics (PK, that is the absorption, distribution, metabolism, and elimination) of a compound given a set of in vivo concentration vs. time observations Cobs

This is achieved by creating a function that calculates probability of Cobs given a PK model M(x,t) and a statistical model S(σ)

This probability is described by a likelihood function L(Cobs, M, S)

We then use an optimizer function to optimize the values of x and σ such that L(Cobs, M(x), S(σ))

We then use the method of quadrature to estimate uncertainty in the estimates of x and σ as well as any functions of those parameters (for example, Cmax and AUC/area under the C(t) curve)

Background

Censored Data

If the observation is that the concentration was below a limit of quantitation (LOQ) we call the observation “censored” In this case we add to the likelihood all the probability from zero to the limit of quantitation We use the cumulative distribution function of the log-normal distribution for this:

$$ CDF(LOQ, \mu, \sigma) = \frac{1}{2} + \frac{1}{2} \rm{erf}\left(\frac{ln(LOQ) - \mu}{\sigma\sqrt{2}}\right) $$

We separate the observations into those above the LOQ and below the LOQ, above the LOQ we use the log-normal density, below the LOQ we use the CDF

References

Anderson, D., and K. Burnham. "Model selection and multi-model inference." Second. NY: Springer-Verlag 63.2020 (2004): 10.

Akaike, H. "Maximum likelihood identification of Gaussian autoregressive moving average models." Biometrika 60.2 (1973): 255-265.

Boxenbaum, Harold G., Sidney Riegelman, and Robert M. Elashoff. "Statistical estimations in pharmacokinetics." Journal of pharmacokinetics and biopharmaceutics 2.2 (1974): 123-148.

Charles, Sandrine, Aude Ratier, and Christelle Lopes. "Generic solving of one-compartment toxicokinetic models." bioRxiv (2021).

Colburn, Wayne A. "Controversy III: To model or not to model." The Journal of Clinical Pharmacology 28.10 (1988): 879-888.

Dovì, V. G., O. Paladino, and A. P. Reverberi. "Some remarks on the use of the inverse hessian matrix of the likelihood function in the estimation of statistical properties of parameters." Applied Mathematics Letters 4.1 (1991): 87-90.

Sayre, Risa R., John F. Wambaugh, and Christopher M. Grulke. "Database of pharmacokinetic time-series data and parameters for 144 environmental chemicals." Scientific data 7.1 (2020): 1-10.

Sheiner, Lewis B. "Analysis of pharmacokinetic data using parametric models—1: Regression models." Journal of pharmacokinetics and biopharmaceutics 12.1 (1984): 93-117.

Sheiner, Lewis B. "Analysis of pharmacokinetic data using parametric models. II. Point estimates of an individual's parameters." Journal of pharmacokinetics and biopharmaceutics 13.5 (1985): 515-540.

Sheiner, Lewis B. "Analysis of pharmacokinetic data using parametric models. III. Hypothesis tests and confidence intervals." Journal of pharmacokinetics and biopharmaceutics 14.5 (1986): 539-555.

Wambaugh, John F., et al. "Evaluating in vitro-in vivo extrapolation of toxicokinetics." Toxicological Sciences 163.1 (2018): 152-169.

Yamaoka, Kiyoshi, Terumichi Nakagawa, and Toyozo Uno. "Application of Akaike's information criterion (AIC) in the evaluation of linear pharmacokinetic equations." Journal of pharmacokinetics and biopharmaceutics 6.2 (1978): 165-175.

Getting Started

Dependencies

Installing

  • Getting Started with R Package bayesmarker from the R command line
library(devtools)
install_github("USEPA/CompTox-ExpoCast-invivoPKfit")
  • RStudio provides a menu ‘Install Packages’ under ‘Tools’ tab
  • Load the invivoPKfit data and functions
library(invivoPKfit)
  • Check what version you are using
packageVersion(invivoPKfit)

Authors

John Wambaugh [@wambaugh.john@epa.gov]

Caroline Ring [@ring.caroline@epa.gov]

Christopher Cook [@Cook.Christopher@epa.gov]

Gilberto Padilla Mercado [@padillamercado.gilberto@epa.gov]

License

License: GPL-3 https://www.gnu.org/licenses/gpl-3.0.en.html

Copy Link

Version

Install

install.packages('invivoPKfit')

Monthly Downloads

196

Version

2.0.2

License

GPL-3

Maintainer

John Wambaugh

Last Published

August 26th, 2025

Functions in invivoPKfit (2.0.2)

calc_rsq

Calculate r-squared for observed vs. predicted values
auc_1comp

Analytic AUC for 1-compartment model
calc_rmse

Calculate RMSE (root mean squared error)
calc_nca

Non-compartmental analysis
calc_sds_alerts

Calculate parameter SDs
auc_2comp

Analytical AUC for the 2-compartment model
auc_httk_gas_pbtk

Calculates AUC for `httk`'s `gas_pbtk` PBPK model
auto_units

Automatically select new time units
auc_flat

AUC for flat model
calc_hessian

Calculate Hessian
check_newdata

Check new data
check_params_flat

Check flat model parameters
check_params_1comp

Check 1-compartment model parameters
check_model

Check models
check_group_hierarchy

Checking data, error, and summary group hierarchical structure
check_method

Check methods
check_required_status.pk

Check required status
check_params_2comp

Check 2-compartment model parameters
check_required_status.default

Default method for checking required status
check_required_status

Check required status
compare_models.pk

Model comparison for [pk()] objects
coef_sd.default

Coefficient standard deviation default
compare_models

Model comparison
coef.pk

Get coefficients
conc_scale_use

Get concentration scalings
combined_sd

Combined standard deviation
coef_sd

Coefficient standard deviations
compare_models.default

Default method for compare_models()
convert_summary_to_log10

Convert sample mean and SD to log10-scale
coef_sd.pk

Get coefficient standard deviations
cp_flat

Flat model
cp_2comp

Analytical 2-compartment model
cp_2comp_dt

Time derivative of analytical 2-compartment model
cvt_2.0.0

CvTdb data for invivoPKfit 2.0.0 release (old)
cp_1comp

Analytical 1-compartment model
convert_time

Helper function to convert time units
cp_httk_gas_pbtk

Calculates plasma concentration for `httk`'s `gas_pbtk` model
cvt_date

CvTdb download date
cvtdb_original

SQL query result (current)
cvt

CvTdb data
do_data_info.pk

calculate summary data info
dlnorm_summary

Log-normal distribution density function for summary data
data_summary.default

Default method for data_summary()
do_data_info

do_data_info generic
data_summary

data_summary()
do_fit

Fitting
do_data_info.default

do_data_info default method
do_fit.default

do_fit default method
data_summary.pk

Data summary for a `pk` object
do_preprocess

Preprocess data generic
do_preprocess.pk

Do pre-processing
do_prefit

Prefitting
-.pk

Subtract a pkproto object from a pk object
eval_tkstats

eval_tkstats()
do_fit.pk

Do fitting
do_preprocess.default

do_preprocess default method
dnorm_summary

Normal distribution density function for summary data
eval_tkstats.default

Default method for eval_tkstats()
do_prefit.default

do_prefit default method
do_prefit.pk

Do pre-fitting
fill_params_2comp

Fill parameters for 2-compartment model
fill_params_flat

Fill parameters for flat model
fit_group

Fit a single group of data
fold_error.default

fold_error default method
fill_params_1comp

Fill parameters for 1-compartment model
fit_sigma.pk

Hyperparameter fitting
fold_error

Fold error
fold_error.pk

Fold errors
eval_tkstats.pk

Evaluate TK statistics
facet_data

Facet a PK fit
get_data_info.pk

Get data_info
get_data_info.default

Default method for get_data_info()
get_data_group

get_data_group()
get_data.pk

Get data
get_data.default

Default method for get_data()
get_data_original

get_data_original()
get_data_info

get_data_info()
get_data_group.pk

Get data grouping
get_data_group.default

Default method for get_data_group()
get_data

get_data()
get_data_original.default

Default method for get_data_original()
get_data_summary

get_data_summary()
get_elbow

Get an elbow point
get_data_original.pk

Get data_original
get_error_group.default

Default method for get_error_group()
get_data_sigma_group.default

Default method for get_data_sigma_group()
get_data_summary.default

Default method for get_data_summary()
get_data_sigma_group

get_data_sigma_group()
get_error_group

get_error_group()
get_data_sigma_group.pk

Get data_sigma_group
get_mapping

get_mapping()
get_error_group.pk

Get error group
get_fit

get_fit()
get_hessian.pk

Get Hessian matrixes
get_mapping.default

Default method for get_mapping()
get_mapping.pk

Get mapping
get_fit.default

Default method for get_fit()
get_fit.pk

Get fits from a `pk` object
get_hessian.default

Default method for get_hessian()
get_hessian

get_hessian()
get_params_1comp

Get parameters for 1-compartment model
get_nca_group.default

Default method for get_nca_group()
get_params_2comp

Get parameters for 2-compartment model
get_nca_group.pk

Get nca_group
get_nca.pk

Get NCA
get_nca_group

get_nca_group()
get_params_httk_gas_pbtk

Get parameters to fit `httk`'s `gas_pbtk` PBPK model
get_nca

get_nca()
get_params_flat

Get parameters to be optimized for flat model
get_nca.default

Default method for get_nca()
get_scale_conc.default

Default method for get_scale_conc()
get_scale_conc

get_scale_conc()
get_scale_time.pk

Get scale_time
get_scale_time.default

Default method for get_scale_time()
get_scale_time

get_scale_time()
get_scale_conc.pk

Get scale_conc
get_peak

Find the peak of a data series
get_prefit

get_prefit()
get_prefit.default

Default method for get_prefit()
get_prefit.pk

Get prefit
get_settings_preprocess

get_settings_preprocess()
get_starts_1comp

Get starting values for 1-compartment model
get_settings_optimx

get_settings_optimx()
get_settings_optimx.pk

Get settings_optimx
get_settings_preprocess.pk

Get settings_preprocess
get_settings_optimx.default

Default method for get_settings_optimx()
get_starts_flat

Get starting values for flat model
get_starts_2comp

Get starting values for 2-compartment model
get_starts_httk_gas_pbtk

Get starting values for httk `gas_pbtk` model with specific clearance
get_settings_preprocess.default

Default method for get_settings_preprocess()
get_status.default

Default method for getting status
get_stat_model

get_stat_model()
get_tkstats

Get TK stats
get_tkstats.default

Default method for get_tkstats()
get_status.pk

Check status of a `pk` object
get_stat_model.default

Default method for get_stat_model()
get_winning_model

get_winning_model()
get_tkstats.pk

Get TK stats
hess_sd2

Inverse diagonal, method 2
hess_sd1

Inverse diagonal, method 1
is.pk

Check whether an object is of class `pk`
is.pk_faceted

Check whether an object is of class `pk_faceted`
get_status

Get status
get_stat_model.pk

Get stat_model
ignore_unused_imports

Ignore unused imports
get_winning_model.pk

Get winning model
get_winning_model.default

Default method for get_winning_model()
invivoPKfit

invivoPKfit: A package to fit model parameters to in vivo data
is.pk_scales

Is an object class `pk_scales`?
is.pk_model

Checks whether object is of class `pk_model`
is.pkproto

Is an object pkproto?
logLik.pk

Log-likelihood
log_likelihood

Log-likelihood
model_1comp

1-compartment model
model_httk_gas_pbtk

Gas pbtk `httk` model
mapping

New mapping
nca

nca()
midpt_log10

Log10-scaled midpoint
model_flat

Flat model
model_2comp

2-compartment model
pk_add.pk_loq_group

Add loq_group
nca.default

Default method for nca()
pk_add.default

Add pkproto object default method
nca.pk

NCA for a `pk` object
pk_add.pk_sd_group

Add sd_group
pk

Create a new `pk` object
pk_add.pk_nca_group

Add a `pk_nca_group` object.
pk_add.pk_scales

Add a `pk_scales` object to a `pk` object.
pk_add

Add a `pkproto` object to a `pk` object
pk_add.pk_facet_data

Add facet_data()
pk_add.pk_stat_error_model

Add a `pk_stat_error_model` object.
pk_model

Create a new `pk_model` object
pk_add.pk_stat_model

Add a `pk_stat_model` object.
pkdataset_nheerlcleaned

Toxicokinetic data from the "Concentration vs. Time Database"
pk_subtract

Subtract a `pkproto` object from a `pk` object
pk_subtract.default

Subtract pkproto object default method
pk_subtract.pk_stat_model

Subtract a `pk_stat_model` object.
pk_add.pk_settings_optimx

Add a `pk_settings_optimx` object.
pk_add.uneval

Add an `uneval` object
pk_add.pk_settings_preprocess

Add a `pk_settings_preprocess` object.
predict.pk

Get predictions
pseudo_cvt

Creating a simple test CvT dataset
print.pk

Print a user-friendly version of a `pk` object
residuals.pk

Get residuals
post_name_value

Creates a [cli::cli_fmt()] output for the pattern "name(x), length = "
recalculate_httk_pbtk_params

Recalculating parameters for `httk`'s pbtk or gas_pbtk model
rmse

Root mean squared error (RMSE)
plot.pk

Plot a [pk()] object.
rename2_cvt

Convert invivoPKfit output table names to the CvTdb names
+.pk

Add a `pkproto` object to a `pk` object
scale_conc

Scale concentrations
rsq.default

Default method for rsq()
rowwise_calc_percentages

Helper function for calculating percentages of count data, by row
scale_time

Scale times
rsq.pk

Calculate R-squared for observed vs. predicted values
set_params_starts

Set model parameter starts
rmse.default

Root mean squared error (RMSE) default method
rsq

rsq()
rmse.pk

Root mean squared error
set_params_optimize

Set model parameters to optimize
stat_nca_group

NCA group
stat_error_model

Error model
stat_sd_group

SD Group
status_data_info

Status ID for data summary info
stat_model

Add PK model(s) to be fitted
stat_loq_group

LOQ Group
settings_preprocess

Data preprocessing settings
settings_optimx

`optimx` optimizer settings
status_fit

Status ID for fitting
status_init

Status ID for initialization
tkstats_httk_gas_pbtk

TK stats for gas_pbtk model fit with inivivoPKfit
status_prefit

Status ID for pre-fitting
time_units

Allowable time units
tkstats_2comp

Toxicokinetic statistics for 1-compartment model
status_preprocess

Status ID for preprocessing
time_conversions

Time conversion table
summary.pk

Print summary of a `pk` object
subtract_pk

Subtract various `pkproto` objects from a `pk` object
tkstats_1comp

Toxicokinetic statistics for 1-compartment model
tkstats_flat

TK stats for flat model
twofold_test

twofold_test()
transformed_params_2comp

Transformed parameters for 2-compartment model
twofold_test.pk

Evaluate whether data and predictions are within two-fold of mean or concentration, respectively
toggle_clearance_mode

Switch between model parameters to optimize
twofold_test.default

Default method for twofold_test()
AAFE.default

Default method for AAFE()
BIC.pk

Bayesian information criterion
AFE

AFE()
AFE.default

Default method for AFE()
add_pk

Add various `pkproto` objects to a `pk` object
adjust_model_name

Sets the `name` element for models to the `pk_model` object name in the environment
AAFE

AAFE()
AIC.pk

Akaike information criterion
AAFE.pk

Calculate absolute average fold error (AAFE)
AFE.pk

Calculate average fold error