A two-compartment pharmacokinetic (PK) model describes how a drug distributes and is eliminated within the body by assuming the existence of two interconnected compartments. Moving from a one-compartment model to a two-compartment model allows the representation of drugs that do not distribute instantaneously throughout the body. Instead, the drug first enters a highly perfused central compartment and then gradually equilibrates with a peripheral compartment. This mathematical model enables the prediction of drug concentrations over time and supports dose optimization.
The model fits a biexponential concentration-time curve (alpha and beta phases) to observed data and assumes the existence of two compartments:
Central compartment (C1): Includes the blood and highly perfused tissues or vital organs. It is the first compartment reached by the drug, and drug concentrations are measured in this compartment.
Peripheral compartment (C2): Includes other tissues, such as muscle and skin, where the drug distributes more slowly. Low blood perfusion.
Drug movement between compartments is reversible, and elimination usually occurs from the central compartment in an open model.
Drug transfer between compartments is characterized by the following rate constants:
k12: Transfer rate constant from the central(C1) compartment to the peripheral compartment (C1 to C2)
k21: Transfer rate constant from the peripheral(C2) compartment to the central compartment (C2 to C1)
kel (k10): Elimination rate constant from the central compartment (C1 to "Exit").
After administration, the drug enters and distributes within the central compartment and subsequently moves to the peripheral compartment. The concentration–time profile is characterized by two distinct phases:
1) Distribution phase (α): The initial and rapid phase during which the drug distributes from the blood to tissues.
2) Elimination phase (β): The later and slower phase during which the drug is eliminated from the body.
The concentration in the central compartment decreases over time, while the concentration in the peripheral compartment increases, reaches a peak, and subsequently declines as the drug is eliminated.
Two-compartment models are commonly used for drugs that distribute slowly within the body. They are useful for determining appropriate dosing regimens, maintaining therapeutic drug levels, evaluating potential rebound effects when the drug returns from the peripheral to the central compartment, adjusting doses for special populations such as obese patients, older adults, and individuals with liver or kidney impairment, and defining dosing intervals to prevent drug accumulation.
A traditional two-compartment mammillary model consists of a central compartment (Vc), which includes blood (drug concentration Cblood), and a peripheral compartment. Drug transfer between compartments is governed by the rate constants k12 and k21. Drug infusion and elimination are represented by the infusion rate (R0) and clearance (Cl), respectively.
Transfer rate constants (micro-constants):
k12
k21
k10
Volume parameters:
V1: Volume of the central compartment
V2: Volume of the peripheral compartment
Macro parameters (observed in the concentration–time curve):
A: Intercept of the distribution (fast) phase
α (alpha): Rate constant of the distribution phase
B: Intercept of the elimination (slow) phase
β (beta): Rate constant of the elimination phase
By accounting for both distribution and elimination phases, the two-compartment model improves the understanding of drug behavior in the body and contributes to more accurate and individualized dosing decisions.
Source:
Yan D, Wu X, Li J, Tang S. Statistical Analysis of Two-Compartment Pharmacokinetic Models with Drug Non-adherence. Bull Math Biol. 2023 Jun 9;85(7):65. doi: 10.1007/s11538-023-01173-0. PMID: 37294520.
Maung, N. H., Methaneethorn, J., Wattanavijitkul, T., & Sriboonruang, T. (2022). Comparison of area under the curve for vancomycin from one- and two-compartment models using sparse data. European journal of hospital pharmacy : science and practice, 29(e1), e57–e62. https://doi.org/10.1136/ejhpharm-2020-002637
Upton RN. The two-compartment recirculatory pharmacokinetic model--an introduction to recirculatory pharmacokinetic concepts. Br J Anaesth. 2004 Apr;92(4):475-84. doi: 10.1093/bja/aeh089. Epub 2004 Feb 6. PMID: 14766714.
Grasping the mechanisms of drug clearance is essential for ensuring accurate dosing and effectively mitigating toxicological risks. The one-compartment model is a mathematical model used to understand the rate at which a drug is eliminated or redistributed from the blood and to describe drug concentration over time. It is particularly useful for evaluating the drug's elimination rate.
The model assumes that the body consists of a single compartment, represented by the blood (or plasma), and that the drug undergoes a phase of elimination or redistribution. Overall, drug elimination is governed by the combined processes of metabolism and excretion. Elimination may occur through urine, exhaled air, or bile/feces (relies primarily on the liver and kidneys). Under this assumption, the drug enters the compartment, reaches a concentration, and subsequently leaves the compartment through elimination or redistribution.
A key limitation of the one-compartment model is that it does not distinguish between blood (plasma) and tissues. Therefore, when a drug exits the compartment, the model only indicates that it has left the compartment, without specifying whether it was eliminated from the body or redistributed to tissues.
a) First-order kinetics
In first-order kinetics, the rate of elimination is proportional to the drug concentration. Exponential curve decay. As drug concentration decreases, the elimination rate decreases proportionally.
b) Zero-order kinetics
In some cases, the body eliminates a fixed quantity of drug per unit of time, regardless of concentration, producing a linear decline in plasma concentration. Because individual plasma concentrations cannot be accurately predicted by dosage alone, therapeutic drug monitoring (TDM) is required to guide safe adjustments. These unpredictable plasma concentrations increase the risk of treatment failure or toxicity.
c) Michaelis-Menten kinetics
This model combines characteristics of first-order and zero-order kinetics. Produce a hyperbolic curve. When drug concentration (C) is low, elimination approximates first-order kinetics. When concentration is high, elimination approaches zero-order kinetics. Phenytoin is a typical example. Michaelis-Menten kinetics is described by: Elimination = (Vmax · C) / (Km + C)
The one-compartment model is generally applied to drugs that rapidly distribute and equilibrate throughout tissues and body fluids. For compounds following a one-compartment model, the half-life is defined as the time required for half of the chemical to be lost from the plasma.
Source:
Denault D, Patel P, Ashurst JV. Physiology, Zero- and First-Order Kinetics. [Updated 2026 Jan 10]. In: StatPearls [Internet]. Treasure Island (FL): StatPearls Publishing; 2026 Jan-. Available from: https://www.ncbi.nlm.nih.gov/books/NBK499866/
The Receiver Operating Characteristic (ROC) curve is a graphical tool used to evaluate the performance of a diagnostic test or classification model. It is constructed using the sensitivity (true positive rate) and specificity (true negative rate) calculated from a dataset containing both individuals with and without the disease (or positive and negative cases). The AUC systematically counts how many 'duels' between a sick patient and a healthy patient the test manages to score higher for the sick patient — and expresses this as a proportion from 0 to 1. It means, the first step will be calculate and order the predict probabilities. For each cut off possible, there will be calculate the sensitivity and specificity. Then, the probabilities will be compared against the real results. The ROC curve is also commonly used to compare the performance of two or more classification models.
The graph plots:
Y-axis: Sensitivity (True Positive Rate)
X-axis: 1 − Specificity (False Positive Rate)
Both axes range from 0 to 1.
Each point on the ROC curve represents a different decision threshold (cutoff value) used to classify observations as positive or negative. As the threshold changes, the sensitivity and specificity of the model also change.
The diagonal line represents the performance of a model that classifies observations randomly:
Above the diagonal: Performance is better than random chance.
Below the diagonal: Performance is worse than random chance.
An ideal model has a ROC curve that rises quickly toward the upper-left corner, indicating high sensitivity and high specificity. Therefore, when comparing models, the one with the curve closest to the upper-left corner generally provides the best overall classification performance.
The Area Under the Curve (AUC) is the area beneath the ROC curve and provides a single measure of a model's overall ability to discriminate between positive and negative cases. Like the ROC curve, the AUC ranges from 0 to 1.
AUC = 0.5: The model performs no better than random chance.
AUC close to 1.0: The model has excellent discriminatory ability, approaching perfect classification.
AUC = 1.0: The model perfectly distinguishes between positive and negative cases.
A practical interpretation of the AUC is that it represents the probability that the model will assign a higher predicted score to a randomly selected positive case than to a randomly selected negative case. For example, an AUC of 0.73 indicates a 73% probability that the model will correctly rank a positive case above a negative one.
In this example (image), the Youden index cutoff helps classify a test result as either positive or negative for the condition. In a screening scenario, the priority is high sensitivity to avoid missing cases, whereas diagnostic confirmation requires higher specificity to ensure accurate rule-in.
The venn.diagram() function, a cornerstone of the VennDiagram package in R, offers a framework for visualizing the intersections and unique identifiers across multiple datasets. Unlike basic plotting utilities, this function performs precise geometric calculations (cardinality*) to position shapes (ranging from circles for up to three sets to ellipses for higher-dimensional data) based on the underlying cardinality* of the groups.
*cardinality here means count the unique items exist in each specific area.
The function operates on list-based data structures, where it automatically computes:
Set Specificity: The count of unique elements within an individual list.
Intersections: The shared elements across every possible combination of sets.
In summary, once you provide a list or multiple lists, the algorithm counts the unique elements, calculates the shared elements (intersections) between them, and distributes these values across the corresponding sets in the diagram.
Because the package is built upon the grid graphics system, it produces a graphical object known as a grob. While the default behavior is often to write these diagrams directly to a file (such as a .png), they can be rendered immediately within an R console using the grid.draw() command. Bellow, a diagram produced by AI, from this text.
Data rarely arrives in a format that is ready for analysis. As Hadley Wickham aptly notes, “Data is often organized to facilitate some goal other than analysis. For example, it’s common for data to be structured to make data entry, not analysis, easy.” This reality explains why data preparation is not just a preliminary step, but a core part of any analytical workflow.
Preparing data is essential and it is often the most time-consuming stage of an analysis. Yet, the quality of insights you generate depends directly on how well this step is done. Clean, well-structured data allows analysts to explore patterns, build reliable models, and communicate results effectively.
Below are key concepts that every data professional should keep in mind when preparing data, especially when working in R with the tidyverse.
One of the most common data preparation tasks is reshaping datasets.
pivot_wider(names_from = , values_from = )
Converts data from long format to wide format. This is useful for reporting, tables, or when variables need to appear as separate columns.
pivot_longer(names_to = , values_to = )
Converts data from wide format to long format. This format is preferred for most statistical analyses and is especially important for visualization.
👉 Best practice: When creating plots, always work with long-format data. Visualization libraries are designed to work more naturally and consistently with this structure.
Real-world datasets often mix numbers and text in the same column. When this happens:
parse_number()
Use this function inside mutate() to extract numeric values from character strings.
This ensures that values intended for calculations are correctly interpreted as numbers, not text.
A more advanced, but extremely powerful, concept in data reshaping is .value.
.value is a special sentinel used inside the names_to argument of pivot_longer().
It is particularly useful when column names contain multiple pieces of information.
Instead of storing all values in a single column, .value allows part of the column name to remain as actual column headers in the long dataset.
In practice, this means you can reshape complex “wide” datasets while preserving meaningful structure without unnecessary post-processing.
Data preparation is not glamorous, but it is foundational. Understanding how to pivot data correctly, extract clean numeric values, and use advanced tools like .value can dramatically improve both efficiency and analytical clarity.
In a world increasingly driven by data, knowing how to prepare data well is just as important as knowing how to analyze it.
📚 Source: R for Data Science