Learn R Programming

bayestransmission (version 0.1.0)

newCppModel: Create a new C++ model object with parameters

Description

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)

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

Arguments

modelParameters

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

  • LogNormalModelParams() - Basic log-normal model

  • LinearAbxModel() - Linear antibiotic model

  • Or custom parameter lists containing:

    • modname: Model name ("LogNormalModel", "LinearAbxModel", "LinearAbxModel2", "MixedModel")

    • nstates: Number of states (2 or 3)

    • nmetro: Number of Metropolis-Hastings steps

    • forward: Forward simulation flag

    • cheat: Cheat flag for debugging

    • Insitu: In situ parameters from InsituParams()

    • SurveillanceTest: Surveillance test parameters from SurveillanceTestParams()

    • ClinicalTest: Clinical test parameters from ClinicalTestParams()

    • OutCol: Out-of-unit infection parameters from OutOfUnitInfectionParams()

    • InCol: In-unit parameters from InUnitParams() or ABXInUnitParams()

    • Abx: Antibiotic parameters from AbxParams()

    • AbxRate: Antibiotic rate parameters from AbxRateParams()

verbose

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

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

  • LogNormalModelParams() for creating model parameters

  • LinearAbxModel() for linear antibiotic model parameters

  • InsituParams(), SurveillanceTestParams(), etc. for parameter components

  • newModelExport() for extracting parameter values from a model

Examples

Run this code
# \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)
# }

Run the code above in your browser using DataLab