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, ������, ������) =1/2+1/2 ������������������((ln⁡������������������−������)/(√2 ������))

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

232

Version

2.0.1

License

GPL-3

Maintainer

John Wambaugh

Last Published

March 24th, 2025

Functions in invivoPKfit (2.0.1)

auc_flat

AUC for flat model
auto_units

Automatically select new time units
check_method

Check methods
auc_1comp_cl

Analytic AUC for 1-compartment model with specific clearance
calc_sds_alerts

Calculate parameter SDs
calc_hessian

Calculate Hessian
calc_nca

Non-compartmental analysis
auc_2comp

Analytical AUC for the 2-compartment model
calc_rmse

Calculate RMSE (root mean squared error)
calc_rsq

Calculate r-squared for observed vs. predicted values
check_model

Check models
check_params_1comp_cl

Check 1-compartment model parameters
check_params_2comp

Check 2-compartment model parameters
check_newdata

Check new data
check_required_status.default

Default method for checking required status
check_params_1comp

Check 1-compartment model parameters
check_required_status

Check required status
check_required_status.pk

Check required status
check_params_flat

Check flat model parameters
coef.pk

Get coefficients
coef_sd.pk

Get coefficient standard deviations
coef_sd.default

Coefficient standard deviation default
coef_sd

Coefficient standard deviations
data_summary.default

Default method for data_summary()
data_summary.pk

Data summary for a `pk` object
combined_sd

Combined standard deviation
cp_flat

Flat model
compare_models.pk

Model comparison for [pk()] objects
cvt

CvTdb data
conc_scale_use

Get concentration scalings
do_data_info

do_data_info generic
do_data_info.default

do_data_info default method
fill_params_1comp

Fill parameters for 1-compartment model
compare_models.default

Default method for compare_models()
compare_models

Model comparison
do_fit.default

do_fit default method
do_fit.pk

Do fitting
facet_data

Facet a PK fit
-.pk

Subtract a pkproto object from a pk object
cp_1comp

Analytical 1-compartment model
convert_summary_to_log10

Convert sample mean and SD to log10-scale
do_prefit.default

do_prefit default method
convert_time

Helper function to convert time units
do_prefit

Prefitting
cp_1comp_cl

Analytical 1-compartment model with specific clearance
cp_2comp

Analytical 2-compartment model
cp_2comp_dt

Time derivative of analytical 2-compartment model
get_data_original.default

Default method for get_data_original()
get_data_original

get_data_original()
cvt_date

CvTdb download date
get_fit

get_fit()
get_fit.default

Default method for get_fit()
get_mapping.pk

Get mapping
do_preprocess.pk

Do pre-processing
fill_params_1comp_cl

Fill parameters for 1-compartment model with specific clearance
do_preprocess.default

do_preprocess default method
fill_params_2comp

Fill parameters for 2-compartment model
dlnorm_summary

Log-normal distribution density function for summary data
dnorm_summary

Normal distribution density function for summary data
data_summary

data_summary()
get_nca

get_nca()
get_data.default

Default method for get_data()
do_data_info.pk

calculate summary data info
eval_tkstats

eval_tkstats()
do_fit

Fitting
get_prefit.default

Default method for get_prefit()
get_scale_conc.pk

Get scale_conc
get_prefit

get_prefit()
get_scale_conc.default

Default method for get_scale_conc()
get_data_group

get_data_group()
get_data_original.pk

Get data_original
get_data.pk

Get data
fill_params_flat

Fill parameters for flat model
get_stat_model

get_stat_model()
get_fit.pk

Get fits from a `pk` object
get_data_sigma_group

get_data_sigma_group()
get_hessian

get_hessian()
get_params_1comp_cl

Get parameters for 1-compartment model with clearance assumption
get_params_1comp

Get parameters for 1-compartment model
get_data_group.default

Default method for get_data_group()
fit_group

Fit a single group of data
get_data_sigma_group.pk

Get data_sigma_group
get_data_sigma_group.default

Default method for get_data_sigma_group()
get_settings_optimx

get_settings_optimx()
get_settings_optimx.default

Default method for get_settings_optimx()
eval_tkstats.default

Default method for eval_tkstats()
eval_tkstats.pk

Evaluate TK statistics
fold_error

Fold error
get_elbow

Get an elbow point
get_error_group

get_error_group()
get_settings_optimx.pk

Get settings_optimx
get_stat_model.pk

Get stat_model
get_settings_preprocess

get_settings_preprocess()
get_stat_model.default

Default method for get_stat_model()
logLik.pk

Log-likelihood
do_prefit.pk

Do pre-fitting
do_preprocess

Preprocess data generic
get_data_info.default

Default method for get_data_info()
get_data

get_data()
fold_error.pk

Fold errors
fold_error.default

fold_error default method
get_data_group.pk

Get data grouping
get_scale_time.default

Default method for get_scale_time()
get_data_info.pk

Get data_info
get_scale_time

get_scale_time()
log_likelihood

Log-likelihood
get_data_info

get_data_info()
get_data_summary

get_data_summary()
get_status

Get status
get_data_summary.default

Default method for get_data_summary()
get_winning_model.default

Default method for get_winning_model()
pk_add.default

Add pkproto object default method
get_winning_model.pk

Get winning model
pk_add

Add a `pkproto` object to a `pk` object
get_error_group.default

Default method for get_error_group()
pk_add.pk_stat_error_model

Add a `pk_stat_error_model` object.
pk_add.pk_settings_preprocess

Add a `pk_settings_preprocess` object.
get_settings_preprocess.default

Default method for get_settings_preprocess()
get_tkstats

Get TK stats
get_mapping

get_mapping()
get_tkstats.default

Default method for get_tkstats()
get_settings_preprocess.pk

Get settings_preprocess
get_mapping.default

Default method for get_mapping()
hess_sd2

Inverse diagonal, method 2
rmse.default

Root mean squared error (RMSE) default method
rmse.pk

Root mean squared error
scale_conc

Scale concentrations
get_hessian.default

Default method for get_hessian()
get_hessian.pk

Get Hessian matrixes
get_params_1comp_fup

Get parameters for 1-compartment model with clearance assumption
hess_sd1

Inverse diagonal, method 1
get_nca.default

Default method for get_nca()
get_error_group.pk

Get error group
model_1comp

1-compartment model
pk_add.pk_settings_data_info

Add a `pk_settings_data_info` object.
get_params_flat

Get parameters to be optimized for flat model
scale_time

Scale times
model_1comp_cl_nonrest

1-compartment model that assumes non-restrictive clearance
model_2comp

2-compartment model
get_params_2comp

Get parameters for 2-compartment model
get_settings_data_info.pk

Get settings_data_info
get_settings_data_info.default

Default method for get_settings_data_info()
get_starts_1comp

Get starting values for 1-compartment model
get_peak

Find the peak of a data series
pk_add.pk_settings_optimx

Add a `pk_settings_optimx` object.
pkdataset_nheerlcleaned

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

Get starting values for 1-compartment model with specific clearance
ignore_unused_imports

Ignore unused imports
invivoPKfit

invivoPKfit: A package to fit model parameters to in vivo data
model_flat

Flat model
subtract_pk

Subtract various `pkproto` objects from a `pk` object
plot.pk

Plot a [pk()] object.
get_nca.pk

Get NCA
get_prefit.pk

Get prefit
get_scale_conc

get_scale_conc()
mapping

New mapping
midpt_log10

Log10-scaled midpoint
get_scale_time.pk

Get scale_time
get_settings_data_info

get_settings_data_info()
get_starts_flat

Get starting values for flat model
get_stat_error_model

get_stat_error_model()
get_starts_1comp_fup

Get starting values for 1-compartment model with specific clearance
status_prefit

Status ID for pre-fitting
settings_data_info

Data info settings
pk_model

Create a new `pk_model` object
tkstats_flat

TK stats for flat model
settings_optimx

`optimx` optimizer settings
tkstats_2comp

Toxicokinetic statistics for 1-compartment model
pk_subtract

Subtract a `pkproto` object from a `pk` object
summary.pk

Print summary of a `pk` object
status_preprocess

Status ID for preprocessing
nca.pk

NCA for a `pk` object
get_status.pk

Check status of a `pk` object
get_status.default

Default method for getting status
get_starts_2comp

Get starting values for 2-compartment model
get_tkstats.pk

Get TK stats
model_1comp_cl_rest

1-compartment model that assumes restrictive clearance
get_winning_model

get_winning_model()
tkstats_1comp

Toxicokinetic statistics for 1-compartment model
pk

Create a new `pk` object
print.pk

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

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

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

Get stat_error_model
get_stat_error_model.default

Default method for get_stat_error_model()
is.pk_scales

Is an object class `pk_scales`?
nca.default

Default method for nca()
model_1comp_fup

1-compartment model that assumes restrictive clearance optimizes Fup
rename2_cvt

Convert invivoPKfit output table names to the CvTdb names
rsq.default

Default method for rsq()
nca

nca()
status_fit

Status ID for fitting
rsq.pk

Calculate R-squared for observed vs. predicted values
pk_add.pk_stat_model

Add a `pk_stat_model` object.
pk_add.uneval

Add an `uneval` object
tkstats_1comp_cl

Toxicokinetic statistics for 1-compartment model with specific clearance
status_init

Status ID for initialization
twofold_test.default

Default method for twofold_test()
pk_add.pk_facet_data

Add facet_data()
pk_add.pk_scales

Add a `pk_scales` object to a `pk` object.
is.pkproto

Is an object pkproto?
pk_subtract.default

Subtract pkproto object default method
twofold_test.pk

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

Subtract a `pk_stat_model` object.
+.pk

Add a `pkproto` object to a `pk` object
settings_preprocess

Data preprocessing settings
rsq

rsq()
stat_model

Add PK model(s) to be fitted
predict.pk

Get predictions
rmse

Root mean squared error (RMSE)
stat_error_model

Error model
rowwise_calc_percentages

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

Time conversion table
residuals.pk

Get residuals
time_units

Allowable time units
transformed_params_2comp

Transformed parameters for 2-compartment model
status_data_info

Status ID for data summary info
twofold_test

twofold_test()
AAFE.pk

Calculate absolute average fold error (AAFE)
add_pk

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

AFE()
AIC.pk

Akaike information criterion
AFE.default

Default method for AFE()
AFE.pk

Calculate average fold error
auc_1comp

Analytic AUC for 1-compartment model
AAFE.default

Default method for AAFE()
BIC.pk

Bayesian information criterion
AAFE

AAFE()