Skip to contents

Creates and initializes a C++ model object based on the provided parameters. This function wraps the underlying C++ model classes (LogNormalModel, LinearAbxModel, LinearAbxModel2, MixedModel) in appropriate R reference classes that expose the model's methods and properties.

Usage

newCppModel(modelParameters, verbose = FALSE)

Arguments

modelParameters

List of model parameters created using functions from constructors.R, such as:

verbose

Logical flag to print progress messages during model creation and parameter setup (default: FALSE)

Value

A reference class object wrapping the C++ model. The specific class depends on modelParameters$modname:

  • CppLogNormalModel - For "LogNormalModel"

  • CppLinearAbxModel - For "LinearAbxModel"

  • CppLinearAbxModel2 - For "LinearAbxModel2"

  • CppMixedModel - For "MixedModel" (if exposed in C++)

All returned objects inherit from CppBasicModel and provide access to:

  • Properties:

    • InColParams - In-unit colonization parameters

    • OutColParams - Out-of-unit colonization parameters

    • InsituParams - In situ parameters

    • SurveillanceTestParams - Surveillance test parameters

    • ClinicalTestParams - Clinical test parameters

    • AbxParams - Antibiotic parameters

  • Methods:

    • logLikelihood(hist) - Calculate log likelihood for a SystemHistory

    • getHistoryLinkLogLikelihoods(hist) - Get individual link log likelihoods

    • forwardSimulate(...) - Perform forward simulation

    • initEpisodeHistory(...) - Initialize episode history

    • sampleEpisodes(...) - Sample episodes

    • setAbx(...) - Set antibiotic parameters

Details

The function uses the existing newModel C++ function to instantiate the model and configure all parameters, then wraps it in the appropriate R reference class based on the model type specified in modelParameters$modname.

See also

Examples

# \donttest{
# Create a linear antibiotic model (recommended - stable constructors)
params <- LinearAbxModel()
model <- newCppModel(params)

# Access model properties
inColParams <- model$InColParams
insituParams <- model$InsituParams

# Get parameter values
paramValues <- inColParams$values

# Get parameter names (if available)
paramNames <- inColParams$names

# Create a log-normal model
params <- LogNormalModelParams("LogNormalModel")
model <- newCppModel(params, verbose = TRUE)
#> Creating C++ model of type: LogNormalModel
#> Creating C++ model object...
#> 
#>   * Setting up Abx...Done
#>   * Setting up Insitu...Done
#>   * Setting up Surveillance Test...Done
#>   * Setting up Clinical Test...Done
#>   * Setting up Out of Unit...Done
#>   * Setting up In Unit...Done
#>   * Setting up Abx Rates...Done
#> Model created successfully
# }