Skip to contents

Run a given model

Usage

run_model(
  project,
  modelId,
  parameterValues,
  parameterConstraints = NULL,
  silent = clairvoyant::opts$get("silent")
)

Arguments

project

The project, as imported with read_project()

modelId

The identifier of the model to run

parameterValues

The parameter values to use, as a named list

parameterConstraints

Optionally, a named list of lists, where each list's name is a parameter identifier, and where each element of the is an R expression; if it evaluates to FALSE for the corresponding parameter, the model step is not executes and NA is returned instead.

silent

Whether to be silent or chatty.

Value

The result of evaluating the expressions forming the model, as well as the parameter values and the intermediate values

Examples

### Get the path to an example project
exampleProjectPath <-
  system.file(
    "example1",
    package = "clairvoyant"
  );

### Import it
exampleProject <-
  clairvoyant::read_project(
    exampleProjectPath
  );

### Run the model once
clairvoyant::run_model(
  project = exampleProject,
  modelId = "basic_model",
  parameterValues = 
    list(
      salePrice = 10,
      productionCosts = 5,
      prevalence = 3.6,
      population_size = 17000000
    )
);
#> $parameterValues
#> $parameterValues$salePrice
#> [1] 10
#> 
#> $parameterValues$productionCosts
#> [1] 5
#> 
#> $parameterValues$prevalence
#> [1] 3.6
#> 
#> $parameterValues$population_size
#> [1] 1.7e+07
#> 
#> 
#> $intermediateValues
#> $intermediateValues$profit_per_pill
#> [1] 5
#> 
#> $intermediateValues$number_of_customers
#> [1] 612000
#> 
#> 
#> $outcomeValue
#> [1] 3060000
#> 
#> $df
#>   salePrice productionCosts prevalence population_size profit_per_pill
#> 1        10               5        3.6         1.7e+07               5
#>   number_of_customers total_profit
#> 1              612000      3060000
#> 
#> attr(,"class")
#> [1] "clairvoyant"             "clairvoyant_modelResult"