Learn R Programming

The PKNCA R Package

The PKNCA R package is designed to perform all noncompartmental analysis (NCA) calculations for pharmacokinetic (PK) data. The package is broadly separated into two parts (calculation and summary) with some additional housekeeping functions.

The primary and secondary goals of the PKNCA package are to 1) only give correct answers to the specific questions being asked and 2) automate as much as possible to simplify the task of the analyst. When automation would leave ambiguity or make a choice that the analyst may have an alternate preference for, it is either not used or is possible to override.

Note that backward compatibility will not be guaranteed until version 1.0. Argument and function changes will continue until then. These will be especially noticeable around the inclusion of IV NCA parameters and additional specifications of the dosing including dose amount and route.

Citation

Citation information for the PKNCA package is available with a call to citation(package="PKNCA"). The preferred citation until publication of version 1.0 is below:

Denney W, Duvvuri S and Buckeridge C (2015). "Simple, Automatic Noncompartmental Analysis: The PKNCA R Package." Journal of Pharmacokinetics and Pharmacodynamics, 42(1), pp. 11-107,S65. ISSN 1573-8744, doi: 10.1007/s10928-015-9432-2, <URL: https://github.com/billdenney/pknca>.

Installation

From CRAN

The current stable version of PKNCA is available on CRAN. You can install it and its dependencies using the following command:

install.packages("PKNCA")

From GitHub

To install the development version from GitHub, type the following commands:

install.packages("remotes")
remotes::install_github("billdenney/pknca")

Calculating parameters

# Load the package
library(PKNCA)
# Set the business rule options with the PKNCA.options() function
# Load your concentration-time data
conc_raw <- read.csv("myconc.csv", stringsAsFactors=FALSE)
# Load your dose data
dose_raw <- read.csv("mydose.csv", stringsAsFactors=FALSE)
# Put your concentration data into a PKNCAconc object
o_conc <- PKNCAconc(data=conc_raw,
                    formula=conc~time|treatment+subject/analyte)
# Put your dose data into a PKNCAdose object
o_dose <- PKNCAdose(data=dose_raw,
                    formula=dose~time|treatment+subject)
# Combine the two (and automatically determine the intervals of
# interest
o_data <- PKNCAdata(o_conc, o_dose)
# Compute the NCA parameters
o_results <- pk.nca(o_data)
# Summarize the results
summary(o_results)

More help is available in the function help files, and be sure to look at the PKNCA.options function for many choices to make PKNCA conform to your company's business rules for calculations and summarization.

Feature requests

Please use the github issues page (https://github.com/billdenney/pknca/issues) to make feature requests and bug reports.

Copy Link

Version

Install

install.packages('PKNCA')

Monthly Downloads

2,451

Version

0.11.0

License

AGPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Bill Denney

Last Published

June 19th, 2024

Functions in PKNCA (0.11.0)

any_sparse_dense_in_interval

Determine if there are any sparse or dense calculations requested within an interval
addProvenance

Add a hash and associated information to enable checking object provenance.
add.interval.col

Add columns for calculations within PKNCA intervals
as.data.frame.PKNCAresults

Extract the parameter results from a PKNCAresults and return them as a data.frame.
as_PKNCAconc

Convert an object into a PKNCAconc object
add_impute_to_intervals

Add the imputation column to the intervals, if it is not already there
assert_dosetau

Assert that a value is a dosing interval
assert_intervaltime_single

Assert that an interval is accurately defined as an interval, and return the interval
exclude

Exclude data points or results from calculations or summarization.
clean.conc.na

Handle NA values in the concentration measurements as requested by the user.
defunct

The following functions are defunct
assert_lambdaz

Assert that a lambda.z value is valid
assert_number_between

Confirm that a value is greater than another value
choose_interval_method

Choose how to interpolate, extrapolate, or integrate data in each concentration interval
cov_holder

Calculate the covariance for two time points with sparse sampling
check.conversion

Check that the conversion to a data type does not change the number of NA values
assert_aucmethod

Assert that a value is a valid AUC method
assert_conc

Verify that concentration measurements are valid
clean.conc.blq

Handle BLQ values in the concentration measurements as requested by the user.
formula.PKNCAconc

Extract the formula from a PKNCAconc object.
business.mean

Generate functions to do the named function (e.g. mean) applying the business rules.
get.parameter.deps

Get all columns that depend on a parameter
assert_numeric_between

Confirm that a value is greater than another value
check.interval.specification

Check the formatting of a calculation interval specification data frame.
check.interval.deps

Take in a single row of an interval specification and return that row updated with any additional calculations that must be done to fulfill all dependencies.
fit_half_life

Perform the half-life fit given the data. The function simply fits the data without any validation. No selection of points or any other components are done.
get.best.model

Extract the best model from a list of models using the AIC.
geomean

Compute the geometric mean, sd, and CV
choose.auc.intervals

Choose intervals to compute AUCs from time and dosing information
group_by.PKNCAresults

dplyr grouping for PKNCA
find.tau

Find the repeating interval within a vector of doses
getAttributeColumn

Retrieve the value of an attribute column.
auc_integrate

Support function for AUC integration
getColumnValueOrNot

Get the value from a column in a data frame if the value is a column there, otherwise, the value should be a scalar or the length of the data.
group_vars.PKNCAconc

Get grouping variables for a PKNCA object
get.first.model

Get the first model from a list of models
checkProvenance

Check the hash of an object to confirm its provenance.
exclude_nca

Exclude NCA parameters based on examining the parameter set.
getDataName.PKNCAconc

Get the name of the element containing the data for the current object.
get.interval.cols

Get the columns that can be used in an interval specification
interp_extrap_conc_method

Interpolate or extrapolate concentrations using the provided method
is_sparse_pk.PKNCAconc

Is a PKNCA object used for sparse PK?
filter.PKNCAresults

dplyr filtering for PKNCA
get_impute_method

Get the impute function from either the intervals column or from the method
getIndepVar

Get the independent variable (right hand side of the formula) from a PKNCA object.
pk.calc.clast.obs

Determine the last observed concentration above the limit of quantification (LOQ).
pk.calc.cl

Calculate the (observed oral) clearance
pk.calc.auciv

Calculate AUC for intravenous dosing
pk.calc.aucpext

Calculate the AUC percent extrapolated
pk.business

Run any function with a maximum missing fraction of X and 0s possibly counting as missing. The maximum fraction missing comes from PKNCA.options("max.missing").
pk.calc.ae

Calculate amount excreted (typically in urine or feces)
pk.calc.fe

Calculate fraction excreted (typically in urine or feces)
pk.calc.tlag

Determine the observed lag time (time before the first concentration above the limit of quantification or above the first concentration in the interval)
pk.calc.half.life

Compute the half-life and associated parameters
pk.calc.tlast

Determine time of last observed concentration above the limit of quantification.
findOperator

Find the first occurrence of an operator in a formula and return the left, right, or both sides of the operator.
getGroups.PKNCAconc

Get the groups (right hand side after the | from a PKNCA object).
getDepVar

Get the dependent variable (left hand side of the formula) from a PKNCA object.
normalize_exclude

Normalize the exclude column by setting blanks to NA
mutate.PKNCAresults

dplyr mutate-based modification for PKNCA
parse_formula_to_cols

Convert a formula representation to the columns for input data
pk.calc.deg.fluc

Determine the degree of fluctuation
model.frame.PKNCAconc

Extract the columns used in the formula (in order) from a PKNCAconc or PKNCAdose object.
inner_join.PKNCAresults

dplyr joins for PKNCA
interp.extrap.conc

Interpolate concentrations between measurements or extrapolate concentrations after the last measurement.
pk.calc.count_conc

Count the number of concentration measurements in an interval
pk.calc.cstart

Determine the concentration at the beginning of the interval
pk.calc.kel

Calculate the elimination rate (Kel)
pk.calc.cav

Calculate the average concentration during an interval.
pk.calc.ceoi

Determine the concentration at the end of infusion
pk.calc.ctrough

Determine the trough (end of interval) concentration
pk.calc.aucabove

Calculate the AUC above a given concentration
pk.calc.cmax

Determine maximum observed PK concentration
pk.calc.aucint

Calculate the AUC over an interval with interpolation and/or extrapolation of concentrations for the beginning and end of the interval.
pk.calc.ptr

Determine the peak-to-trough ratio
pk.calc.clr

Calculate renal clearance
pk.calc.mrt

Calculate the mean residence time (MRT) for single-dose data or linear multiple-dose data.
pk.nca.intervals

Compute NCA for multiple intervals
pk.calc.mrt.md

Calculate the mean residence time (MRT) for multiple-dose data with nonlinear kinetics.
pk.nca

Compute NCA parameters for each interval for each subject.
pk.nca.interval

Compute all PK parameters for a single concentration-time data set
pk.tss

Compute the time to steady-state (tss)
pk.calc.thalf.eff

Calculate the effective half-life
pk.tss.data.prep

Clean up the time to steady-state parameters and return a data frame for use by the tss calculators.
pk.calc.auxc

A compute the Area Under the (Moment) Curve
pk.calc.c0

Estimate the concentration at dosing time for an IV bolus dose.
pk.calc.f

Calculate the absolute (or relative) bioavailability
pk.calc.dn

Determine dose normalized NCA parameter
pk.calc.tmax

Determine time of maximum observed PK concentration
pk.calc.totdose

Extract the dose used for calculations
pk.calc.swing

Determine the PK swing
pk.calc.sparse_auc

Calculate AUC and related parameters using sparse NCA methods
roundingSummarize

During the summarization of PKNCAresults, do the rounding of values based on the instructions given.
setAttributeColumn

Add an attribute to an object where the attribute is added as a name to the names of the object.
pknca_find_units_param

Find NCA parameters with a given unit type
pk.calc.time_above

Determine time at or above a set value
print.PKNCAconc

Print and/or summarize a PKNCAconc or PKNCAdose object.
setDuration.PKNCAconc

Set the duration of dosing or measurement
print.PKNCAdata

Print a PKNCAdata object
pk.tss.monoexponential

Compute the time to steady state using nonlinear, mixed-effects modeling of trough concentrations.
pk.tss.stepwise.linear

Compute the time to steady state using stepwise test of linear trend
time_calc

Times relative to an event (typically dosing)
tss.monoexponential.generate.formula

A helper function to generate the formula and starting values for the parameters in monoexponential models.
setExcludeColumn

Set the exclude parameter on an object
pk.calc.vz

Calculate the terminal volume of distribution (Vz)
pk_nca_result_to_df

Convert the grouping info and list of results for each group into a results data.frame
pknca_units_table

Create a unit assignment and conversion table
pk.calc.vss

Calculate the steady-state volume of distribution (Vss)
pknca_units_add_paren

Add parentheses to a unit value, if needed
summary.PKNCAdata

Summarize a PKNCAdata object showing important details about the concentration, dosing, and interval information.
sparse_mean

Calculate the mean concentration at all time points for use in sparse NCA calculations
pk.tss.monoexponential.population

A helper function to estimate population and popind outputs for monoexponential time to steady-state.
setRoute

Set the dosing route
pk.tss.monoexponential.individual

A helper function to estimate individual and single outputs for monoexponential time to steady-state.
signifString

Round a value to a defined number of significant digits printing out trailing zeros, if applicable.
print.provenance

Print the summary of a provenance object
pknca_unit_conversion

Perform unit conversion (if possible) on PKNCA results
print.summary_PKNCAresults

Print the results summary
var_sparse_auc

Calculate the variance for the AUC of sparsely sampled PK
superposition

Compute noncompartmental superposition for repeated dosing
summary.PKNCAresults

Summarize PKNCA results
roundString

Round a value to a defined number of digits printing out trailing zeros, if applicable.
reexports

Objects exported from other packages
sparse_to_dense_pk

Extract the mean concentration-time profile as a data.frame
sparse_auc_weight_linear

Calculate the weight for sparse AUC calculation with the linear-trapezoidal rule
sort.interval.cols

Sort the interval columns by dependencies.
sparse_pk_attribute

Set or get a sparse_pk object attribute
PKNCA

Compute noncompartmental pharmacokinetics
PKNCA_impute_method

Methods for imputation of data with PKNCA
PKNCAdata

Create a PKNCAdata object.
PKNCAdose

Create a PKNCAdose object
PKNCA.options

Set default options for PKNCA functions
PKNCA.choose.option

Choose either the value from an option list or the current set value for an option.
PKNCAconc

Create a PKNCAconc object
PKNCA.options.describe

Describe a PKNCA.options option by name.
PKNCA.set.summary

Define how NCA parameters are summarized.
PKNCA_impute_fun_list

Separate out a vector of PKNCA imputation methods into a list of functions
as_sparse_pk

Generate a sparse_pk object
assert_PKNCAdata

Assert that an object is a PKNCAdata object
adj.r.squared

Calculate the adjusted r-squared value
PKNCAresults

Generate a PKNCAresults object