Skip to contents

Introduction

The following example demonstrates the capabilities of pharmacokinetic-pharmacodynamic (PK/PD) modeling in East Horizon using R integration. We simulate plasma drug concentrations using a one-compartment model with first-order absorption and elimination, then transform concentration to effect via an Emax model to generate continuous outcomes for a two-arm trial (control vs treatment). A final example shows how to integrate externally sourced PK/PD data from a CSV file.

Once CyneRgy is installed, you can load this example in RStudio with the following command:

CyneRgy::RunExample( "PKPDResponseGeneration" )

RStudio Project File: PKPDResponseGeneration.Rproj

In the R directory of this example you will find the following R files:

  1. GenerateDrugConcentration.R - This file contains the R code for simulating drug concentrations for Example 1.

  2. GenerateResponseEmaxModel.R - This file contains the R code to simulate treatment effect responses for patients for Example 2. (Note: Contains GenerateDrugConcentration function inside)

  3. PlotEmax.R - This file plots a visual that shows the mean response for each treatment group as a function of time based on the output of GenerateResponseEmaxModel.R. It is used to create the Emax over visits plot shown in the Example 2 section below.

  4. GeneratePatientFromCSVSpecific.R - This file is able to read in and use simulated patient data from CSV files with a specific formatting style to allow for faster run times. It is used in Example 3.

  5. GeneratePatientFromCSVGeneral.R - This file is able to work in the same way as the specific code, but it has a more general formatting style that leads to slower run times. It is used in Example 3.

  6. GenerateTreatmentControlCSV.R - This file generates CSV files for treatment and control groups based on the simulated patient data. It is used in Example 3.

In the Inputs directory, you will find the following CSV files used in Example 3:

  1. SimPatientDataNull.csv - This file contains simulated patient data with no treatment effect.

  2. SimPatientDataAlt.csv - This file contains simulated patient data with a treatment effect.

Example 1 - Simulate Drug Concentration Response from a One-Compartment Model with First-order Absorption

In the R function GenerateDrugConcentration, we use a one-compartment PK model with first-order absorption to simulate plasma concentrations for patients. The patient outcome is defined as a list of vectors, where the exact number of vectors is determined by the number of visits defined in the function parameters. Each vector contains the drug concentration for each patient at the specified VisitTime. The function also returns an ErrorCode. A value of0 indicates a successful simulation execution, while a value of -1 indicates a failure.

Refer to the table below for the definitions of the user-defined parameters used in this example, along with example values.

User parameter Definition Example value
AbsorptionRate Dose first-order absorption rate constant. Describes the rate at which a drug moves from the site of administration into the central compartment. 1
EliminationRate Dose first-order elimination rate constant. Describes the fraction of drug eliminated from the body per unit of time once the drug is in the central compartment. 0.2
Dose Amount of drug administered to the body at the start of the model. 500

The OneCompartmentModelPK function is called inside the main function, and the deSolve R package will generate a vector of concentrations that are stored inside the vConcentration variable. Then, based on treatment group assignment, the function adds normally distributed noise to the concentration vector using the corresponding group-specific mean and standard deviation.

The figure below illustrates where this example fits within the R integration points of Cytel products, accompanied by a flowchart outlining the general steps performed by the R code.

Example 2 - Simulate Treatment Effect with Emax Model

GenerateResponseEmaxModel.R serves as an extension of GenerateDrugConcentration.R. It converts per-visit plasma concentrations into treatment responses using the Emax PD model. It first calls the PK function to generate drug concentrations per subject per visit, then applies the Emax equation to convert the concentrations to our expected treatment effect:

E=E0+Emax×CpEC50+CpE = E_0 + \frac{E_{\text{max}} \times C_p}{E_{C_{50}} + C_p}

where:

  • EE is the predicted treatment effect (response) at concentration CpC_p.
  • E0E_0 is the baseline effect in the absence of drug (intercept).
  • EmaxE_{\text{max}} is the maximum incremental effect achievable above baseline.
  • CpC_p is the per-visit plasma concentration for a subject generated by the PK step.
  • EC50E_{C_{50}} is the concentration at which 50% of EmaxE_{\text{max}} is achieved.

Responses for control group subjects are simulated from normal distributions defined by the control means and sandard deviations, while treatment subjects receive responses from the Emax-predicted effect with additional variability. The output of this function is shown as visit-level response arrays for all subjects, along with an error code of 0 for success, and an error code of -1 if parameter requirements are not met.

Refer to the table below for the definitions of the user-defined parameters used in this example, along with example values.

User parameter Definition Example value
AbsorptionRate Dose first-order absorption rate constant. Describes the rate at which a drug moves from the site of administration into the central compartment. 1
EliminationRate Dose first-order elimination rate constant. Describes the fraction of drug eliminated from the body per unit of time once the drug is in the central compartment. 0.2
Dose Amount of drug administered to the body at the start of the model. 500
E0 Baseline effect, when there is an absence of the drug. Can also be interpreted as the intercept in an effect vs. concentration graph. 0
Emax Maximum drug effect the system can achieve above baseline. -12
EC50 Drug concentration at which 50% of the maximum effect is achieved. 15

The figure below illustrates where this example fits within the R integration points of Cytel products, accompanied by a flowchart outlining the general steps performed by the R code.

PlotEmax.R was used to plot a visual that shows the mean response for each treatment group as a function of time.

The plot shows simulated responses over five visits for control and treatment groups. Control responses remain around the baseline (~10), while treatment responses start high (~40) and gradually decline, reflecting the Emax effect of the drug as its concentration decreases over time.

Example 3 - Integrating externally sourced PK/PD data from a CSV file

In some situations, you may have pre-simulated patient data from external PK/PD models or other sources that you want to integrate into your trial simulation. This example demonstrates how to read patient responses from a CSV file instead of generating them on-the-fly during each simulation run. This approach offers several advantages: first, reading pre-generated data is much faster than computing complex PK/PD models for each patient in each simulation replicate. Second, using the same CSV file ensures consistent patient data across simulation runs. Finally, you can also leverage data generated from sophisticated external tools or empirical datasets.

The example includes three R files:

  1. GenerateTreatmentControlCSV.R - A helper function that generates sample CSV files with simulated patient data. This is provided to help you test the CSV reading functionality. It creates a CSV file with treatment assignments (0 = control, 1 = treatment) and response values across multiple visits. The function simulates normally distributed responses with an optional treatment effect that grows across visits.

In the Inputs directory of this example, you will find two sample CSV files that were generated using this function:

  • SimPatientDataNull.csv - Contains 500,000 simulated patients with no treatment effect (null hypothesis scenario). Both control and treatment groups have similar response distributions.
  • SimPatientDataAlt.csv - Contains 500,000 simulated patients with a treatment effect (alternative hypothesis scenario). Treatment group shows progressively better responses across visits compared to control.

These files serve as examples of properly formatted CSV data that can be used with the CSV reader functions.

  1. GeneratePatientFromCSVGeneral.R - A flexible CSV reader that accepts various column naming conventions and treatment/control identifiers. This function is more permissive in the CSV formats it accepts:
  • Visit columns: Accepts “Visit X”, “Visit.X”, or “VisitX” (case-insensitive)
  • Treatment column: Accepts “Treatment”, “TreatmentID”, “Trt”, or “TrtID” (case-insensitive)
  • Treatment identifiers: Accepts “1”, “t”, “trt”, “treatment”, or “active” (case-insensitive)
  • Control identifiers: Accepts “0”, “c”, “ctl”, “control”, “placebo”, or “cntl” (case-insensitive)
  • Missing values: Recognizes ““,”NA”, “NaN”, “na”, “null”, or “N/A”
  1. GeneratePatientFromCSVSpecific.R - A faster CSV reader with stricter formatting requirements. This function runs faster than the general version but requires a specific CSV format:
  • Visit columns: Must be named exactly “Visit 1”, “Visit 2”, etc.
  • Treatment column: Must be named “Treatment”
  • Treatment identifiers: Must be “1”
  • Control identifiers: Must be “0”
  • Missing values: Recognizes ““,”NA”, “NaN”, “na”, “null”, or “N/A”

The figure below illustrates where this example fits within the R integration points of Cytel products, accompanied by a flowchart outlining the general steps performed by the R code.

Refer to the table below for the definitions of the user-defined parameter used in this example, along with example values.

User parameter Definition Example value
InputFileName Name of a CSV file (including the .csv extension) that contains the pre-simulated patient data. This file should be uploaded to the Inputs folder of your East Horizon project. SimPatientDataAlt.csv

Using CSV-based Patient Data in East Horizon

To use pre-simulated patient data from a CSV file in your East Horizon simulation, follow these steps:

Step 1: Upload CSV reader R files to Project Root

Upload one of the CSV reader R files to the root folder of your East Horizon project:


Step 2: Upload CSV File to Inputs Folder

Upload your patient data CSV file to the Inputs folder of your East Horizon project. You can use one of the provided example files:


Step 3: Configure Response Card

  1. In East Horizon’s Response card, select “User Specified - R” as your distribution.
  2. In the R code selection, choose the CSV reader R file you uploaded in Step 1.
  3. Set the user parameter InputFileName to the name of your CSV file (include the .csv extension).
    • For example: InputFileName = "SimPatientDataAlt.csv"
  4. Configure the remaining design parameters as desired.
  5. Run the simulation.

Note: Ensure your CSV file contains enough patients for both treatment arms across all simulation replicates. The CSV readers will return an error if an insufficient number of patients are available.