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

if (FALSE) { # \dontrun{
# Create a basic log-normal model
params <- LogNormalModelParams("LogNormalModel")
model <- newCppModel(params)

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

# Create a linear antibiotic model
params <- LinearAbxModel()
model <- newCppModel(params, verbose = TRUE)

# Get parameter values
inColParams <- model$InColParams
paramValues <- inColParams$values

# Use with a system history for likelihood calculation
# (requires data and SystemHistory object)
# ll <- model$logLikelihood(systemHistory)
} # }