Title: | Generate Concentration-Time Profiles from Linear PK Systems |
---|---|
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. |
Authors: | Benjamin Rich [aut, cre] |
Maintainer: | Benjamin Rich <[email protected]> |
License: | GPL-3 |
Version: | 1.1.4 |
Built: | 2024-11-04 05:19:27 UTC |
Source: | https://github.com/benjaminrich/linpk |
pkprofile
to a data.frame
Coerce a pkprofile
to a data.frame
## S3 method for class 'pkprofile' as.data.frame(x, ..., col.names = c("time", "conc"), .state = FALSE)
## S3 method for class 'pkprofile' as.data.frame(x, ..., col.names = c("time", "conc"), .state = FALSE)
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 |
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.
blockdiag(..., .names = NULL, .colnames = .names, .rownames = .names)
blockdiag(..., .names = NULL, .colnames = .names, .rownames = .names)
... |
Any number of square matrices making up the diagonal blocks of the matrix. |
.names , .colnames , .rownames
|
Optionally, specify the row and column names of the resulting matrix. |
A block-diagonal matrix.
blockdiag(matrix(1, 2, 2), 2, matrix(3, 4, 4)) blockdiag(c(a=5, b=6), Diag(c=7, d=8), LTmat(c(1, 2, 3), .names=c("e", "f"))) blockdiag(a=5, b=6, Diag(c=7, d=8), LTmat(c(1, 2, 3), .names=c("e", "f"))) blockdiag(5, 6, Diag(7, 8), LTmat(c(1, 2, 3)), .names=c("a", "b", "c", "d", "e", "f"))
blockdiag(matrix(1, 2, 2), 2, matrix(3, 4, 4)) blockdiag(c(a=5, b=6), Diag(c=7, d=8), LTmat(c(1, 2, 3), .names=c("e", "f"))) blockdiag(a=5, b=6, Diag(c=7, d=8), LTmat(c(1, 2, 3), .names=c("e", "f"))) blockdiag(5, 6, Diag(7, 8), LTmat(c(1, 2, 3)), .names=c("a", "b", "c", "d", "e", "f"))
Convert from standard deviation and correlation matrix to covariance matrix.
cor2cov(cor, sd)
cor2cov(cor, sd)
cor |
A correlation matrix. If |
sd |
A vector of standard deviations (optional). |
A covariance matrix.
cor2cov(matrix(c(1, 0.5, 0.5, 1), 2, 2), 0.1) cor2cov(LTmat(c(0.39, 0.67, 0.28), .names=c("CL", "VC")))
cor2cov(matrix(c(1, 0.5, 0.5, 1), 2, 2), 0.1) cor2cov(LTmat(c(0.39, 0.67, 0.28), .names=c("CL", "VC")))
Like the base diag
function, except that vectors of length
one are converted to 1-by-1 matrices, values can be specified either as a
single vector argument or multiple arguments, and row and column names can
be specified.
Diag(x, ..., .names = names(x), .colnames = .names, .rownames = .names)
Diag(x, ..., .names = names(x), .colnames = .names, .rownames = .names)
x |
A numeric (or number-like) vector (possibly named). |
... |
Additional numeric (or number-like) vectors (possibly named). |
.names , .colnames , .rownames
|
Optionally, specify the row and column names of the resulting diagonal matrix. |
Diag(6) Diag(3.14, .names="pi") Diag(1:6, .colnames=LETTERS[1:6], .rownames=letters[1:6]) Diag(1, 2, 3) Diag(a=1, b=2, c=3) Diag(a=1, c(b=2, c=3)) Diag(2+3i, 4+5i)
Diag(6) Diag(3.14, .names="pi") Diag(1:6, .colnames=LETTERS[1:6], .rownames=letters[1:6]) Diag(1, 2, 3) Diag(a=1, b=2, c=3) Diag(a=1, c(b=2, c=3)) Diag(2+3i, 4+5i)
Get the doses from a PK profile.
dose.frame(x)
dose.frame(x)
x |
A object of class |
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.
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)
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.
finalstate(x) finaltime(x)
finalstate(x) finaltime(x)
x |
A object of class |
A numeric
vector containing the state of each compartment at
the final observation time (finalstate
), or the final observation
time itself (finaltime
).
pkprofile
for generating a PK profile.
pkprofile.pkprofile
for appending to an existing PK profile.
# 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)
# 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.
generateETA(n, omegaLT, omega = LTmat(omegaLT), eta.names = colnames(omega))
generateETA(n, omegaLT, omega = LTmat(omegaLT), eta.names = colnames(omega))
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 |
An matrix, where each row contains the vector of random
effects for one individual (
is the size of the covariance matrix).
omegaLT <- c(0.123, 0.045, 0.678) generateETA(10, omegaLT)
omegaLT <- c(0.123, 0.045, 0.678) generateETA(10, omegaLT)
Half-lives of a linear PK system.
halflife(x)
halflife(x)
x |
A object of class |
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
).
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)
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.
linpkApp(...)
linpkApp(...)
... |
Arguments passed to |
Called for its side effects.
The app requires the following packages:
'shiny'
'shinyjs'
'shinyAce'
'dygraphs'
Make they are installed or the app won't work.
## Not run: linpkApp() ## End(Not run)
## Not run: linpkApp() ## End(Not run)
Construct a symmetric matrix from its lower triangle.
LTmat( LT, ..., .names = attr(LT, ".names"), .colnames = .names, .rownames = .names )
LTmat( LT, ..., .names = attr(LT, ".names"), .colnames = .names, .rownames = .names )
LT |
A numeric (or number-like) vector giving the elements of the lower triangle of the matrix by row (see examples). |
... |
Additional numeric (or number-like) vectors, appended to
|
.names , .colnames , .rownames
|
Optionally, specify the row and column names of the resulting diagonal matrix. The names can also be specified as the LHS of a 2-sided formula (see Examples). |
A symmetric matrix.
LTmat(1:6) LTmat(1, 3, 5, .names=c("a", "b")) LTmat(c(a, b) ~ c(1, 3, 5)) # Names can also be specified as LHS of a 2-sided formula LTmat(1+2i, 3+4i, 5+6i)
LTmat(1:6) LTmat(1, 3, 5, .names=c("a", "b")) LTmat(c(a, b) ~ c(1, 3, 5)) # Names can also be specified as LHS of a 2-sided formula LTmat(1+2i, 3+4i, 5+6i)
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.
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, ... )
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, ... )
... |
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. |
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
.
pkprofile(default)
: Default method.
pkprofile(matrix)
: Matrix method.
Pay attention to the default arguments. They are there for convenience, but may lead to undesired results if one is not careful.
# 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")
# 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")
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.
## S3 method for class 'pkprofile' pkprofile(obj, t.obs = finaltime(obj) + seq(0, 24, 0.1), ..., append = TRUE)
## S3 method for class 'pkprofile' pkprofile(obj, t.obs = finaltime(obj) + seq(0, 24, 0.1), ..., append = TRUE)
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. |
An object of class "pkprofile".
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.
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)
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.
secondary(x, From = NULL, To = NULL, include.dose.times = T)
secondary(x, From = NULL, To = NULL, include.dose.times = T)
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? |
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).
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))
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))