View source: R/find_best_lambdaz.R
| find_best_lambdaz | R Documentation |
Identifies the optimal terminal phase for lambdaz estimation using a systematic log-linear regression approach with adjusted R-squared optimization criteria.
find_best_lambdaz(
time,
conc,
route = "bolus",
duration = NULL,
adj_r_squared_threshold = 0.7,
nlastpoints = 3,
tolerance = 1e-04
)
time |
Numeric vector of observation time points. |
conc |
Numeric vector of concentration measurements corresponding to time points. |
route |
Administration method specification:
|
duration |
Numeric (optional). Duration of infusion administration, in the same
time units as |
adj_r_squared_threshold |
Minimum acceptable adjusted R-squared value for valid estimation (default = 0.7). Values below this threshold will generate warnings. |
nlastpoints |
Integer. Minimum number of terminal points (from the end of the profile)
to include when evaluating candidate regression segments for |
tolerance |
Threshold for considering adjusted R-squared values statistically equivalent (default = 1e-4). Used when selecting between fits with similar goodness-of-fit. |
The algorithm implements the following decision logic:
Identifies the time of maximum observed concentration (Tmax)
Defines candidate terminal phases starting from the last 3 measurable concentrations
Iteratively evaluates longer time spans by including preceding data points
For each candidate phase:
Performs log-concentration vs. time linear regression
Requires negative regression slope (positive \lambda_z)
Calculates adjusted R-squared metric
Selects the optimal phase based on:
Highest adjusted R-squared value
When R-squared differences are < tolerance, selects the fit with more points
Validates final selection against R-squared threshold
A list containing:
lambdaz: Estimated terminal elimination rate constant (\lambda_z), or NA if no valid fit
UsedPoints: Number of data points used in the optimal fit
adj.r.squared: Adjusted R-squared value (R^2) of the optimal regression
message: Character vector containing diagnostic messages or warnings
Zhonghui Huang
# Basic usage
time <- c(0.5, 1, 2, 4, 6, 8, 10)
conc <- c(12, 8, 5, 3, 2, 1.5, 1)
find_best_lambdaz(time, conc)
# With infusion route specification
find_best_lambdaz(time, conc, route = "bolus",duration=1)
# Custom threshold settings
find_best_lambdaz(time, conc, adj_r_squared_threshold = 0.8, tolerance = 0.001)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.