crcmodel | R Documentation |
This class implements a 'crcmodel'.
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).
new()
Create a new 'crcmodel' object.
crcmodel$new(name)
name
name of the model to be created.
s new 'crcmodel' object.
set_input()
Set Input
crcmodel$set_input(name, value, type)
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.
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.
to_json()
Converts a 'crcmodel' to a JSON string
crcmodel$to_json(input_types)
input_types
vector of input types to include in the json object.
a JSON string containing the crcmodel objects that should be exported
set_inputs_from_json()
Set model Inputs from JSON string
crcmodel$set_inputs_from_json(json)
json
a JSON string generated by the model_to_json function
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.
set_posterior()
Set Posterior distribution of model parameters
crcmodel$set_posterior( posteriors_list, posterior_weights, cols_to_ignore = NULL, n_posterior = 1000, use_average = F, seed = 12345678, resample = T )
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.
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.
set_natural_history_fn()
Set Natural History Function
crcmodel$set_natural_history_fn( natural_history_fn, returns_standardized_df = T )
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.
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.
set_screening_fn()
Set Screening Function
crcmodel$set_screening_fn(screening_fn, returns_standardized_df = T)
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.
This function allows the user to have a custom screening function.
simulate_natural_history()
Simulate Natural History Wrapper Function
crcmodel$simulate_natural_history(...)
...
any set of parameters passed to this function will be passed along to the user natural history function.
This function is a wrapper around the user natural history function. It passes the 'self' object and any other parameters provided to the function.
simulate_screening()
Simulate Screening Wrapper Function
crcmodel$simulate_screening(...)
...
any set of parameters passed to this function will be passed along to the user screening function.
This function is a wrapper around the user screening. It passes the 'self' object and any other parameters provided to the function.
clone()
The objects of this class are cloneable with this method.
crcmodel$clone(deep = FALSE)
deep
Whether to make a deep clone.
set_natural_history_fn
set_natural_history_fn
set_screening_fn
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.