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.
Arguments
- modelParameters
List of model parameters created using functions from constructors.R, such as:
LogNormalModelParams()- Basic log-normal modelLinearAbxModel()- Linear antibiotic modelOr custom parameter lists containing:
modname: Model name ("LogNormalModel", "LinearAbxModel", "LinearAbxModel2", "MixedModel")nstates: Number of states (2 or 3)nmetro: Number of Metropolis-Hastings stepsforward: Forward simulation flagcheat: Cheat flag for debuggingInsitu: In situ parameters fromInsituParams()SurveillanceTest: Surveillance test parameters fromSurveillanceTestParams()ClinicalTest: Clinical test parameters fromClinicalTestParams()OutCol: Out-of-unit infection parameters fromOutOfUnitInfectionParams()InCol: In-unit parameters fromInUnitParams()orABXInUnitParams()Abx: Antibiotic parameters fromAbxParams()AbxRate: Antibiotic rate parameters fromAbxRateParams()
- 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 parametersOutColParams- Out-of-unit colonization parametersInsituParams- In situ parametersSurveillanceTestParams- Surveillance test parametersClinicalTestParams- Clinical test parametersAbxParams- Antibiotic parameters
Methods:
logLikelihood(hist)- Calculate log likelihood for a SystemHistorygetHistoryLinkLogLikelihoods(hist)- Get individual link log likelihoodsforwardSimulate(...)- Perform forward simulationinitEpisodeHistory(...)- Initialize episode historysampleEpisodes(...)- Sample episodessetAbx(...)- 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
LogNormalModelParams()for creating model parametersLinearAbxModel()for linear antibiotic model parametersInsituParams(),SurveillanceTestParams(), etc. for parameter componentsnewModelExport()for extracting parameter values from a model
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
# }