Type: | Package |
Version: | 1.1.2 |
Date: | 2022-12-04 |
Title: | Generate Concentration-Time Profiles from Linear PK Systems |
Author: | Benjamin Rich [aut, cre] |
Maintainer: | Benjamin Rich <mail@benjaminrich.net> |
URL: | https://github.com/benjaminrich/linpk |
BugReports: | https://github.com/benjaminrich/linpk/issues |
Description: | Generate concentration-time profiles from linear pharmacokinetic (PK) systems, possibly with first-order absorption or zero-order infusion, possibly with one or more peripheral compartments, and possibly under steady-state conditions. Single or multiple doses may be specified. Secondary (derived) PK parameters (e.g. Cmax, Ctrough, AUC, Tmax, half-life, etc.) are computed. |
License: | GPL-3 |
Imports: | graphics,utils,mvtnorm |
Suggests: | knitr,rmarkdown,shiny |
VignetteBuilder: | knitr |
Encoding: | UTF-8 |
RoxygenNote: | 7.2.1 |
NeedsCompilation: | no |
Packaged: | 2022-12-04 13:56:55 UTC; ben |
Repository: | CRAN |
Date/Publication: | 2022-12-04 14:10:07 UTC |
Construct a symmetric matrix from its lower triangle.
Description
Construct a symmetric matrix from its lower triangle.
Usage
LTmat(LT, .names = attr(LT, ".names"), .colnames = .names, .rownames = .names)
Arguments
LT |
A numeric vector giving the elements of the lower triangle of the matrix by row (see examples). |
.names , .colnames , .rownames |
Optionally, specify row and column names of the resulting matrix. |
Value
A symmetric matrix.
Examples
LTmat(1:6)
Coerce a pkprofile
to a data.frame
Description
Coerce a pkprofile
to a data.frame
Usage
## S3 method for class 'pkprofile'
as.data.frame(x, ..., col.names = c("time", "conc"), .state = FALSE)
Arguments
x |
An object of class |
... |
Further arguments passed along. |
col.names |
Character vector of length 2 giving the names for the time and concentration columns. |
.state |
Include the complete state along with |
Value
A data.frame
with columns time
and conc
(or the
names specified in col.names
). If .state == TRUE
, then the
complete state is appended (as a matrix column).
Construct a block-diagonal matrix.
Description
Construct a block-diagonal matrix.
Usage
blockdiag(...)
Arguments
... |
Any number of square matrices making up the diagonal blocks of the matrix. |
Value
A block-diagonal matrix.
Examples
blockdiag(matrix(1, 2, 2), 2, matrix(3, 4, 4))
Convert from standard deviation and correlation matrix to covariance matrix.
Description
Convert from standard deviation and correlation matrix to covariance matrix.
Usage
cor2cov(cor, sd)
Arguments
cor |
A correlation matrix. If |
sd |
A vector of standard deviations (optional). |
Value
A covariance matrix.
Examples
cor2cov(matrix(c(1, 0.5, 0.5, 1), 2, 2), 0.1)
Get the doses from a PK profile.
Description
Get the doses from a PK profile.
Usage
dose.frame(x)
Arguments
x |
A object of class |
Value
A data.frame
containing the realized doses, one per row. The
data.frame
has all the columns described in pkprofile
,
except addl
, since all additional doses have been expanded to
individual rows. It also has a conc
column with the simulated
concentration at the time of the dose.
See Also
Examples
t.obs <- seq(0, 6*24, 0.5)
y <- pkprofile(t.obs, cl=0.5, vc=11, ka=1.3,
dose=list(t.dose=c(0, 24*2 + 14), amt=c(100, 50), addl=c(4, 0), ii=24))
dose.frame(y)
Get the final state or time of a PK profile.
Description
Get the final state or time of a PK profile.
Usage
finalstate(x)
finaltime(x)
Arguments
x |
A object of class |
Value
A numeric
vector containing the state of each compartment at
the final observation time (finalstate
), or the final observation
time itself (finaltime
).
See Also
-
pkprofile
for generating a PK profile. -
pkprofile.pkprofile
for appending to an existing PK profile.
Examples
# Administer a dose at time 0 and a second dose using the final state
# from the first dose (at 12h) as the initial state for the second dose.
t.obs <- seq(0, 12, 0.1)
y <- pkprofile(t.obs, cl=0.25, vc=5, ka=1, dose=list(t.dose=0, amt=1))
finalstate(y)
y2 <- pkprofile(t.obs, cl=0.25, vc=5, ka=1, dose=list(t.dose=0, amt=1), initstate=finalstate(y))
plot(y, xlim=c(0, 24), ylim=c(0, max(y2)), col="blue") # First dose
lines(t.obs+12, y2, col="red") # Second dose
# Add a vertical line to show where the first profile ends.
abline(v=finaltime(y), col="gray75", lty=2)
Generate individual random effects from a multivariate normal distribution.
Description
Generate individual random effects from a multivariate normal distribution.
Usage
generateETA(n, omegaLT, omega = LTmat(omegaLT), eta.names = colnames(omega))
Arguments
n |
The number of individuals. |
omegaLT |
A numeric vector giving the elements of the lower triangle of the covariance matrix by row. |
omega |
The covariance matrix. |
eta.names |
A character vector of names for each random effect
(defaults to the column names of |
Value
An n \times p
matrix, where each row contains the vector of random
effects for one individual (p
is the size of the covariance matrix).
See Also
Examples
omegaLT <- c(0.123, 0.045, 0.678)
generateETA(10, omegaLT)
Half-lives of a linear PK system.
Description
Half-lives of a linear PK system.
Usage
halflife(x)
Arguments
x |
A object of class |
Value
A numeric
vector containing the half-lives for the different
phases of the system. The number of phases generally equal the number of
compartments, plus one for the absorption phase if the system has first
order absorption (i.e. if ka
is specified). The values are returned
sorted in ascending order, so the first corresponds to the alpha phase,
the second beta, the third gamma, and so on. The absorption half-life, if
present, comes last (it can also be identified by comparing it to the value
of log(2)/ka
).
Examples
y <- pkprofile(0, cl=0.25, vc=5, ka=1.1)
halflife(y)
log(2)/1.1
y <- pkprofile(0, cl=0.25, vc=5, ka=0.01) # Flip-flop kinetics
halflife(y)
log(2)/0.01
# Three-compartment model
y <- pkprofile(0, cl=2, vc=10, q=c(0.5, 0.3), vp=c(30, 40))
halflife(y)
# The terminal half-life can be used to obtain the terminal slope of the
# concentration-time curve on the semi-log scale:
t.obs <- seq(0, 36, 0.1)
y <- pkprofile(t.obs, cl=0.25, vc=5, ka=1, dose=list(t.dose=0, amt=1))
plot(log2(y))
abline(-2.247927, -1/halflife(y)[1], col=adjustcolor("blue", 0.2), lwd=12)
Runs the interactive shiny app.
Description
Runs the interactive shiny app.
Usage
linpkApp(...)
Arguments
... |
Arguments passed to |
Value
Called for its side effects.
Note
The app requires the following packages:
'shiny'
'shinyjs'
'shinyAce'
'dygraphs'
Make they are installed or the app won't work.
Examples
## Not run:
linpkApp()
## End(Not run)
Generate a concentration-time profile.
Description
This function generates concentration-time profiles from a linear pharmacokinetic (PK) system, possibly with first-order absorption or zero-order infusion, possibly with one or more peripheral compartments, and possibly under steady-state conditions. Single or multiple doses may be specified.
Usage
pkprofile(...)
## Default S3 method:
pkprofile(
t.obs = seq(0, 24, 0.1),
cl = 1,
vc = 5,
q = numeric(0),
vp = numeric(0),
ka = 0,
dose = list(t.dose = 0, amt = 1, rate = 0, dur = 0, ii = 24, addl = 0, ss = 0, cmt = 0,
lag = 0, f = 1),
sc = vc,
initstate = NULL,
...
)
## S3 method for class 'matrix'
pkprofile(
A,
t.obs = seq(0, 24, 0.1),
dose = list(t.dose = 0, amt = 1, rate = 0, dur = 0, ii = 24, addl = 0, ss = 0, cmt = 0,
lag = 0, f = 1),
defdose = 1,
sc = 1,
initstate = NULL,
...
)
Arguments
... |
Further arguments passed along to other methods. |
t.obs |
A numeric vector of times at which to observe concentrations. |
cl |
Central clearance parameter. |
vc |
Central volume parameter. |
q |
Inter-compartmental clearance. Can be a vector for more than one
peripheral compartment, or empty for none. Must match |
vp |
Peripheral volume. Can be a vector for more than one
peripheral compartment, or empty for none. Must match |
ka |
First-order absorption rate parameter. Set to 0 to indicate that there is no first-order absorption (i.e. bolus or infusion). |
dose |
A
|
sc |
A scaling constant for the central compartment. Concentrations are obtained by dividing amounts by this constant. |
initstate |
A numeric vector containing values to initialize the compartments. |
A |
A matrix of first-order rate constants between the compartments. |
defdose |
The default dose compartment when the compartment is missing or 0. |
Value
An object of class "pkprofile", which is simply a numeric vector of
concentration values with some attributes attached to it.
This object has its own methods for print
, plot
, lines
and points
.
Methods (by class)
-
pkprofile(default)
: Default method. -
pkprofile(matrix)
: Matrix method.
Warning
Pay attention to the default arguments. They are there for convenience, but may lead to undesired results if one is not careful.
See Also
Examples
# Default values, a bolus injection
y <- pkprofile()
plot(y)
t.obs <- seq(0, 24, 0.1)
dur <- 1
amt <- 1
ka <- 1
cl <- 0.25
vc <- 5
q <- 2.5
vp <- 10
# One-compartment model with first-order absorption, single dose
y <- pkprofile(t.obs, cl=cl, vc=vc, ka=ka, dose=list(amt=amt))
plot(y)
# Two-compartment model with first-order absorption, single dose
y <- pkprofile(t.obs, cl=cl, vc=vc, vp=vp, q=q, ka=ka, dose=list(amt=amt))
plot(y)
# One-compartment model with zero-order infusion, single dose
y <- pkprofile(t.obs, cl=cl, vc=vc, dose=list(dur=dur, amt=amt))
plot(y)
# Two-compartment model with zero-order infusion, single dose
y <- pkprofile(t.obs, cl=cl, vc=vc, vp=vp, q=q, dose=list(dur=dur, amt=amt))
plot(y)
# Two-compartment model with bolus injection, single dose
y <- pkprofile(t.obs, cl=cl, vc=vc, vp=vp, q=q, dose=list(amt=amt))
plot(y)
# Two-compartment model with bolus injection into the peripheral compartment, single dose
y <- pkprofile(t.obs, cl=cl, vc=vc, vp=vp, q=q, dose=list(amt=amt, cmt=2))
plot(y)
# Two-compartment model with zero-order infusion into the peripheral compartment, single dose
y <- pkprofile(t.obs, cl=cl, vc=vc, vp=vp, q=q, dose=list(amt=amt, cmt=2, dur=dur))
plot(y)
t.obs <- seq(0, 24*6, 1)
# One-compartment model with first-order absorption, multiple doses
y <- pkprofile(t.obs, cl=cl, vc=vc, ka=ka, dose=list(t.dose=seq(0, 24*5, 12), amt=amt))
plot(y)
# One-compartment model with first-order absorption, multiple doses specified by addl and ii
y <- pkprofile(t.obs, cl=cl, vc=vc, ka=ka, dose=list(t.dose=0, amt=amt, addl=9, ii=12))
plot(y, type="b")
points(y, col="blue")
# One-compartment model with first-order absorption, multiple doses under steady-state conditions
yss <- pkprofile(t.obs, cl=cl, vc=vc, ka=ka, dose=list(t.dose=0, amt=amt, addl=9, ii=12, ss=1))
lines(yss, col="red")
points(yss, col="green")
# One-compartment model with zero-order infusion, multiple doses specified by addl and ii
y <- pkprofile(t.obs, cl=cl, vc=vc, dose=list(dur=dur, amt=amt, addl=9, ii=12))
plot(y, log="y")
# One-compartment model with zero-order infusion, multiple doses under steady-state conditions
yss <- pkprofile(t.obs, cl=cl, vc=vc, dose=list(dur=dur, amt=amt, addl=9, ii=12, ss=1))
lines(yss, col="red")
Printing and plotting methods for class pkprofile
.
Description
Printing and plotting methods for class pkprofile
.
Usage
## S3 method for class 'pkprofile'
print(x, ...)
## S3 method for class 'pkprofile'
plot(x, y, ...)
## S3 method for class 'pkprofile'
lines(x, y, ...)
## S3 method for class 'pkprofile'
points(x, y, ...)
Arguments
x |
An object of class |
y |
Any other object. Specifying |
Continue an existing concentration-time profile.
Description
This method can be used to append to an existing PK profile, for instance to simulate a PK profile with parameters that change over time. Each time the parameters change, a new call to this method is used to advance the system with the new parameter values.
Usage
## S3 method for class 'pkprofile'
pkprofile(obj, t.obs = finaltime(obj) + seq(0, 24, 0.1), ..., append = TRUE)
Arguments
obj |
An object returned from a previous call to |
t.obs |
A numeric vector of times at which to observe concentrations. |
... |
Further arguments passed along. |
append |
Should the new profile be appended to the current samples? Otherwise, only the new samples are returned. |
Value
An object of class "pkprofile".
Warning
The new parameters take effect at the time when the previous profile ends. If the previous profile ends before the new sampling starts, the new parameters will be used to advance the system to the start of the new sampling.
Any ongoing zero-order infusion at the end of the previous profile is dropped. The remaining infusion amount will NOT be carried forward.
See Also
Examples
t.obs <- seq(0, 24, 0.1)
amt <- 1
ka <- 1
cl <- 0.25
vc <- 5
# One-compartment model with first-order absorption
# First dose at time 0
y <- pkprofile(t.obs, cl=cl, vc=vc, ka=ka, dose=list(t.dose=0, amt=amt))
# Second dose at 24h with a lower clearance
y <- pkprofile(y, t.obs+24, cl=0.5*cl, vc=vc, ka=ka, dose=list(t.dose=24, amt=amt))
# Third dose at 48h with a higher clearance
y <- pkprofile(y, t.obs+48, cl=2*cl, vc=vc, ka=ka, dose=list(t.dose=48, amt=amt))
plot(y)
Derive secondary PK parameters.
Description
Derive secondary PK parameters.
Usage
secondary(x, From = NULL, To = NULL, include.dose.times = T)
Arguments
x |
A object of class |
From |
A vector of interval start times. The defaults is the times of the doses. |
To |
A vector of interval end times. The defaults is the time of the next dose, or last observation time. |
include.dose.times |
Should dose times (and end of infusion times) be considered in addition to the simulation times? |
Value
A data.frame
with one row for each time interval and with the
following columns:
From
The time of the start of the interval. Can differ from the specified start time because it always corresponds to an actual data point.
To
The time of the end of the interval. Can differ from the specified end time because it always corresponds to an actual data point.
N
The number of distinct data points in the interval used to derive
AUC
,Cmax
, etc.Ctrough
Concentration at the time of dose (i.e. just prior to the dose). Only present if the start of the interval corresponds to a dose time.
Cmin
Minimum concentration over the interval.
Tmin
Time of the minimum concentration over the interval.
Cmax
Maximum concentration over the interval.
Tmax
Time of the maximum concentration over the interval.
Cave
Average concentration over the interval (calculated by the trapezoid rule).
AUC
Area under the concentration-time curve over the interval (calculated by the trapezoid rule).
Examples
t.obs <- seq(0, 24*4, 0.1)
y <- pkprofile(t.obs, cl=0.25, vc=5, ka=1, dose=list(t.dose=0, amt=1, addl=6, ii=12))
secondary(y)
secondary(y, 0, 48)
secondary(y, 0, Inf)
sum(secondary(y)$AUC) # Same as above
plot(y)
with(secondary(y), points(Tmax, Cmax, pch=19, col="blue"))
with(secondary(y), points(Tmin, Cmin, pch=19, col="red"))
with(secondary(y), points(From, Ctrough, pch=19, col="green"))
with(secondary(y), points(From + 6, Cave, pch=19, col="purple", cex=2))