# R6 Class Representing a `crcmodel`

`crcmodel.Rd`

This class implements a `crcmodel`.

## 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 `set_input()`

Set Input

### 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.

### Method `set_natural_history_fn()`

Set Natural History Function

#### 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

### Method `simulate_natural_history()`

Simulate Natural History Wrapper Function

### Method `simulate_screening()`

Simulate Screening Wrapper Function