Skip to contents

\leftarrow Go back to the Integration Point: Response page

Input Variables

When creating a custom R script, you can optionally use specific variables provided by East Horizon’s engine itself. These variables are automatically available and do not need to be set by the user, except for the UserParam variable. Refer to the table below for the variables that are available for this integration point and endpoint.

Variable Type Description
NumSub Integer Number of subjects in the trial.
NumArm Integer Number of arms in the trial ﴾including placebo/control, and experimental﴿.
TreatmentID Vector of Integer Vector of length NumSub, indicating the allocation of subjects to arms. Index 0 represents placebo/control. For example, [0, 0, 1] indicates three subjects: two in the control group and one experimental.
EndpointType Vector of Integer Vector of length equal to the number of endpoints, indicating the endpoint types:
0: Continuous.
1: Binary.
2: Time-to-Event.
EndpointName Vector of Character Vector of length equal to the number of endpoints, indicating the endpoint names.
SurvMethod Named List of Integer Named List of length equal to the number of endpoints, indicating the selected input method for survival analysis for survival endpoints. For example, SurvMethod[“Endpoint 1”] is the input method for Endpoint 1. Possible values:
1: Hazard rate.
2: Cumulative % survival rates.
3: Median survival times.
NA: Endpoint is not Time-to-Event (e.g., Binary).
NumPrd Named List of Integer Named List of length equal to the number of endpoints, indicating the number of periods in the trial for survival endpoints. For example, NumPrd[[“Endpoint 1”]] is the number of periods for Endpoint 1. Fixed to NA if the endpoint is not Time-to-Event (e.g., Binary).
PrdTime Named List of Array of Numeric Named List of length equal to the number of endpoints, indicating the times used to specify survival parameters. For example, PrdTime[“Endpoint 1”] is the array of period times for Endpoint 1. The length of each array is the number of periods. Depends on SurvMethod:
– If SurvMethod = 1: Starting times of hazard pieces.
– If SurvMethod = 2: Times at which the cumulative % survivals are specified.
– If SurvMethod = 3: Defaults to 0.
– If the endpoint is not Time-to-Event (e.g., Binary): Defaults to NA.
SurvParam Named List of Matrix Named List of length equal to the number of endpoints, indicating the matric of survival parameters used to generate time of events. For example, SurvParam[“Endpoint 1”] is the 2D matrix of survival parameters for Endpoint 1. The dimension of each matrix is NumPrd x NumArm. Depends on SurvMethod:
– If SurvMethod = 1: Specifies hazard rates per arm per period. Size: NumPrd rows ×\timesNumArm columns, where SurvParam[i, j] represents the hazard rate for the jth arm in the ith period.
– If SurvMethod = 2: Specifies cumulative % survival rates per arm per period. Size: NumPrd rows ×\timesNumArm columns, where SurvParam[i, j] represents the cumulative % survival for the jth arm in the ith period.
– If SurvMethod = 3: Contains median survival times for each arm. Size: 1 row ×\times 2 columns, where column 1 is control and column 2 is experimental.
– If the endpoint is not Time-to-Event (e.g., Binary): Defaults to NA.
PropResp Named List of Vector of Numeric Named List of length equal to the number of endpoints, indicating the expected proportion of responders on each arm for binary endpoints. For example, PropResp[“Endpoint 1”] is the vector of expected proportions of responders on each arm for Endpoint 1. The length of each vector is NumArm. Fixed to NA if the endpoint is not Binary (e.g., Time-to-Event). Only applicable when Dual Endpoint = TTE-Binary.
Correlation Integer Correlation between the endpoints:
5: Very strong positive.
4: Strong positive.
3: Moderate positive.
2: Weak positive.
1: Very weak positive.
0: Uncorrelated.
-1: Very weak negative.
-2: Weak negative.
-3: Moderate negative.
-4: Strong negative.
-5: Very strong negative.
UserParam List Contains all user-defined parameters specified in the East Horizon interface (refer to the Instructions section). To access these parameters in your R code, use the syntax: UserParam$NameOfTheVariable, replacing NameOfTheVariable with the appropriate parameter name.

Note: “Endpoint 1” is used as a sample endpoint name. It will be the actual endpoint name as specified by the user.

Expected Output Variable

East Horizon expects an output of a specific type. Refer to the table below for the expected output for this integration point:

Type Description
List A named list containing SurvivalTime and ErrorCode.

Expected Members of the Output List

Members Type Description
Response Named List of Vector of Numeric Named List of length equal to the number of endpoints, containing the survival time outputs for each endpoint. For example, Response[“Endpoint 1”] is the vector of generated response values for each subject for Endpoint 1. The length of each vector is NumSub.
ErrorCode Integer Optional. Can be used to handle errors in your script:
0: No error.
Positive Integer: Nonfatal error, the current simulation will be aborted, but the next simulation will proceed.
Negative Integer: Fatal error, no further simulations will be attempted.

Note: Additional custom variables can be included as members of the output list. All outputs will automatically be available as input variables for analysis or treatment selection endpoints in the SimData variable as described here: Variables of SimData.

Minimal Template

Your R script could contain a function such as this one, with a name of your choice. All applicable input variables must be declared, even if they are not used in the script. Input variables that are not applicable (depending on TTE-TTE vs. TTE-Binary) must not be declared. We recommend always declaring UserParam as a default NULL value in the function arguments, as this will ensure that the same function will work regardless of whether the user has specified any custom parameters in East Horizon.

A detailed template with step-by-step explanations is available here: SimulatePatientOutcome.DEP.R.

For Dual Endpoint = TTE-TTE

GenerateResponse <- function( NumSub, NumArm, TreatmentID, EndpointType, EndpointName,
                              SurvMethod, NumPrd, PrdTime, SurvParam, Correlation, UserParam = NULL )
{
  nError            <- 0 # Error handling (no error)
  
  Response          <- list()
  Response[[EndpointName[[1]]]] <- rep( 0, NumSub ) # Initializing survival times array of the first endpoint to 0
  Response[[EndpointName[[2]]]] <- rep( 0, NumSub ) # Initializing survival times array of the second endpoint to 0
  
  # Write the actual code here.
  # Store the generated survival times values in each array of the list Response.

  return( list( Response = as.list( vResponse ), ErrorCode = as.integer( nError ) ) )
}

For Dual Endpoint = TTE-Binary

GenerateResponse <- function( NumSub, NumArm, TreatmentID, EndpointType, EndpointName,
                              SurvMethod, NumPrd, PrdTime, SurvParam, PropResp, Correlation, UserParam = NULL )
{
  nError            <- 0 # Error handling (no error)
  
  Response          <- list()
  Response[[EndpointName[[1]]]] <- rep( 0, NumSub ) # Initializing survival times array of the first endpoint to 0
  Response[[EndpointName[[2]]]] <- rep( 0, NumSub ) # Initializing survival times array of the second endpoint to 0
  
  # Write the actual code here.
  # Store the generated survival times values in each array of the list Response.

  return( list( Response = as.list( vResponse ), ErrorCode = as.integer( nError ) ) )
}

Examples

Explore the following examples for more context:

  1. 2-Arm, Dual Endpoints - Patient Simulation