Skip to contents

This class implements a `crcmodel`.

See also

set_natural_history_fn

set_natural_history_fn

set_screening_fn

Public fields

name

is a character string representing the model name (e.g. CRC-SPIN v 2.1)

inputs

is a list of model inputs. One can add inputs to the object with the set_input function.

inputs_table

is a data.frame listing all inputs added to the model.

posterior_params

is a data.frame containing parameters from the posterior distribution of the model. This table is set with the set_posterior function.

natural_history_results

is the object that will receive results from the natural history function.

screening_results

is the object that will receive results from the natural history function.

simulate_natural_history_fn

is a function that will take as parameters self and ..., simulate the natural history of crc and returns invisible(self).

simulate_screening_fn

is a function that will take as parameters self and ..., simulate the natural history of crc and returns invisible(self).

Methods


Method new()

Create a new `crcmodel` object.

Usage

crcmodel$new(name)

Arguments

name

name of the model to be created.

Returns

s new `crcmodel` object.


Method set_input()

Set Input

Usage

crcmodel$set_input(name, value, type)

Arguments

name

character string defining the input name

value

input value. Can be a single value, a list or a vector.

type

Functionality TBD, but inputs can be filtered by type.

Details

Use this function to add a new input to a crcmodel object. All model inputs shoulhd be added or modified through this function. Inputs can be vectors or lists of strings, numeric or integers, to guarantee that they can be translated to and from JSON without any issues.


Method to_json()

Converts a `crcmodel` to a JSON string

Usage

crcmodel$to_json(input_types)

Arguments

input_types

vector of input types to include in the json object.

Returns

a JSON string containing the crcmodel objects that should be exported


Method set_inputs_from_json()

Set model Inputs from JSON string

Usage

crcmodel$set_inputs_from_json(json)

Arguments

json

a JSON string generated by the model_to_json function

Details

Use this function to set model inputs from a JSON string. Note that the posterior distribution is not included in the json strong of model inputs.


Method set_posterior()

Set Posterior distribution of model parameters

Usage

crcmodel$set_posterior(
  posteriors_list,
  posterior_weights,
  cols_to_ignore = NULL,
  n_posterior = 1000,
  use_average = F,
  seed = 12345678,
  resample = T
)

Arguments

posteriors_list

named list of one more more data.frames containing the posterior of model parameters.

posterior_weights

character indicating the name of the column that contain weights to be used when sampling from the posterior

cols_to_ignore

character vector of columns name to ignore. This is useful when the posterior files contain columns that are not parameters and are not inputs to the model.

n_posterior

the size of the sample to take from each posterior file.

use_average

T if one wants to use the average value of all parameters rather than the mean

seed

random seed to use when sampling from the posterior

resample

if T, samples from the posterior using the posterior weights. Otherwise, returns the full posterior, and preservers the weights.

Details

Use this function to add a new input to a crcmodel object. All model inputs shoulhd be added or modified through this function. Inputs can be vectors or lists of strings, numeric or integers, to guarantee that they can be translated to and from JSON without any issues.


Method set_natural_history_fn()

Set Natural History Function

Usage

crcmodel$set_natural_history_fn(
  natural_history_fn,
  returns_standardized_df = T
)

Arguments

natural_history_fn

an R function that is capable of simulating the model's natural history.

returns_standardized_df

if TRUE, your natural history function must return a standardized dataframe.

Details

This function allows the user to have a custom natural history function. Having this flexibility effectively decouples the model itself from the package that is used to simulate the model. As in a regression, the functional form of the model is not baked into `lm`. Instead, `lm` allows you to create *any* linear model. Use this function to define a natural history function. You are advised to create a simple natural history function and put a `browser()` inside it. Then, after creating your model with `my_model <- crcmodel$new()` and adding inputs with `my_model$set_input()`, assign your custom natural history function with `my_model$set_natural_history(my_function_name)`. `my_function_name` should the name of a function that you already sourced from a script or from a package. Finally, run `my_model$simulate_natural_history()` to run your natural history model. You will then see all your inputs inside the `self` object, which is an environment that contains all the inputs for your model.


Method set_screening_fn()

Set Screening Function

Usage

crcmodel$set_screening_fn(screening_fn, returns_standardized_df = T)

Arguments

screening_fn

an R function that is capable of simulating the model's screening.

returns_standardized_df

if TRUE, your natural history function must return a standardized dataframe.

Details

This function allows the user to have a custom screening function.


Method simulate_natural_history()

Simulate Natural History Wrapper Function

Usage

crcmodel$simulate_natural_history(...)

Arguments

...

any set of parameters passed to this function will be passed along to the user natural history function.

Details

This function is a wrapper around the user natural history function. It passes the `self` object and any other parameters provided to the function.


Method simulate_screening()

Simulate Screening Wrapper Function

Usage

crcmodel$simulate_screening(...)

Arguments

...

any set of parameters passed to this function will be passed along to the user screening function.

Details

This function is a wrapper around the user screening. It passes the `self` object and any other parameters provided to the function.


Method clone()

The objects of this class are cloneable with this method.

Usage

crcmodel$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.