| Title: | Framework for Patient-Level Microsimulation of Risk Factor Trajectories & Hazard-Based Events |
|---|---|
| Description: | Fast, flexible, patient-level microsimulation. Time-stepped simulation with a 'C++' back-end from user-supplied initial population, trajectories, hazards, and corresponding event transitions. User-defined aggregate time series histories are returned together with the final population. Designed for simulation of chronic diseases with continuous and evolving risk factors, but could easily be applied more generally. |
| Authors: | Pete Dodd [aut, cre] (ORCID: <https://orcid.org/0000-0001-5825-9347>), Robert Chisholm [aut] (ORCID: <https://orcid.org/0000-0002-6983-2759>), University of Sheffield [cph], Horizon Europe [fnd] |
| Maintainer: | Pete Dodd <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.4 |
| Built: | 2026-09-16 11:41:29 UTC |
| Source: | https://github.com/cran/golden |
This dataset contains example fits of body mass index (BMI) to gamma distributions for the United States in 2022. The original data were taken from an analysis of the contribution of undernutrition to tuberculosis incidence, which was published in the Lancet Global Health in 2026. The data on which these fits are based is from the NCD Risk Factor Collaboration (NCD-RisC) estimates dataset.
bmi_fitsbmi_fits
A data.frame/data.table with 28 rows and 4 variables:
Biological sex ('char'): Men, Women
Age category in years ('char'): 0-4, 5-9, ..., 85plus
Gamma distribution shape parameter ('num'): k > 0
Gamma distribution scale parameter ('num'): theta > 0
https://github.com/petedodd/bmitb
Validate an history column object If validation fails, an exception will be raised.
check_column(column, initPop = NULL)check_column(column, initPop = NULL)
column |
An S3 object of class "golden_history_column" |
initPop |
(Optional) data.table to check columns required by functions exist |
No return value, called for side effects.
library(data.table) dt <- data.table(a = rep(0, 100)) # Create an S3 golden_history_column col <- new_column("sum_a", sum, c("a")) # check_column() will not throw an exception # as col is a valid S3 golden_history_column # and dt contains column "a" check_column(col, dt)library(data.table) dt <- data.table(a = rep(0, 100)) # Create an S3 golden_history_column col <- new_column("sum_a", sum, c("a")) # check_column() will not throw an exception # as col is a valid S3 golden_history_column # and dt contains column "a" check_column(col, dt)
Validate an hazard object If validation fails, an exception will be raised.
check_hazard(hazard, initPop = NULL)check_hazard(hazard, initPop = NULL)
hazard |
An S3 object of class "golden_hazard" |
initPop |
(Optional) data.table to check columns required by functions exist |
No return value, called for side effects.
library(data.table) N <- 100 dt <- data.table(a = runif(N, 0, 1), b = rep(0, N)) # Define a hazard function, which returns a vector of equal length uncertainties test_hazard <- function(a) { ret <- (a < 0.5) } # Define a transition function, which sets all "b" columns affected by the hazard to 100 test_transition <- function() { return (100) } # Create an S3 golden_hazard haz <- new_hazard( test_hazard, c("a"), new_transition(test_transition, c(), "b") ) # check_hazard() will not throw an exception # as haz is a valid S3 golden_hazard # and dt contains column "a" check_hazard(haz, dt)library(data.table) N <- 100 dt <- data.table(a = runif(N, 0, 1), b = rep(0, N)) # Define a hazard function, which returns a vector of equal length uncertainties test_hazard <- function(a) { ret <- (a < 0.5) } # Define a transition function, which sets all "b" columns affected by the hazard to 100 test_transition <- function() { return (100) } # Create an S3 golden_hazard haz <- new_hazard( test_hazard, c("a"), new_transition(test_transition, c(), "b") ) # check_hazard() will not throw an exception # as haz is a valid S3 golden_hazard # and dt contains column "a" check_hazard(haz, dt)
Validate an history object If validation fails, an exception will be raised.
check_history(history, initPop = NULL)check_history(history, initPop = NULL)
history |
An S3 object of class "golden_history" |
initPop |
(Optional) data.table to check columns required by functions exist |
No return value, called for side effects.
library(data.table) dt <- data.table(a = rep(0, 100)) # Create an S3 golden_history, containing 1 golden_history_column hist <- new_history(new_column("sum_a", sum, c("a"))) # check_history() will not throw an exception # as hist is a valid S3 golden_history # and dt contains column "a" used by the column check_history(hist, dt)library(data.table) dt <- data.table(a = rep(0, 100)) # Create an S3 golden_history, containing 1 golden_history_column hist <- new_history(new_column("sum_a", sum, c("a"))) # check_history() will not throw an exception # as hist is a valid S3 golden_history # and dt contains column "a" used by the column check_history(hist, dt)
Validate the configuration passed to run_simulation() If validation fails, an exception will be raised.
check_parameters(parameters, initPop = NULL)check_parameters(parameters, initPop = NULL)
parameters |
An golden_parameters S3 object to be validated |
initPop |
data.frame which contains the columns required by parameters |
No return value, called for side effects.
library(data.table) N <- 100 dt <- data.table(a = runif(N, 0, 1), b = rep(0, N)) # Define a hazard function, which returns a vector of equal length uncertainties test_hazard <- function(a) { ret <- (a < 0.5) } # Define a transition function, which sets all "b" columns affected by the hazard to 100 test_transition <- function() { return (100) } # Create an S3 golden_hazard haz <- new_hazard( test_hazard, c("a"), new_transition(test_transition, c(), "b") ) # Define a trajectory function, which adds 2 to all members of the input vector test_trajectory <- function(a) { return (a + 2) } # Create an S3 golden_trajectory trj <- new_trajectory(test_trajectory, c("b"), "b") # Create an S3 golden_history, containing 1 golden_history_column hist <- new_history(new_column("sum_a", sum, c("a"))) # Create an S3 golden_parameters params <- new_parameters( hazards = haz, trajectories = trj, steps = 10, debug = FALSE, history = hist ) # check_parameters() will not throw an exception # as params is a valid S3 golden_parameters # and dt contains columns "a" and "b" check_parameters(params, dt)library(data.table) N <- 100 dt <- data.table(a = runif(N, 0, 1), b = rep(0, N)) # Define a hazard function, which returns a vector of equal length uncertainties test_hazard <- function(a) { ret <- (a < 0.5) } # Define a transition function, which sets all "b" columns affected by the hazard to 100 test_transition <- function() { return (100) } # Create an S3 golden_hazard haz <- new_hazard( test_hazard, c("a"), new_transition(test_transition, c(), "b") ) # Define a trajectory function, which adds 2 to all members of the input vector test_trajectory <- function(a) { return (a + 2) } # Create an S3 golden_trajectory trj <- new_trajectory(test_trajectory, c("b"), "b") # Create an S3 golden_history, containing 1 golden_history_column hist <- new_history(new_column("sum_a", sum, c("a"))) # Create an S3 golden_parameters params <- new_parameters( hazards = haz, trajectories = trj, steps = 10, debug = FALSE, history = hist ) # check_parameters() will not throw an exception # as params is a valid S3 golden_parameters # and dt contains columns "a" and "b" check_parameters(params, dt)
Validate an trajectory object If validation fails, an exception will be raised.
check_trajectory(trajectory, initPop = NULL)check_trajectory(trajectory, initPop = NULL)
trajectory |
An S3 object of class "golden_trajectory" |
initPop |
(Optional) data.table to check columns required by functions exist |
No return value, called for side effects.
library(data.table) dt <- data.table(b = rep(0, 100)) # Define a trajectory function, which adds 2 to all members of the input vector test_trajectory <- function(a) { return (a + 2) } # Create an S3 golden_trajectory trj <- new_trajectory(test_trajectory, c("b"), "b") # check_trajectory() will not throw an exception # as trj is a valid S3 golden_trajectory # and dt contains column "b" check_trajectory(trj, dt)library(data.table) dt <- data.table(b = rep(0, 100)) # Define a trajectory function, which adds 2 to all members of the input vector test_trajectory <- function(a) { return (a + 2) } # Create an S3 golden_trajectory trj <- new_trajectory(test_trajectory, c("b"), "b") # check_trajectory() will not throw an exception # as trj is a valid S3 golden_trajectory # and dt contains column "b" check_trajectory(trj, dt)
Validate an transition object If validation fails, an exception will be raised.
check_transition(transition, initPop = NULL)check_transition(transition, initPop = NULL)
transition |
An S3 object of class "golden_transition" |
initPop |
(Optional) data.table to check columns required by functions exist |
No return value, called for side effects.
library(data.table) dt <- data.table(b = rep(0, 100)) # Define a transition function, which sets all columns affected by the hazard to 100 test_transition <- function() { return (100) } # Define an S3 golden_transition trn <- new_transition(test_transition, c(), "b") # check_transition() will not throw an exception # as trn is a valid S3 golden_transition # and dt contains column "b" check_transition(trn, dt)library(data.table) dt <- data.table(b = rep(0, 100)) # Define a transition function, which sets all columns affected by the hazard to 100 test_transition <- function() { return (100) } # Define an S3 golden_transition trn <- new_transition(test_transition, c(), "b") # check_transition() will not throw an exception # as trn is a valid S3 golden_transition # and dt contains column "b" check_transition(trn, dt)
Temporary testing method, probably replaced in future with R's simdata package or similar
create_cohort(demog, N)create_cohort(demog, N)
demog |
Demographic information containing columns AgeGrp/PopMale/PopFemale/PopTotal |
N |
Size of the population to generate |
A sample population data.table, with columns male/age/bmi/death
library(data.table) demog <- data.table( AgeGrp = c(0, 1, 2, 3), PopMale = c(1000, 1100, 1050, 980), PopFemale = c(950, 1020, 1005, 970) ) demog[, PopTotal := PopMale + PopFemale] cohort <- create_cohort(demog, 100)library(data.table) demog <- data.table( AgeGrp = c(0, 1, 2, 3), PopMale = c(1000, 1100, 1050, 980), PopFemale = c(950, 1020, 1005, 970) ) demog[, PopTotal := PopMale + PopFemale] cohort <- create_cohort(demog, 100)
Example data on cardiovascular disease (CVD) risk from the Globorisk model, which is a model for estimating 10-year risk of fatal and non-fatal CVD events, see:
https://doi.org/10.1016/S2213-8587(17)30015-3 https://doi.org/10.1016/S2213-8587(15)00081-9
These data are available in the 'globorisk' R package, see the source link below. This subset is for the United States, and contains the coefficients for the risk prediction equations.
The exact extraction of these data from the 'globorisk' package is in the 'data-raw/dataprep.R' file in this package.
globorisk_coefsgloborisk_coefs
A data.frame/data.table with 1 rows and 18 variables:
Risk model type ('char', set to "office").
Coefficient for centered and scaled systolic blood pressure ('num').
Coefficient for centered and scaled total cholesterol ('num').
Variable not used in this model, but included as 'NA' for completeness ('num').
Variable not used in this model, but included as 'NA' for completeness ('num').
Variable not used in this model, but included as 'NA' for completeness ('num').
Variable not used in this model, but included as 'NA' for completeness ('num').
Coefficient for centered and scaled systolic blood pressure by age interaction term ('num').
Variable not used in this model, but included as 'NA' for completeness ('num').
Variable not used in this model, but included as 'NA' for completeness ('num').
Variable not used in this model, but included as 'NA' for completeness ('num').
Coefficient for centered and scaled body mass index (BMI) ('num').
Coefficient for centered and scaled smoking status ('num').
Coefficient for centered and scaled smoking by sex interaction term ('num').
Coefficient for centered and scaled smoking status by age interaction term ('num').
Coefficient for centered and scaled BMI by age interaction term ('num').
Variable not used in this model, but included as 'NA' for completeness ('num').
Globorisk use Local Area Countries flag ('num', set to 0).
https://github.com/boyercb/globorisk
Example data on cardiovascular disease (CVD) risk from the Globorisk model, which is a model for estimating 10-year risk of fatal and non-fatal CVD events, see:
https://doi.org/10.1016/S2213-8587(17)30015-3 https://doi.org/10.1016/S2213-8587(15)00081-9
These data are available in the 'globorisk' R package, see the source link below. This subset is for the United States in 2000, and contains the baseline hazard.
The exact extraction of these data from the 'globorisk' package is in the 'data-raw/dataprep.R' file in this package.
globorisk_cvdrgloborisk_cvdr
A data.frame/data.table with 20 rows and 4 variables:
Age category ('int'): 1,...,10.
Sex ('int'): 0, 1.
Baseline hazard per year for CVD events ('num').
Age and sex concatenated category ('char'): "1_0", "1_1", ..., "10_1".
https://github.com/boyercb/globorisk
Example data on cardiovascular disease (CVD) risk from the Globorisk model, which is a model for estimating 10-year risk of fatal and non-fatal CVD events, see:
https://doi.org/10.1016/S2213-8587(17)30015-3 https://doi.org/10.1016/S2213-8587(15)00081-9
These data are available in the 'globorisk' R package, see the source link below. This subset is for the United States, and contains the reference values for centering.
The exact extraction of these data from the 'globorisk' package is in the 'data-raw/dataprep.R' file in this package.
globorisk_rfgloborisk_rf
A data.frame/data.table with 18 rows and 9 variables:
ISO country code ('char'): "USA".
Age category ('int'): 1,...,10.
Sex ('int'): 0, 1.
Systolic blood pressure mean value for centering ('num').
Total cholesterol mean value for centering ('num').
Diabetes mean value for centering ('num').
Smoking status mean value for centering ('num').
Body mass index mean value for centering ('num').
Age and sex concatenated category ('char'): "1_0", "1_1", ..., "9_1".
https://github.com/boyercb/globorisk
Fast, flexible, patient-level microsimulation. Time-stepped simulation with a 'C++' back-end from user-supplied initial population, trajectories, hazards, and corresponding event transitions. User-defined aggregate time series histories are returned together with the final population. Designed for simulation of chronic diseases with continuous and evolving risk factors, but could easily be applied more generally.
Maintainer: Pete Dodd [email protected] (ORCID)
Authors:
Robert Chisholm [email protected] (ORCID)
Other contributors:
University of Sheffield [copyright holder]
Horizon Europe [funder]
## Not run: # A full example can be found in the vignettes ## End(Not run)## Not run: # A full example can be found in the vignettes ## End(Not run)
Example life table data for the United States from 2000 to 2100, with age-specific mortality rates for each sex and in total. The original data were taken from the World Population Prospects 2024 revision, which is published by the United Nations Department of Economic and Social Affairs, Population Division.
https://population.un.org/wpp/
The data on which these life tables are based is from the WPP 2024 revision, as made available through the 'wpp2024' R package available from the source below. The exact extraction of these data from the WPP 2024 revision is in the 'data-raw/dataprep.R' file in this package.
lifetable_datalifetable_data
A data.frame/data.table with 10,201 rows and 5 variables:
The year of the life table data ('integer'), ranging from 2000 to 2100.
The age group for the life table data ('integer'), ranging from 0 to 100.
Actuarial mortality for men; age-specific hazard of death ('num').
Actuarial mortality for women; age-specific hazard of death ('num').
Actuarial mortality for both sexes combined; age-specific hazard of death ('num').
https://github.com/PPgp/wpp2024
Create a new golden_history_column
new_column(name, fn, args, filter_fn = NULL, filter_args = NULL)new_column(name, fn, args, filter_fn = NULL, filter_args = NULL)
name |
Name of the column in the output data-table |
fn |
Reduction function, which converts the input columns to a single value |
args |
Names of columns and special variables to be passed to fn |
filter_fn |
(Optional) Filter function, which returns a bool vector denoting which rows should be reduced |
filter_args |
(Optional) Names of columns and special variables to be passed to filter_fn. Required if filter_fn is |
An object of class "golden_history_column"
# Create an S3 golden_history_column named "sum_a", using sum(). with column "a" col <- new_column("sum_a", sum, c("a"))# Create an S3 golden_history_column named "sum_a", using sum(). with column "a" col <- new_column("sum_a", sum, c("a"))
Create a new hazard object
new_hazard( fn, args, transitions, freq = 1, first = 1, last = 2147483647, name = NULL )new_hazard( fn, args, transitions, freq = 1, first = 1, last = 2147483647, name = NULL )
fn |
Function which calculates the hazard likelihood |
args |
Character vector of parameter names expected by fn |
transitions |
Transition object(s) to be applied where the hazard is successful |
freq |
(Optional) The frequency of hazard execution, hazards always execute on first step |
first |
(Optional) First step the hazard should be enabled (initial step is index 1) |
last |
(Optional) Last step the hazard should be enabled (initial step is index 1) |
name |
(Optional) Name used in error messages and similar. Defaults to an automatic name |
An object of class "golden_hazard"
# Define a hazard function, which returns a vector of equal length uncertainties test_hazard <- function(a) { ret <- (a < 0.5) } # Define a transition function, which sets all "b" columns affected by the hazard to 100 test_transition <- function() { return (100) } # Create an S3 golden_hazard haz <- new_hazard( test_hazard, c("a"), new_transition(test_transition, c(), "b") )# Define a hazard function, which returns a vector of equal length uncertainties test_hazard <- function(a) { ret <- (a < 0.5) } # Define a transition function, which sets all "b" columns affected by the hazard to 100 test_transition <- function() { return (100) } # Create an S3 golden_hazard haz <- new_hazard( test_hazard, c("a"), new_transition(test_transition, c(), "b") )
Create a new golden_history
new_history(columns, frequency = 1)new_history(columns, frequency = 1)
columns |
golden_history_column S3 object(s) |
frequency |
The number of simulation steps per history collection. |
An object of class "golden_history"
# Create an S3 golden_history, containing 1 golden_history_column hist <- new_history(new_column("sum_a", sum, c("a")))# Create an S3 golden_history, containing 1 golden_history_column hist <- new_history(new_column("sum_a", sum, c("a")))
Create a new golden_parameters
new_parameters( hazards = list(), trajectories = list(), steps, random_seed = 0, debug = TRUE, print_timing = TRUE, history = NULL )new_parameters( hazards = list(), trajectories = list(), steps, random_seed = 0, debug = TRUE, print_timing = TRUE, history = NULL )
hazards |
golden_hazard S3 object(s) |
trajectories |
golden_trajectory S3 object(s) |
steps |
Number of steps to run |
random_seed |
Seed to be used for random generation. If set 0, current R random state will be used. |
debug |
(TRUE/FALSE) flag indicating whether validation checks are enabled. These catch NaN, but reduce performance |
print_timing |
(TRUE/FALSE) flag indicating whether a per-function timing report should be printed after the simulation, this will always be suppressed for fast (<= 1 second) simulations. |
history |
golden_history S3 object representing the columns of data to be aggregated during simulation |
An object of class "golden_parameters"
# Define a hazard function, which returns a vector of equal length uncertainties test_hazard <- function(a) { ret <- (a < 0.5) } # Define a transition function, which sets all "b" columns affected by the hazard to 100 test_transition <- function() { return (100) } # Create an S3 golden_hazard haz <- new_hazard( test_hazard, c("a"), new_transition(test_transition, c(), "b") ) # Define a trajectory function, which adds 2 to all members of the input vector test_trajectory <- function(a) { return (a + 2) } # Create an S3 golden_trajectory trj <- new_trajectory(test_trajectory, c("b"), "b") # Create an S3 golden_history, containing 1 golden_history_column hist <- new_history(new_column("sum_a", sum, c("a"))) # Create an S3 golden_parameters params <- new_parameters( hazards = haz, trajectories = trj, steps = 10, debug = FALSE, history = hist )# Define a hazard function, which returns a vector of equal length uncertainties test_hazard <- function(a) { ret <- (a < 0.5) } # Define a transition function, which sets all "b" columns affected by the hazard to 100 test_transition <- function() { return (100) } # Create an S3 golden_hazard haz <- new_hazard( test_hazard, c("a"), new_transition(test_transition, c(), "b") ) # Define a trajectory function, which adds 2 to all members of the input vector test_trajectory <- function(a) { return (a + 2) } # Create an S3 golden_trajectory trj <- new_trajectory(test_trajectory, c("b"), "b") # Create an S3 golden_history, containing 1 golden_history_column hist <- new_history(new_column("sum_a", sum, c("a"))) # Create an S3 golden_parameters params <- new_parameters( hazards = haz, trajectories = trj, steps = 10, debug = FALSE, history = hist )
Create a new trajectory object
new_trajectory(fn, args, states, name = NULL)new_trajectory(fn, args, states, name = NULL)
fn |
Function defining the trajectory function |
args |
Character vector of parameter names expected by fn |
states |
Name(s) of the column(s) where the result(s) of the trajectory function is to be stored |
name |
(Optional) Name used in error messages and similar. Defaults to an automatic name |
An object of class "golden_trajectory"
If a list if passed to states, fn must return a list of equal length
# Define a trajectory function, which adds 2 to all members of the input vector test_trajectory <- function(a) { return (a + 2) } # Create an S3 golden_trajectory trj <- new_trajectory(test_trajectory, c("b"), "b")# Define a trajectory function, which adds 2 to all members of the input vector test_trajectory <- function(a) { return (a + 2) } # Create an S3 golden_trajectory trj <- new_trajectory(test_trajectory, c("b"), "b")
Create a new transition object
new_transition(fn, args, states, name = NULL)new_transition(fn, args, states, name = NULL)
fn |
Function defining the transition functions |
args |
Character vector of parameter names expected by fn |
states |
Name(s) of the column(s) where the result of the transition function is to be stored |
name |
(Optional) Name used in error messages and similar. Defaults to an automatic name |
An object of class "golden_transition"
# Define a transition function, which sets all columns affected by the hazard to 100 test_transition <- function() { return (100) } # Define an S3 golden_transition trn <- new_transition(test_transition, c(), "b")# Define a transition function, which sets all columns affected by the hazard to 100 test_transition <- function() { return (100) } # Define an S3 golden_transition trn <- new_transition(test_transition, c(), "b")
Example population data for the United States for 2000, with age-specific populations in thousands. The original data were taken from the World Population Prospects 2024 revision, which is published by the United Nations Department of Economic and Social Affairs, Population Division.
https://population.un.org/wpp/
The data on which these population data are based is from the WPP 2024 revision, as made available through the 'wpp2024' R package available from the source below. The exact extraction of these data from the WPP 2024 revision is in the 'data-raw/dataprep.R' file in this package.
pop_snapshotpop_snapshot
A matrix with 101 rows and 2 columns:
Named first matrix colum: the male population in thousands for each age group, with rows for ages 0 to 100 years.
Named second matrix column: the female population in thousands for each age group, with rows for ages 0 to 100 years.
https://github.com/PPgp/wpp2024
Print the contents of a golden_hazard type S3 object
## S3 method for class 'golden_hazard' print(x, ..., indent = 0L)## S3 method for class 'golden_hazard' print(x, ..., indent = 0L)
x |
The object to be printed |
... |
Not used. Included for S3 method compatibility. |
indent |
(Optional) The level the printing is indented, useful if nested within another S3 object |
No return value, called for side effects.
# Define a hazard function, which returns a vector of equal length uncertainties test_hazard <- function(a) { ret <- (a < 0.5) } # Define a transition function, which sets all "b" columns affected by the hazard to 100 test_transition <- function() { return (100) } # Create an S3 golden_hazard haz <- new_hazard( test_hazard, c("a"), new_transition(test_transition, c(), "b") ) print(haz)# Define a hazard function, which returns a vector of equal length uncertainties test_hazard <- function(a) { ret <- (a < 0.5) } # Define a transition function, which sets all "b" columns affected by the hazard to 100 test_transition <- function() { return (100) } # Create an S3 golden_hazard haz <- new_hazard( test_hazard, c("a"), new_transition(test_transition, c(), "b") ) print(haz)
Print the contents of a golden_history type S3 object
## S3 method for class 'golden_history' print(x, ..., indent = 0L)## S3 method for class 'golden_history' print(x, ..., indent = 0L)
x |
The object to be printed |
... |
Not used. Included for S3 method compatibility. |
indent |
(Optional) The level the printing is indented, useful if nested within another S3 object |
No return value, called for side effects.
# Create an S3 golden_history hist <- new_history(new_column("sum_a", sum, c("a"))) print(hist)# Create an S3 golden_history hist <- new_history(new_column("sum_a", sum, c("a"))) print(hist)
Print the contents of a golden_history_column type S3 object
## S3 method for class 'golden_history_column' print(x, ..., indent = 0L)## S3 method for class 'golden_history_column' print(x, ..., indent = 0L)
x |
The object to be printed |
... |
Not used. Included for S3 method compatibility. |
indent |
(Optional) The level the printing is indented, useful if nested within another S3 object |
No return value, called for side effects.
# Create an S3 golden_history_column col <- new_column("sum_a", sum, c("a")) print(col)# Create an S3 golden_history_column col <- new_column("sum_a", sum, c("a")) print(col)
Print the contents of a golden_parameters type S3 object
## S3 method for class 'golden_parameters' print(x, ..., indent = 0)## S3 method for class 'golden_parameters' print(x, ..., indent = 0)
x |
The object to be printed |
... |
Not used. Included for S3 method compatibility. |
indent |
(Optional) The level the printing is indented, useful if nested within another S3 object |
No return value, called for side effects.
# Define a hazard function, which returns a vector of equal length uncertainties test_hazard <- function(a) { ret <- (a < 0.5) } # Define a transition function, which sets all "b" columns affected by the hazard to 100 test_transition <- function() { return (100) } # Create an S3 golden_hazard haz <- new_hazard( test_hazard, c("a"), new_transition(test_transition, c(), "b") ) # Define a trajectory function, which adds 2 to all members of the input vector test_trajectory <- function(a) { return (a + 2) } # Create an S3 golden_trajectory trj <- new_trajectory(test_trajectory, c("b"), "b") # Create an S3 golden_history, containing 1 golden_history_column hist <- new_history(new_column("sum_a", sum, c("a"))) # Create an S3 golden_parameters params <- new_parameters( hazards = haz, trajectories = trj, steps = 10, debug = FALSE, history = hist ) print(params)# Define a hazard function, which returns a vector of equal length uncertainties test_hazard <- function(a) { ret <- (a < 0.5) } # Define a transition function, which sets all "b" columns affected by the hazard to 100 test_transition <- function() { return (100) } # Create an S3 golden_hazard haz <- new_hazard( test_hazard, c("a"), new_transition(test_transition, c(), "b") ) # Define a trajectory function, which adds 2 to all members of the input vector test_trajectory <- function(a) { return (a + 2) } # Create an S3 golden_trajectory trj <- new_trajectory(test_trajectory, c("b"), "b") # Create an S3 golden_history, containing 1 golden_history_column hist <- new_history(new_column("sum_a", sum, c("a"))) # Create an S3 golden_parameters params <- new_parameters( hazards = haz, trajectories = trj, steps = 10, debug = FALSE, history = hist ) print(params)
Print the contents of a golden_timing type S3 object
## S3 method for class 'golden_timing' print(x, ...)## S3 method for class 'golden_timing' print(x, ...)
x |
The object to be printed |
... |
Not used. Included for S3 method compatibility. |
No return value, called for side effects.
library(data.table) N <- 100 dt <- data.table(a = runif(N, 0, 1), b = rep(0, N)) # Define a hazard function, which returns a vector of equal length uncertainties test_hazard <- function(a) { ret <- (a < 0.5) } # Define a transition function, which sets all "b" columns affected by the hazard to 100 test_transition <- function() { return (100) } # Create an S3 golden_hazard haz <- new_hazard( test_hazard, c("a"), new_transition(test_transition, c(), "b") ) # Define a trajectory function, which adds 2 to all members of the input vector test_trajectory <- function(a) { return (a + 2) } # Define an S3 golden_trajectory trj <- new_trajectory(test_trajectory, c("b"), "b") # Create an S3 golden_history, containing 1 golden_history_column hist <- new_history(new_column("sum_a", sum, c("a"))) # Define an S3 golden_parameters params <- new_parameters( hazards = haz, trajectories = trj, steps = 10, debug = FALSE, history = hist ) # Run the simulation to collect results results <- run_simulation(dt, params) print(results$timing)library(data.table) N <- 100 dt <- data.table(a = runif(N, 0, 1), b = rep(0, N)) # Define a hazard function, which returns a vector of equal length uncertainties test_hazard <- function(a) { ret <- (a < 0.5) } # Define a transition function, which sets all "b" columns affected by the hazard to 100 test_transition <- function() { return (100) } # Create an S3 golden_hazard haz <- new_hazard( test_hazard, c("a"), new_transition(test_transition, c(), "b") ) # Define a trajectory function, which adds 2 to all members of the input vector test_trajectory <- function(a) { return (a + 2) } # Define an S3 golden_trajectory trj <- new_trajectory(test_trajectory, c("b"), "b") # Create an S3 golden_history, containing 1 golden_history_column hist <- new_history(new_column("sum_a", sum, c("a"))) # Define an S3 golden_parameters params <- new_parameters( hazards = haz, trajectories = trj, steps = 10, debug = FALSE, history = hist ) # Run the simulation to collect results results <- run_simulation(dt, params) print(results$timing)
Print the contents of a golden_trajectory type S3 object
## S3 method for class 'golden_trajectory' print(x, ..., indent = 0L)## S3 method for class 'golden_trajectory' print(x, ..., indent = 0L)
x |
The object to be printed |
... |
Not used. Included for S3 method compatibility. |
indent |
(Optional) The level the printing is indented, useful if nested within another S3 object |
No return value, called for side effects.
# Define a trajectory function, which adds 2 to all members of the input vector test_trajectory <- function(a) { return (a + 2) } # Create an S3 golden_trajectory trj <- new_trajectory(test_trajectory, c("b"), "b") print(trj)# Define a trajectory function, which adds 2 to all members of the input vector test_trajectory <- function(a) { return (a + 2) } # Create an S3 golden_trajectory trj <- new_trajectory(test_trajectory, c("b"), "b") print(trj)
Print the contents of a golden_transition type S3 object
## S3 method for class 'golden_transition' print(x, ..., indent = 0L)## S3 method for class 'golden_transition' print(x, ..., indent = 0L)
x |
The object to be printed |
... |
Not used. Included for S3 method compatibility. |
indent |
(Optional) The level the printing is indented, useful if nested within another S3 object |
No return value, called for side effects.
# Define a transition function, which sets all columns affected by the hazard to 100 test_transition <- function() { return (100) } # Define an S3 golden_transition trn <- new_transition(test_transition, c(), "b") print(trn)# Define a transition function, which sets all columns affected by the hazard to 100 test_transition <- function() { return (100) } # Define an S3 golden_transition trn <- new_transition(test_transition, c(), "b") print(trn)
Execute a patient trajectory simulation
run_simulation(initPop, parameters)run_simulation(initPop, parameters)
initPop |
data.table containing initial population for simulation |
parameters |
Simulation configuration |
An list containing final population, history and timing data.tables
library(data.table) N <- 100 dt <- data.table(a = runif(N, 0, 1), b = rep(0, N)) # Define a hazard function, which returns a vector of equal length uncertainties test_hazard <- function(a) { ret <- (a < 0.5) } # Define a transition function, which sets all "b" columns affected by the hazard to 100 test_transition <- function() { return (100) } # Create an S3 golden_hazard haz <- new_hazard( test_hazard, c("a"), new_transition(test_transition, c(), "b") ) # Define a trajectory function, which adds 2 to all members of the input vector test_trajectory <- function(a) { return (a + 2) } # Define an S3 golden_trajectory trj <- new_trajectory(test_trajectory, c("b"), "b") # Create an S3 golden_history, containing 1 golden_history_column hist <- new_history(new_column("sum_a", sum, c("a"))) # Define an S3 golden_parameters params <- new_parameters( hazards = haz, trajectories = trj, steps = 10, debug = FALSE, history = hist ) # Run the simulation to collect results results <- run_simulation(dt, params)library(data.table) N <- 100 dt <- data.table(a = runif(N, 0, 1), b = rep(0, N)) # Define a hazard function, which returns a vector of equal length uncertainties test_hazard <- function(a) { ret <- (a < 0.5) } # Define a transition function, which sets all "b" columns affected by the hazard to 100 test_transition <- function() { return (100) } # Create an S3 golden_hazard haz <- new_hazard( test_hazard, c("a"), new_transition(test_transition, c(), "b") ) # Define a trajectory function, which adds 2 to all members of the input vector test_trajectory <- function(a) { return (a + 2) } # Define an S3 golden_trajectory trj <- new_trajectory(test_trajectory, c("b"), "b") # Create an S3 golden_history, containing 1 golden_history_column hist <- new_history(new_column("sum_a", sum, c("a"))) # Define an S3 golden_parameters params <- new_parameters( hazards = haz, trajectories = trj, steps = 10, debug = FALSE, history = hist ) # Run the simulation to collect results results <- run_simulation(dt, params)